Skip to content
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ Note that LEADS requires **Python >= 3.12**. To set up the environment on a Rasp
command, see [Environment Setup](#environment-setup).

```shell
pip install Pillow customtkinter pynput pyserial lgpio gpiozero pynmea2 leads
pip install Pillow PySDL2 customtkinter gpiozero lgpio pynmea2 pynput pyserial leads
```

`numpy` and `pandas` will be automatically installed with `leads`.

`Pillow`, `customtkinter`, `pynput`, `pyserial`, `lgpio`, `gpiozero`, and `pynmea2` are optional.
`Pillow`, `PySDL2`, `customtkinter`, `gpiozero`, `lgpio`, `pynmea2`, `pynput`, and `pyserial` are optional.

If you only want the framework, run the following.

Expand Down
6 changes: 6 additions & 0 deletions leads_audio/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from importlib.util import find_spec as _find_spec

if not _find_spec("sdl2"):
raise ImportError("Please install `PySDL2` to run this module\n>>>pip install PySDL2")

from leads_audio.prototype import *
Binary file added leads_audio/assets/direction-indicator-off.mp3
Binary file not shown.
Binary file added leads_audio/assets/direction-indicator-on.mp3
Binary file not shown.
Binary file added leads_audio/assets/warning.mp3
Binary file not shown.
44 changes: 44 additions & 0 deletions leads_audio/prototype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from atexit import register as _register

from sdl2 import AUDIO_S16 as _AUDIO_S16
from sdl2.sdlmixer import Mix_Init as _init, Mix_OpenAudioDevice as _open_audio_device, MIX_INIT_MP3 as _MIX_INIT_MP3, \
Mix_LoadMUS as _load_music, Mix_PlayMusic as _play_music, Mix_Music as _Music, \
Mix_GetError as _get_error, Mix_FreeMusic as _free_music, Mix_CloseAudio as _close_audio

from leads_audio.system import _ASSETS_PATH


def _ensure(flag: int) -> None:
if flag < 0:
raise RuntimeError(_get_error().decode())


_init(_MIX_INIT_MP3)
_ensure(_open_audio_device(44100, _AUDIO_S16, 2, 2048, b"System", 1))


@_register
def _release_resources() -> None:
_close_audio()


class _SoundEffect(object):
def __init__(self, name: str) -> None:
self._name: str = name
self._source: _Music | None = None

def load_source(self) -> _Music:
if self._source is None:
self._source = _load_music(f"{_ASSETS_PATH}/{self._name}.mp3".encode())
return self._source

def play(self) -> None:
_ensure(_play_music(self.load_source(), 1))

def stop(self) -> None:
_ensure(_free_music(self.load_source()))


DIRECTION_INDICATOR_ON: _SoundEffect = _SoundEffect("direction-indicator-on")
DIRECTION_INDICATOR_OFF: _SoundEffect = _SoundEffect("direction-indicator-off")
WARNING: _SoundEffect = _SoundEffect("warning")
3 changes: 3 additions & 0 deletions leads_audio/system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from os.path import abspath as _abspath

_ASSETS_PATH: str = f"{_abspath(__file__)[:-9]}assets"
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
url="https://github.com/ProjectNeura/LEADS",
packages=find_packages(),
package_data={
"leads_audio": ["assets/*"],
"leads_gui": ["assets/*", "assets/icons/*"],
"leads_vec": ["_bootloader/leads_vec.service.sh"]
},
Expand Down