Skip to content

Conversation

@stheid
Copy link

@stheid stheid commented Apr 22, 2021

No description provided.

@stheid stheid changed the title Added requirements to setup.py Dependencies and Platformindependent sound playing Apr 22, 2021
@mwhamgenomics
Copy link
Owner

Thanks for the PR! This repo can definitely use some cleaning up. I got stacktraces with playsound, though:

File ".../miniconda3/envs/pysplit/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
File ".../miniconda3/envs/pysplit/lib/python3.9/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
File ".../miniconda3/envs/pysplit/lib/python3.9/site-packages/playsound.py", line 55, in _playsoundOSX
    from AppKit import NSSound
ModuleNotFoundError: No module named 'AppKit'

Looks like AppKit is part of macOS's built-in Python and isn't present in independently-installed interpreters or Conda environments. Installing PyObjC fixes this, but there's 1-2 seconds of lag before the sound plays.

I see other projects like https://github.com/Krozark/sound-player just look for different executables depending on OS and call whatever they find - which I think I like, assuming it doesn't lag on other OSes (I've found afplay to be fine on macOS). Any thoughts?

@stheid
Copy link
Author

stheid commented May 10, 2021

opinions

Yeah, that dependency was even listed in pypi https://pypi.org/project/playsound/

Delays of about a second are definetly not acceptable

I think the golden way would be to move everything to pip-only deps, to make it most transparent what has to be installed.

For robustness reasons i would not want to depend a project on another 0 star github projects as long as there are alternatives.

suggestion

scrolling through that blog gives me the impression that installing simpleaudio is very nice as it has no dependencies at all. however only supporting wav. pydub could than be used to provide a little bit more support.

If you like the idea i might have a look at it in the next couple of weeks but i have currently moved a bit away of speedrunning relatet stuff.

the unrelated

i think it would be nice to include some default freesounds, as most people will probably be to lazy to search for it. However my audiofiles are also not entirely free.

@mwhamgenomics
Copy link
Owner

Nice, I didn't know about those libraries. Agreed that dependencies should ideally be reasonably mature and available on Pip. My thoughts:

Playsound

I found that most of the lag happens when it's importing AppKit for the first time:

import playsound  # no lag
playsound.playsound('gold_split.m4a')  # lag
playsound.playsound('gold_split.m4a')  # no lag

It's possible to pre-load the right libraries and move the lag to when the app starts - so it's still there, but at least it's not when the user hits 'split' and plays the sound:

import playsound
from AppKit import NSSound  # lag
from Foundation import NSURL  # lag
playsound.playsound('gold_split.m4a')  # no lag

Don't know whether similar workarounds would be needed on other OSes though. We'd also need to set PyObjC as a dependency only when the user is on macOS and not using the system's Python - that should be possible, but not currently sure how it would be done.

Simpleaudio/PyDub

I quite like this option, yes! Simpleaudio can't play the .m4a files that I use, but PyDub can convert the sound file:

sound = pydub.AudioSegment.from_file('gold_split.m4a')
simpleaudio.play_buffer(sound.raw_data, sound.channels, sound.sample_width, sound.frame_rate)

The conversion has a dependency on ffmpeg or avconv for non-wav/raw/pcm sounds, though. It worked for me because by chance I had brew install-ed ffmpeg ages ago. Maybe we can:

  • note in the documentation this dependency for certain sound formats
  • if the user tries to play, e.g, an m4a sound without ffmpeg/avconv, then handle the error and don't play the sound

Default sounds

Thanks, will open an issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants