diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8d8cc65..581dc70 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,8 +11,8 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04, windows-latest, macOS-latest] - python-version: [3.5, 3.6, 3.7, 3.8, 3.9, 3.10.0, 3.11.0] + os: [ubuntu-20.04, windows-2022, macOS-13] + python-version: [3.6, 3.7, 3.8, 3.9, 3.10.0, 3.11.0] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 555aac3..407780c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - `sound_check` function ### Changed +- `playsound` replaced with `nava` +- `nava` added to `requirements.txt` - Test system modified - `Python 3.11` added to `test.yml` - CLI mode updated diff --git a/dev-requirements.txt b/dev-requirements.txt index bc66e85..65985a2 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,5 +1,5 @@ art==5.9 -playsound==1.3.0 +nava==0.3 codecov>=2.0.15 pytest>=4.3.1 pytest-cov>=2.6.1 diff --git a/nafas/functions.py b/nafas/functions.py index 51a7eaa..043e7f8 100644 --- a/nafas/functions.py +++ b/nafas/functions.py @@ -5,8 +5,7 @@ from nafas.params import NAFAS_DESCRIPTION, NAFAS_NOTICE, STANDARD_MENU, STANDARD_MENU_ORDER, STEP_MAP from nafas.params import PROGRAMS, PROGRAM_DESCRIPTION, SOUND_MAP, STEP_TEMPLATE, CYCLE_TEMPLATE from nafas.params import SOUND_WARNING_MESSAGE -import playsound -import threading +import nava import os from warnings import warn @@ -132,7 +131,7 @@ def sound_check(): """ sound_path = get_sound_path(SOUND_MAP['Silence']) try: - playsound.playsound(sound_path) + nava.play(sound_path) except Exception: warn(SOUND_WARNING_MESSAGE, RuntimeWarning) @@ -276,38 +275,15 @@ def graphic_counter(delay_time): print() -def _playsound_async(sound_path, debug): - """ - Play sound asynchronous in a thread. - - :param sound_path: sound path - :type sound_path: str - :param debug: debug mode flag - :type debug: bool - :return: None - """ - try: - playsound.playsound(sound_path) - except Exception as e: - if debug: - print(str(e)) - - -def play_sound(sound_path, debug=False): +def play_sound(sound_path): """ Play inputted sound file. :param sound_path: sound path :type sound_path: str - :param debug: debug mode flag - :type debug: bool - :return: new thread as threading.Thread object + :return: sound id as int """ - new_thread = threading.Thread( - target=_playsound_async, args=( - sound_path, debug,), daemon=True) - new_thread.start() - return new_thread + return nava.play(sound_path, async_mode=True) def run(program_data): @@ -324,15 +300,15 @@ def run(program_data): unit = program_data["unit"] pre = program_data["pre"] print("Preparing ", end="", flush=True) - sound_thread = play_sound(get_sound_path(SOUND_MAP['Prepare'])) + sid = play_sound(get_sound_path(SOUND_MAP['Prepare'])) graphic_counter(pre) line() time.sleep(1) - sound_thread.join() - sound_thread = play_sound(get_sound_path(SOUND_MAP['Start'])) + nava.stop(sid) + sid = play_sound(get_sound_path(SOUND_MAP['Start'])) print("Start", flush=True) time.sleep(1) - sound_thread.join() + nava.stop(sid) line() time.sleep(1) for i in range(cycle): @@ -341,15 +317,16 @@ def run(program_data): for index, item in enumerate(ratio): if item != 0: item_name = STEP_MAP[index] - sound_thread = play_sound(get_sound_path(SOUND_MAP[item_name])) + sid = play_sound(get_sound_path(SOUND_MAP[item_name])) print( STEP_TEMPLATE.format( item_name, str( unit * item)), flush=True) graphic_counter(item * unit) - sound_thread.join() + nava.stop(sid) time.sleep(1) line() - sound_thread = play_sound(get_sound_path(SOUND_MAP['End'])) + sid = play_sound(get_sound_path(SOUND_MAP['End'])) print("Well done!", flush=True) - sound_thread.join() + time.sleep(2) + nava.stop(sid) diff --git a/requirements.txt b/requirements.txt index bfb003f..68c8786 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ art>=1.8 -playsound>=1.0.0 - +nava>=0.4 diff --git a/test/test.py b/test/test.py index 7c55ac1..aa430d0 100644 --- a/test/test.py +++ b/test/test.py @@ -128,9 +128,10 @@ . . . . ###################################################################### Well done! ->>> play_sound(1, debug=False).join() ->>> play_sound(1, debug=True).join() -ignore_this_message +>>> sid = play_sound(1) +Traceback (most recent call last): + ... +nava.errors.NavaBaseError: Sound file's path should be a string. >>> try: ... wave_path = os.path.join("nafas", "sounds", "silence.wav") ... temp_path = os.path.join("nafas", "sounds", "temp.wav")