this file is part of audioread 2013 adrian sampson permission is hereby granted free of charge to any person obtaining a copy of this software and associated documentation files the software to deal in the software without restriction including without limitation the rights to use copy modify merge publish distribute sublicense andor sell copies of the software and to permit persons to whom the software is furnished to do so subject to the following conditions the above notice and this permission notice shall be included in all copies or substantial portions of the software multilibrary crossplatform audio decoding from import ffdec from exceptions import decodeerror nobackenderror from version import version as version noqa from base import audiofile noqa def gstavailable try import gi except importerror return false try gi requireversion gst 1 0 except valueerror attributeerror return false try from gi repository import gst noqa except importerror return false return true def caavailable import ctypes util lib ctypes util findlibrary audiotoolbox return lib is not none def madavailable a cache for the available backends returns a list of backends that are available on this system the list of backends is cached after the first call if the parameter flushcache is set to true then the cache will be flushed and the backend list will be reconstructed standardlibrary wav and aiff readers core audio gstreamer mad ffmpeg cache the backends we found open an audio file using a library that is available on this system the optional backends parameter can be a list of audio file classes to try opening the file with if it is not provided audioopen tries all available backends if you call this function many times you can avoid the cost of checking for available backends every time by calling availablebackends once and passing the result to each audioopen call if all backends fail to read the file a nobackenderror exception is raised all backends failed this file is part of audioread 2013 adrian sampson permission is hereby granted free of charge to any person obtaining a copy of this software and associated documentation files the software to deal in the software without restriction including without limitation the rights to use copy modify merge publish distribute sublicense and or sell copies of the software and to permit persons to whom the software is furnished to do so subject to the following conditions the above notice and this permission notice shall be included in all copies or substantial portions of the software multi library cross platform audio decoding noqa noqa determine whether gstreamer and the python gobject bindings are installed noqa determines whether coreaudio is available i e we re running on mac os x determines whether the pymad bindings are available noqa a cache for the available backends returns a list of backends that are available on this system the list of backends is cached after the first call if the parameter flush_cache is set to true then the cache will be flushed and the backend list will be reconstructed standard library wav and aiff readers core audio gstreamer mad ffmpeg cache the backends we found open an audio file using a library that is available on this system the optional backends parameter can be a list of audio file classes to try opening the file with if it is not provided audio_open tries all available backends if you call this function many times you can avoid the cost of checking for available backends every time by calling available_backends once and passing the result to each audio_open call if all backends fail to read the file a nobackenderror exception is raised all backends failed
from . import ffdec
from .exceptions import DecodeError, NoBackendError
from .version import version as __version__  
from .base import AudioFile  


def _gst_available():
    
    try:
        import gi
    except ImportError:
        return False

    try:
        gi.require_version('Gst', '1.0')
    except (ValueError, AttributeError):
        return False

    try:
        from gi.repository import Gst  
    except ImportError:
        return False

    return True


def _ca_available():
    
    import ctypes.util
    lib = ctypes.util.find_library('AudioToolbox')
    return lib is not None


def _mad_available():
    
    try:
        import mad  
    except ImportError:
        return False
    else:
        return True



BACKENDS = []


def available_backends(flush_cache=False):
    

    if BACKENDS and not flush_cache:
        return BACKENDS

    
    from . import rawread
    result = [rawread.RawAudioFile]

    
    if _ca_available():
        from . import macca
        result.append(macca.ExtAudioFile)

    
    if _gst_available():
        from . import gstdec
        result.append(gstdec.GstAudioFile)

    
    if _mad_available():
        from . import maddec
        result.append(maddec.MadAudioFile)

    
    if ffdec.available():
        result.append(ffdec.FFmpegAudioFile)

    
    BACKENDS[:] = result

    return BACKENDS


def audio_open(path, backends=None):
    
    if backends is None:
        backends = available_backends()

    for BackendClass in backends:
        try:
            return BackendClass(path)
        except DecodeError:
            pass

    
    raise NoBackendError()