defaudio_open(path): """Open an audio file using a library that is available on this system. """ # Standard-library WAV and AIFF readers. from . import rawread try: return rawread.RawAudioFile(path) except DecodeError: pass
# Core Audio. if _ca_available(): from . import macca try: return macca.ExtAudioFile(path) except DecodeError: pass
# GStreamer. if _gst_available(): from . import gstdec try: return gstdec.GstAudioFile(path) except DecodeError: pass
# MAD. if _mad_available(): from . import maddec try: return maddec.MadAudioFile(path) except DecodeError: pass
defpopen_multiple(commands, command_args, *args, **kwargs): """Like `subprocess.Popen`, but can try multiple commands in case some are not available. `commands` is an iterable of command names and `command_args` are the rest of the arguments that, when appended to the command name, make up the full first argument to `subprocess.Popen`. The other positional and keyword arguments are passed through. """ for i, command inenumerate(commands): cmd = [command] + command_args try: return subprocess.Popen(cmd, *args, **kwargs) except OSError: if i == len(commands) - 1: # No more commands to try. raise