Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace simple audio #730

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/build-multi-os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,6 @@ jobs:
sudo apt-get install -y avrdude libasound2-dev
./AppRun -m pip install --upgrade pip
./AppRun -m pip install --upgrade setuptools
# hack to fix setup.py script with faulty include
./AppRun -m pip install --global-option=build_ext --global-option="-I$(pwd)/opt/${{steps.vars.outputs.python-minor}}/include/${{steps.vars.outputs.python-minor}}" simpleaudio
./AppRun -m pip install -r requirements.build.txt
- name: Add AppDir subdirectories to PATH
run: |
Expand Down
2 changes: 0 additions & 2 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ exclude = (?x)(
follow_imports= silent
strict= True

[mypy-simpleaudio]
ignore_missing_imports= True
[mypy-sliplib]
ignore_missing_imports= True
[mypy-fbs_runtime.*]
Expand Down
1 change: 0 additions & 1 deletion requirements.build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Pillow==10
pyserial==3.5
sliplib==0.6.2
bitarray==2.9.2
simpleaudio==1.0.4
numpy==1.26.4
charset-normalizer<3.0.0
semver==3.0.2
14 changes: 8 additions & 6 deletions src/main/python/main/ayab/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

from __future__ import annotations
from os import path

import simpleaudio as sa
from PySide6.QtCore import QUrl
from PySide6.QtMultimedia import QSoundEffect

from typing import TYPE_CHECKING

Expand All @@ -34,7 +34,7 @@ class AudioPlayer:
def __init__(self, gui: GuiMain):
self.__dir = gui.app_context.get_resource("assets")
self.__prefs = gui.prefs
coderabbitai[bot] marked this conversation as resolved.
Show resolved Hide resolved
self.__cache: dict[str, sa.WaveObject] = {}
self.__cache: dict[str, QSoundEffect] = {}

def play(self, sound: str) -> None:
"""Play audio."""
Expand All @@ -47,7 +47,7 @@ def play(self, sound: str) -> None:
# else
wave_obj.play()

def __wave(self, sound: str) -> sa.WaveObject | None:
def __wave(self, sound: str) -> QSoundEffect | None:
dl1com marked this conversation as resolved.
Show resolved Hide resolved
"""Get and cache audio."""
if sound not in self.__cache:
wave_object = self.__load_wave(sound)
Expand All @@ -56,7 +56,9 @@ def __wave(self, sound: str) -> sa.WaveObject | None:
self.__cache[sound] = wave_object
return self.__cache[sound]

def __load_wave(self, sound: str) -> sa.WaveObject | None:
def __load_wave(self, sound: str) -> QSoundEffect | None:
"""Get audio from file."""
filename = path.join(self.__dir, sound + ".wav")
return sa.WaveObject.from_wave_file(filename)
effect = QSoundEffect()
effect.setSource(QUrl.fromLocalFile(filename))
return effect
coderabbitai[bot] marked this conversation as resolved.
Show resolved Hide resolved
coderabbitai[bot] marked this conversation as resolved.
Show resolved Hide resolved