Giter VIP home page Giter VIP logo

audioread's Introduction

audioread

Decode audio files using whichever backend is available. The library currently supports:

Use the library like so:

with audioread.audio_open(filename) as f:
    print(f.channels, f.samplerate, f.duration)
    for buf in f:
        do_something(buf)

Buffers in the file can be accessed by iterating over the object returned from audio_open. Each buffer is a bytes-like object (buffer, bytes, or bytearray) containing raw 16-bit little-endian signed integer PCM data. (Currently, these PCM format parameters are not configurable, but this could be added to most of the backends.)

Additional values are available as fields on the audio file object:

  • channels is the number of audio channels (an integer).
  • samplerate is given in Hz (an integer).
  • duration is the length of the audio in seconds (a float).

The audio_open function transparently selects a backend that can read the file. (Each backend is implemented in a module inside the audioread package.) If no backends succeed in opening the file, a DecodeError exception is raised. This exception is only used when the file type is unsupported by the backends; if the file doesn't exist, a standard IOError will be raised.

A second optional parameter to audio_open specifies which backends to try (instead of trying them all, which is the default). You can use the available_backends function to get a list backends that are usable on the current system.

Audioread supports Python 3 (3.8+).

Example

The included decode.py script demonstrates using this package to convert compressed audio files to WAV files.

Troubleshooting

A NoBackendError exception means that the library could not find one of the libraries or tools it needs to decode audio. This could mean, for example, that you have a broken installation of FFmpeg. To check, try typing ffmpeg -version in your shell. If that gives you an error, try installing FFmpeg with your OS's package manager (e.g., apt or yum) or using Conda.

Version History

3.0.2
Support path-like objects (not just strings) in the Core Audio backend.
3.0.1
Fix a possible deadlock when FFmpeg's version output produces too much data.
3.0.0
Drop support for Python 2 and older versions of Python 3. The library now requires Python 3.6+. Increase default block size in FFmpegAudioFile to get slightly faster file reading. Cache backends for faster lookup (thanks to @bmcfee). Audio file classes now inherit from a common base AudioFile class.
2.1.9
Work correctly with GStreamer 1.18 and later (thanks to @ssssam).
2.1.8
Fix an unhandled OSError when FFmpeg is not installed.
2.1.7
Properly close some filehandles in the FFmpeg backend (thanks to @RyanMarcus and @ssssam). The maddec backend now always produces bytes objects, like the other backends (thanks to @ssssam). Resolve an audio data memory leak in the GStreamer backend (thanks again to @ssssam). You can now optionally specify which specific backends audio_open should try (thanks once again to @ssssam). On Windows, avoid opening a console window to run FFmpeg (thanks to @flokX).
2.1.6
Fix a "no such process" crash in the FFmpeg backend on Windows Subsystem for Linux (thanks to @llamasoft). Avoid suppressing SIGINT in the GStreamer backend on older versions of PyGObject (thanks to @lazka).
2.1.5
Properly clean up the file handle when a backend fails to decode a file. Fix parsing of "N.M" channel counts in the FFmpeg backend (thanks to @piem). Avoid a crash in the raw backend when a file uses an unsupported number of bits per sample (namely, 24-bit samples in Python < 3.4). Add a __version__ value to the package.
2.1.4
Fix a bug in the FFmpeg backend where, after closing a file, the program's standard input stream would be "broken" and wouldn't receive any input.
2.1.3
Avoid some warnings in the GStreamer backend when using modern versions of GLib. We now require at least GLib 2.32.
2.1.2
Fix a file descriptor leak when opening and closing many files using GStreamer.
2.1.1
Just fix ReST formatting in the README.
2.1.0
The FFmpeg backend can now also use Libav's avconv command. Fix a warning by requiring GStreamer >= 1.0. Fix some Python 3 crashes with the new GStreamer backend (thanks to @xix-xeaon).
2.0.0
The GStreamer backend now uses GStreamer 1.x via the new gobject-introspection API (and is compatible with Python 3).
1.2.2
When running FFmpeg on Windows, disable its crash dialog. Thanks to jcsaaddupuy.
1.2.1
Fix an unhandled exception when opening non-raw audio files (thanks to aostanin). Fix Python 3 compatibility for the raw-file backend.
1.2.0
Add support for FFmpeg on Windows (thanks to Jean-Christophe Saad-Dupuy).
1.1.0
Add support for Sun/NeXT Au files via the standard-library sunau module (thanks to Dan Ellis).
1.0.3
Use the rawread (standard-library) backend for .wav files.
1.0.2
Send SIGKILL, not SIGTERM, to ffmpeg processes to avoid occasional hangs.
1.0.1
When GStreamer fails to report a duration, raise an exception instead of silently setting the duration field to None.
1.0.0
Catch GStreamer's exception when necessary components, such as uridecodebin, are missing. The GStreamer backend now accepts relative paths. Fix a hang in GStreamer when the stream finishes before it begins (when reading broken files). Initial support for Python 3.
0.8
All decoding errors are now subclasses of DecodeError.
0.7
Fix opening WAV and AIFF files via Unicode filenames.
0.6
Make FFmpeg timeout more robust. Dump FFmpeg output on timeout. Fix a nondeterministic hang in the Gstreamer backend. Fix a file descriptor leak in the MAD backend.
0.5
Fix crash when FFmpeg fails to report a duration. Fix a hang when FFmpeg fills up its stderr output buffer. Add a timeout to ffmpeg tool execution (currently 10 seconds for each 4096-byte read); a ReadTimeoutError exception is raised if the tool times out.
0.4
Fix channel count detection for FFmpeg backend.
0.3
Fix a problem with the Gstreamer backend where audio files could be left open even after the GstAudioFile was "closed".
0.2
Fix a hang in the GStreamer backend that occurs occasionally on some platforms.
0.1
Initial release.

Et Cetera

audioread is by Adrian Sampson. It is made available under the MIT license. An alternative to this module is decoder.py.

audioread's People

Contributors

aostanin avatar asellappen avatar bmcfee avatar bomme avatar carlthome avatar cosmologist avatar detrin avatar dpwe avatar flokx avatar iepathos avatar jcsaaddupuy avatar joshmoore avatar kmosiejczuk avatar laarmen avatar llamasoft avatar mightbecharles avatar piem avatar ryanmarcus avatar sampsyo avatar ssssam avatar timgates42 avatar toddrme2178 avatar xix-xeaon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

audioread's Issues

Error reading wav when given a unicode path to audio_open

The first thing audioread tries to do is open a wav/aiff file with aifc. aifc.open() takes a "string or fp type object". Unfortunately this doesn't appear to include unicode:

>>> import audioread
>>> w = audioread.audio_open(u"/some/path")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "audioread/__init__.py", line 55, in audio_open
    return rawread.RawAudioFile(path)
  File "audioread/rawread.py", line 45, in __init__
    self._file = aifc.open(filename)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/aifc.py", line 924, in open
    return Aifc_read(f)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/aifc.py", line 335, in __init__
    self.initfp(f)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/aifc.py", line 286, in initfp
    chunk = Chunk(file)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/chunk.py", line 61, in __init__
    self.chunkname = file.read(4)
AttributeError: 'unicode' object has no attribute 'read'

Maybe you could pass aifc.open an fp instead of filename to get around this?

"Cannot allocate memory" during chromaprint fingerprinting

Hi,

In the middle of fingerprinting ~1,700 songs, I got the following error. I had run "sudo -H pip install -U audioread" before, so the package should have been up to date.

Traceback (most recent call last):
  File "/usr/bin/beet", line 9, in <module>
    load_entry_point('beets==1.3.8', 'console_scripts', 'beet')()
  File "/usr/share/beets/beets/ui/__init__.py", line 964, in main
    _raw_main(args)
  File "/usr/share/beets/beets/ui/__init__.py", line 954, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/usr/share/beets/beetsplug/chroma.py", line 181, in fingerprint_cmd_func
    write=config['import']['write'].get(bool))
  File "/usr/share/beets/beetsplug/chroma.py", line 287, in fingerprint_item
    _, fp = acoustid.fingerprint_file(item.path)
  File "/usr/local/lib/python2.7/dist-packages/acoustid.py", line 321, in fingerprint_file
    return _fingerprint_file_audioread(path, maxlength)
  File "/usr/local/lib/python2.7/dist-packages/acoustid.py", line 262, in _fingerprint_file_audioread
    with audioread.audio_open(path) as f:
  File "/usr/local/lib/python2.7/dist-packages/audioread/__init__.py", line 83, in audio_open
    if _ca_available():
  File "/usr/local/lib/python2.7/dist-packages/audioread/__init__.py", line 57, in _ca_available
    lib = ctypes.util.find_library('AudioToolbox')
  File "/usr/lib/python2.7/ctypes/util.py", line 248, in find_library
    return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
  File "/usr/lib/python2.7/ctypes/util.py", line 237, in _findSoname_ldconfig
    f = os.popen('LC_ALL=C LANG=C /sbin/ldconfig -p 2>/dev/null')
OSError: [Errno 12] Cannot allocate memory

Regex for detecting stereo in ffmpeg

Hi, I'm trying out the lib and found that in ffdec.py the regex for detecting stereo isn't working.

The usual output I get is something like

duration: 00:04:38.00, bitrate: 1411 kb/sstream #0.0: audio: pcm_s16le, 44100 hz, 2 channels, s16, 1411 kb/s

Changing line 83 of ffdec.py to:

if mode == 'stereo' or mode == '2 channels':

Solves it.

Hanging in close()

Mac OS X 10.9, ffmpeg 2.1 from MacPorts, audioread 1.0.1 from pypi.

If I have the following small file (with the directory of MP3s being the one from this repository - https://github.com/mysociety/sayit ):

import audioread.ffdec
import os

def get_audio_duration(in_filename):
    f = audioread.ffdec.FFmpegAudioFile(in_filename)
    return round(f.duration)

root = 'speeches/fixtures/expected_outputs/mp3'
for mp3 in os.listdir(root):
    mp3 = os.path.join(root, mp3)
    print mp3, get_audio_duration(mp3)

Then sometimes it will run fine, but frequently it will hang on one of the files. As far as I have been able to work out, it is hanging on the wait() inside close(), but I'm not sure what I should do in order to debug it further. Running ffmpeg manually, I can't see any problems. I can Ctrl-C, in which case I get a message: Exception KeyboardInterrupt: KeyboardInterrupt() in <bound method FFmpegAudioFile.__del__ of <audioread.ffdec.FFmpegAudioFile object at 0x1087cff90>> ignored and the file continues running without issue (printing the duration, in this case), but leaves an ffmpeg process lying about that I have to manually kill -9.

Hope that's useful, do let me know if you'd like any further information to help debug or fix this.

Backend producing padded byte arrays

When working with mp3 files of indeterminate length, or ones that end on an odd number of PCM frames when decoded, as would be the case for variable bit rate MP3 streams, the yield statement occassionally returns zero.

with audioread.audio_open('workfile.mp3') as input_file:
    for data in input_file:
        # data is zero padded

Sample output for the above function might look like the following:

\xecD\xe4\xe2\xee\xd7\xe6\xd3\xf1\x9b\xe8\x99\xf4K\xe8S\xf5X\xe7\x8b\xf3\xe0\xe5\xd7\xf0\xf5\xe3\xf5\xee\xc8\xe3\xb3\xee\xa6\xe6\x0f\x0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00

This issue either needs documentation, or consideration for any "streaming" solution.

ffmpeg succeeds for broken FLAC

The same file as #3 succeeds in ffmpeg:

ffmpeg output

ffmpeg -i test/Somefile.flac -f s16le - > x
ffmpeg version 0.8.5-4:0.8.5-0ubuntu0.12.04.1, Copyright (c) 2000-2012 the Libav developers
built on Jan 24 2013 18:01:36 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
[flac @ 0x25c39c0] max_analyze_duration reached
Input #0, flac, from 'test/Somefile.flac':
[ ... ]
Press ctrl-c to stop encoding
[flac @ 0x25c5940] overread: 1
Error while decoding stream #0.0
Multiple frames in a packet from stream 0
[flac @ 0x25c5940] invalid sync code
[flac @ 0x25c5940] invalid frame header
[flac @ 0x25c5940] decode_frame() failed
Error while decoding stream #0.0
[flac @ 0x25c5940] invalid sync code
[flac @ 0x25c5940] invalid frame header
[flac @ 0x25c5940] decode_frame() failed
Error while decoding stream #0.0
[flac @ 0x25c5940] qlevel -8 not supported, maybe buggy stream
[flac @ 0x25c5940] decode_frame() failed
Error while decoding stream #0.0
[flac @ 0x25c5940] qlevel -10 not supported, maybe buggy stream
[flac @ 0x25c5940] decode_frame() failed
Error while decoding stream #0.0
[flac @ 0x25c5940] invalid sync code
[flac @ 0x25c5940] invalid frame header
[flac @ 0x25c5940] decode_frame() failed
[ ... ]
[flac @ 0x25c5940] invalid sync code
[flac @ 0x25c5940] invalid frame header
[flac @ 0x25c5940] decode_frame() failed
Error while decoding stream #0.0
size= 33218kB time=192.83 bitrate=1411.2kbits/s

video:0kB audio:33218kB global headers:0kB muxing overhead 0.000000%

and the best:

echo $?
0

rawread does not work with python3

using the 1.0.3 version of rawread does not work with python3, to get it running i had to change the following:
replace xrange with range, add b to ''.join

*** 31,41 ****
"""
assert len(s) % 2 == 0
parts = []
! for i in range(0, len(s), 2):
chunk = s[i:i+2]
newchunk =struct.pack('<h', *struct.unpack('>h', chunk))
parts.append(newchunk)
! return b''.join(parts)

FFMPEG installed but no backend error is still occuring

Dear sir/madam,
Audio read raised the no backend error. So, I installed ffmpeg on my computer and verified its installation too. But when I run my code in the ipython console, I still get the No Backend error. What should I do?

i try to open an audio with m4a format and i got NoBackendError

hi ! thanks for this lib!
i have a audio with m4a format and i want get the content through audioread , but when i doing this i get an error , my code like this:

import audioread
file = './tingting.m4a'
with audioread.audio_open(file) as f:
    print(f.duration, f.channels)
    for buf in f:
        print(f)

the error like this:

NoBackendError                            Traceback (most recent call last)
<ipython-input-8-da9eca8a7457> in <module>()
      1 import audioread
      2 file = './tingting.m4a'
----> 3 with audioread.audio_open(file) as f:
      4     print(f.duration, f.channels)
      5     for buf in f:

D:\Users\keltsing\Anaconda3\lib\site-packages\audioread\__init__.py in audio_open(path)
    114 
    115     # All backends failed!
--> 116     raise NoBackendError()

NoBackendError: 

do i choice a wrong audio format? if that's true, which format audioread support?

The results are different when opening the same file multiple times

Hi there,
I found that the results are different when I open the same file (*.ogg, *.3gpp) multiple times.
The reason is that audioread excutes gstdec when _gst_available() is True, and the result of gstdec has some problem.
I wrote a test to check it.

#coding=utf-8
import numpy as np
from audioread import gstdec
filename = "X23_01.ogg"

w = []
for _ in range(3):
    g = gstdec.GstAudioFile(filename)
    k = 0
    with g as input_file:
        for frame in g:
            w.append(frame)
            break
for i in range(20):
    print (w[0][i], w[1][i], w[2][i])

The output is

('\xfe', '\x00', '\x00')
('\xff', '\x00', '\x00')
('\xfe', '\xfe', '\xfe')
('\xff', '\xff', '\xff')
('\xfe', '\xfe', '\xff')
('\xff', '\xff', '\xff')
('\xfe', '\xfe', '\xfe')
('\xff', '\xff', '\xff')
('\xff', '\xff', '\xff')
('\xff', '\xff', '\xff')
('\xff', '\xff', '\xff')
('\xff', '\xff', '\xff')
('\x00', '\x00', '\x00')
('\x00', '\x00', '\x00')
('\x00', '\x00', '\x00')
('\x00', '\x00', '\x00')
('\x01', '\x02', '\x02')
('\x00', '\x00', '\x00')
('\x00', '\x00', '\x00')
('\x00', '\x00', '\x00')

I tried several *.ogg or *.3gpp files, the results are still different when opening the same file multiple times.

Jupyter notebook audioread.nobackend error

_RemoteTraceback Traceback (most recent call last)
_RemoteTraceback:
"""
Traceback (most recent call last):
File "C:\Users\neel.nath\AppData\Local\Programs\Python\Python36\Lib\site-packages\joblib\externals\loky\process_executor.py", line 398, in process_worker
r = call_item.fn(*call_item.args, **call_item.kwargs)
File "C:\Users\neel.nath\AppData\Local\Programs\Python\Python36\Lib\site-packages\joblib_parallel_backends.py", line 561, in call
return self.func(*args, **kwargs)
File "C:\Users\neel.nath\AppData\Local\Programs\Python\Python36\Lib\site-packages\joblib\parallel.py", line 224, in call
for func, args, kwargs in self.items]
File "C:\Users\neel.nath\AppData\Local\Programs\Python\Python36\Lib\site-packages\joblib\parallel.py", line 224, in
for func, args, kwargs in self.items]
File "", line 6, in save_folds
File "", line 15, in extract_features
File "", line 4, in read_audio
File "C:\Users\neel.nath\AppData\Local\Programs\Python\Python36\Lib\site-packages\librosa\core\audio.py", line 112, in load
with audioread.audio_open(os.path.realpath(path)) as input_file:
File "C:\Users\neel.nath\AppData\Local\Programs\Python\Python36\Lib\site-packages\audioread_init
.py", line 116, in audio_open
raise NoBackendError()
audioread.NoBackendError
"""

The above exception was the direct cause of the following exception:

NoBackendError Traceback (most recent call last)
in ()

~\AppData\Local\Programs\Python\Python36\Lib\site-packages\joblib\parallel.py in call(self, iterable)
960
961 with self._backend.retrieval_context():
--> 962 self.retrieve()
963 # Make sure that we get a last message telling us we are done
964 elapsed_time = time.time() - self._start_time

~\AppData\Local\Programs\Python\Python36\Lib\site-packages\joblib\parallel.py in retrieve(self)
863 try:
864 if getattr(self._backend, 'supports_timeout', False):
--> 865 self._output.extend(job.get(timeout=self.timeout))
866 else:
867 self._output.extend(job.get())

~\AppData\Local\Programs\Python\Python36\Lib\site-packages\joblib_parallel_backends.py in wrap_future_result(future, timeout)
513 AsyncResults.get from multiprocessing."""
514 try:
--> 515 return future.result(timeout=timeout)
516 except LokyTimeoutError:
517 raise TimeoutError()

~\AppData\Local\Programs\Python\Python36\Lib\site-packages\joblib\externals\loky_base.py in result(self, timeout)
429 raise CancelledError()
430 elif self._state == FINISHED:
--> 431 return self.__get_result()
432 else:
433 raise TimeoutError()

~\AppData\Local\Programs\Python\Python36\Lib\site-packages\joblib\externals\loky_base.py in __get_result(self)
380 def __get_result(self):
381 if self._exception:
--> 382 raise self._exception
383 else:
384 return self._result

NoBackendError:

gi dependency breaks due to package namespace collision

The gstreamer backend tries to import the gi package. This package appears to have some kind of a namespace collision on pypi, and will cause failures if https://pypi.python.org/pypi/gi is installed.

Specifically, before it can even fail due to missing API, it will crash on python3 because the gi.py module uses a print statement instead of a function call.

I'm not sure there's a good solution to this, since you can't use install-requires for optional dependencies here.

EDIT: reference librosa group thread here: https://groups.google.com/forum/#!topic/librosa/pKT3z2NYKIE

aubio backend

hi there,

Not really a bug, not really a PR: I played around with aubio and audioread to see how they could work together.

Using aubio's current HEAD and python3, this simple backend for aubio works well, including on remote streams.

This is vastly inefficient though, since aubio's arrays of floats need to be flattened back to a buffer of shorts, but for some reason I thought I should make some noise about it. :-)

cheers, piem

ffdec: Dynamic linker errors are misreported as "file not found" errors

When reading mp3 files I get the following output:

 Traceback (most recent call last):
2017-12-11T06:09:20.901633+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
2017-12-11T06:09:20.901634+00:00 app[web.1]:     response = self.full_dispatch_request()
2017-12-11T06:09:20.901635+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
2017-12-11T06:09:20.901635+00:00 app[web.1]:     rv = self.handle_user_exception(e)
2017-12-11T06:09:20.901640+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
2017-12-11T06:09:20.901641+00:00 app[web.1]:     reraise(exc_type, exc_value, tb)
2017-12-11T06:09:20.901641+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
2017-12-11T06:09:20.901642+00:00 app[web.1]:     raise value
2017-12-11T06:09:20.901643+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
2017-12-11T06:09:20.901644+00:00 app[web.1]:     rv = self.dispatch_request()
2017-12-11T06:09:20.901644+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
2017-12-11T06:09:20.901645+00:00 app[web.1]:     return self.view_functions[rule.endpoint](**req.view_args)
2017-12-11T06:09:20.901646+00:00 app[web.1]:   File "/app/flask_app.py", line 27, in display_drum
2017-12-11T06:09:20.901646+00:00 app[web.1]:     song, sr = librosa.core.load(path)
2017-12-11T06:09:20.901647+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/librosa/core/audio.py", line 107, in load
2017-12-11T06:09:20.901648+00:00 app[web.1]:     with audioread.audio_open(os.path.realpath(path)) as input_file:
2017-12-11T06:09:20.901648+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/audioread/__init__.py", line 111, in audio_open
2017-12-11T06:09:20.901649+00:00 app[web.1]:     return ffdec.FFmpegAudioFile(path)
2017-12-11T06:09:20.901650+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/audioread/ffdec.py", line 150, in __init__
2017-12-11T06:09:20.901651+00:00 app[web.1]:     self._get_info()
2017-12-11T06:09:20.901651+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/audioread/ffdec.py", line 206, in _get_info
2017-12-11T06:09:20.901652+00:00 app[web.1]:     raise IOError('file not found')
2017-12-11T06:09:20.901658+00:00 app[web.1]: OSError: file not found

I have the following packages:

audioread==2.1.5
certifi==2017.11.5
chardet==3.0.4
click==6.7
cycler==0.10.0
decorator==4.1.2
Flask==0.12.2
gunicorn==19.7.1
idna==2.6
itsdangerous==0.24
Jinja2==2.10
joblib==0.11
librosa==0.5.1
llvmlite==0.21.0
MarkupSafe==1.0
matplotlib==2.1.0
numba==0.36.1
numpy==1.13.3
pyparsing==2.2.0
python-dateutil==2.6.1
pytz==2017.3
requests==2.18.4
resampy==0.2.0
scikit-learn==0.19.1
scipy==1.0.0
six==1.11.0
tabulate==0.8.2
urllib3==1.22
Werkzeug==0.13

ffmpeg is installed

GStreamer hang on broken FLAC

During the process of importing my FLAC collection to beet, the import always stopped at one point. I found the file in question and was able to downtrace it to gstdec GstAudioFile stopping at init after self.ready_sem.acquire(). After that I was kind of lost with gst and whatnot ^^

The FLAC file is broken, so I believe audioread should come back with an error. I suspect this could be a bug in gst, but I'm not sure so I report it here first. If it's ok for you, I would send you the file in question or upload it somewhere (~25MB).

flac -t says:

flac 1.2.1, Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007 Josh Coalson
flac comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
welcome to redistribute it under certain conditions. Type `flac' for details.

Somefile.flac: *** Got error code 0:FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC
Somefile.flac: *** Got error code 0:FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC

Somefile.flac: ERROR while decoding data
state = FLAC__STREAM_DECODER_READ_FRAME

ffmpeg decode fails in Cygwin

I've been having issues on Cygwin with beets and the chroma plugin, but they all seem to be rooted around the audioread package. The problem is that the filename passed into the popen_multiple command needs to be quoted for Cygwin Python. I was getting file not found errors from beets when I first started trying to run it with the chroma plugin in Cygwin. Once I edited the ffdec.py file to add quotes around the filename those went away and the ffmpeg process began running properly.

audioread race condition freezes when cleaning up

I have a flac file that causes acoustid to freeze when doing:

import acoustid
acoustid.fingerprint_file('01.flac')

If I press Ctrl-C, I get the following backtrace:

Traceback (most recent call last):
  File "/usr/lib64/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/site-packages/audioread/gstdec.py", line 149, in run
    self.loop.run()
  File "/usr/lib64/python3.6/site-packages/gi/overrides/GLib.py", line 588, in run
    raise KeyboardInterrupt

Btw, the file plays perfectly fine with ffplay, mpv, mplayer... Also, I tried reading the audio blocks with simple audioread code like:

with audioread.audio_open(path) as f:
    for x in f:
        print(x)

and that seems to work fine.

What makes me think that it's an audioread issue and not an acoustid issue is that in audioread's gstdec.py, if I put return None as the first line of get_loop_thread, it doesn't freeze (works normally).

I've tried to debug a bit the problem and noticed that acoustid has a _fingerprint_file_audioread function defined as:

def _fingerprint_file_audioread(path, maxlength):
    """Fingerprint a file by using audioread and chromaprint."""
    try:
        with audioread.audio_open(path) as f:
            duration = f.duration
            fp = fingerprint(f.samplerate, f.channels, iter(f), maxlength)
    except audioread.DecodeError:
        raise FingerprintGenerationError("audio could not be decoded")
    return duration, fp

If I add time.sleep(0.00000000000001) at the end of the with block (just after the fingerprint call), sometimes it works as expected, and if I use time.sleep(0.1) instead, it seems to "fix it" and doesn't freeze anymore, so it seems to be some kind of race condition.

After some more debugging I found out that the exact line where it's freezing is in the call to self.pipeline.set_state(Gst.State.NULL) inside GstAudioFile.close but I'm not sure how to continue from there since I don't have much experience with gstreamer.

I'm using audioread 2.1.5, gstreamer 1.12.3 and pyacoustid 1.1.5 with chromaprint 1.4.2 . I also tried with gstreamer 1.12.2 and audioread 2.1.4.

Btw, another solution I found was to do ffmpeg -i 01.flac output.flac. The resulting file is processed correctly and never freezes.

NoBackendError despite a backend (specifically FFmpeg) being installed

Hello!

This is my first time posting an issue, so please cut me some slack if I'm not following some protocol!

I was trying to use python's librosa package on Windows 10 and encountered the following issue.

After running x, _ = librosa.load('data/fma_small/000/000002.mp3', sr = None) I receive this stack trace:

---------------------------------------------------------------------------
NoBackendError                            Traceback (most recent call last)
<ipython-input-2-15a8daa0e7fd> in <module>()
      1 start, end = 7, 17
      2 filename = utils.get_audio_path(AUDIO_DIR, 2)
----> 3 x, sr = librosa.load(filename, sr = None, mono = True)

Q:\Program Files\Anaconda3\lib\site-packages\librosa\core\audio.py in load(path, sr, mono, offset, duration, dtype, res_type)
    105 
    106     y = []
--> 107     with audioread.audio_open(os.path.realpath(path)) as input_file:
    108         sr_native = input_file.samplerate
    109         n_channels = input_file.channels

Q:\Program Files\Anaconda3\lib\site-packages\audioread\__init__.py in audio_open(path)
    112 
    113     # All backends failed!
--> 114     raise NoBackendError()

NoBackendError:

Out of curiosity, I also tried to run audioread.ffdec.FFmpegAudioFile('data/fma_small/000/000002.mp3') (since I know that FFmpeg is installed) but I received:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Q:\Program Files\Anaconda3\lib\site-packages\audioread\ffdec.py in __init__(self, filename, block_size)
    126                 stderr=subprocess.PIPE,
--> 127                 stdin=self.devnull,
    128             )

Q:\Program Files\Anaconda3\lib\site-packages\audioread\ffdec.py in popen_multiple(commands, command_args, *args, **kwargs)
     88         try:
---> 89             return subprocess.Popen(cmd, *args, **kwargs)
     90         except OSError:

Q:\Program Files\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds)
    946                                 errread, errwrite,
--> 947                                 restore_signals, start_new_session)
    948         except:

Q:\Program Files\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
   1223                                          cwd,
-> 1224                                          startupinfo)
   1225             finally:

FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

NotInstalledError                         Traceback (most recent call last)
<ipython-input-6-be3b460211e8> in <module>()
----> 1 audioread.ffdec.FFmpegAudioFile(filename)

Q:\Program Files\Anaconda3\lib\site-packages\audioread\ffdec.py in __init__(self, filename, block_size)
    129 
    130         except OSError:
--> 131             raise NotInstalledError()
    132 
    133         finally:

NotInstalledError:

Again, I have FFmpeg installed, and ffmpeg works as a command in cmd.

Is anyone able to spot the problem?

Thanks!

Gstreamer backend can return None for duration

Currently, in a few exceptional cases, the Gstreamer backend can set the file's duration field to None. This is unexpected; other backends make this impossible. The backend should raise an exception instead of allowing a null duration.

Duration determination occurs in the _notify_caps callback method in gstdec.py.

support for libav (ffmpeg is not in ubuntu 14.04)

it would be handy if this package supported libav as well as ffmpeg as ubuntu does not support ffmpeg in recent versions. I understand there are slight calling differences.

(and thank you for this package!)

-brewster
Internet Archive

Don't use `select` on Windows

As reported in beetbox/beets#344, the FFmpeg backend doesn't work on Windows because we're using a select call to do a non-blocking read on the output pipe of the ffmpeg process. (On Windows, select only works on sockets.) We could get around this by using a separate thread for reading the subprocess stdout stream and terminating the thread on a timeout.

Relevant Stack Overflow answer.

Conda-forge packaging

Hey, at the scipy2016 sprints, I took the liberty of making a conda forge recipe and feedstock for audioread. This way, downstream libraries can be packaged on conda easily.

I don't mind maintaining this for a bit, but ownership/write access should probably move to this org at some point. What's the best way to manage this?

bus unref needed in GstAudioFile

Hi, I got an error while calling audio_open() several times(with .mp3 files). Looks like it is due to accumulated refs of bus objects in GstAudioFile. I gave it a monkey patch and apparently it seems fine. However, since my files are not gst-encoded, I'm not sure whether this would cause any problem with actual gst decoding tasks.

In my case, I inserted following lines in GstAudioFile.close():

bus = self.pipeline.get_bus()
bus.unref()
bus.remove_signal_watch()

audioread.NoBackendError on Travis

The following .travis.yml produces an audioread.NoBackendError when LibROSA tries to open a Ogg file with audioread.

dist: trusty
language: python
python: 3.6
cache: pip
addons:
  apt:
    packages:
      - libav-tools
install: pip install librosa
script: 
  - python -c "import librosa; librosa.load(librosa.util.example_audio_file())"

rawread error with 24bit wave

Hi,

I'm currently facing a problem trying to read PCM S24 LE encoded wave files. I get the following error on an UBUNTU host using Anaconda with up-to-date libraries:

File "/home/schindler/anaconda/lib/python2.7/site-packages/audioread/rawread.py", line 112, in read_data
    data = audioop.lin2lin(data, old_width, TARGET_WIDTH)
audioop.error: Size should be 1, 2 or 4

I printed the arguments just before the failing statements:

print len(data), old_width, TARGET_WIDTH
data = audioop.lin2lin(data, old_width, TARGET_WIDTH)

and received these values:

6144, 3, 2

here some infomration about the audio file:

soxi

Input File     : '/data/music/DCASE2016/task1/TUT-acoustic-scenes-2016-development/audio/b106_0_30.wav'
Channels       : 2
Sample Rate    : 44100
Precision      : 24-bit
Duration       : 00:00:30.00 = 1323001 samples = 2250 CDDA sectors
File Size      : 7.94M
Bit Rate       : 2.12M
Sample Encoding: 24-bit Signed Integer PCM

ffprobe

Input #0, wav, from '/data/music/DCASE2016/task1/TUT-acoustic-scenes-2016-development/audio/b106_0_30.wav':
  Duration: 00:00:30.00, bitrate: 2116 kb/s
    Stream #0:0: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 44100 Hz, 2 channels, s32 (24 bit), 2116 kb/s

IndexError

I got this error "IndexError: list index out of range" and i try to change the decode (sys.argv[0]) and it said that the file could not be decoded.

WindowsError: [Error 5] Access is denied

I get this error from ffedc.py:

  File "C:\Python27\lib\site-packages\audioread\ffdec.py", line 279, in __exit__
    self.close()
  File "C:\Python27\lib\site-packages\audioread\ffdec.py", line 263, in close
    self.proc.kill()
  File "C:\Python27\lib\subprocess.py", line 1002, in terminate
    _subprocess.TerminateProcess(self._handle, 1)
WindowsError: [Error 5] Access is denied

I've been searching how to resolve it and found this on stackoverflow:
https://stackoverflow.com/questions/17076679/windowserror-access-is-denied-on-calling-process-terminate

But even trying this try-catch trick doesn't work when I modify ffdec.py.
Looks like issue might be related to this:
https://stackoverflow.com/questions/5573257/windowserror-error-5-access-is-denied-when-trying-to-kill-a-subprocess-pytho

But still don't know how to resolve. I tried running my code with admin privileges too and I have all the permissions to modify my file.

Python 3 iteration and bytes with Gstreamer decoder

The iterator for the Gstreamer decoder in Python 3 gives this error:

Traceback (most recent call last):
  File "./undermystic.py", line 23, in <module>
    for buf in f:
TypeError: iter() returned non-iterator of type 'GstAudioFile'

And also, the _new_sample function turns the byte-data into utf-8 strings.

I've fixed these simple Python 3 issues and will do a pull request.

audioread.__version__

It would be great if audioread exposed its current version information in the standard place (audioread.__version__).

This would be useful mainly for upstream debugging / error reporting.

TypeError: expected str, bytes or os.PathLike object, not SpooledTemporaryFile

Hi,
I am trying to load my byte data that is in binary format into audioread.audio_open, ideally I should directly give path for the audio file but I am trying to decode the mp3 after loading my audio file into tensorflow and there arises the issue.

Complete Trace Back is as Follows:
`TypeError Traceback (most recent call last)
in ()
----> 1 au = aio(buffer)

c:\users\shivam.agarwal\pycharmprojects\audioapi\venv\lib\site-packages\audioread_init_.py in audio_open(path)
78 from . import rawread
79 try:
---> 80 return rawread.RawAudioFile(path)
81 except DecodeError:
82 pass

c:\users\shivam.agarwal\pycharmprojects\audioapi\venv\lib\site-packages\audioread\rawread.py in init(self, filename)
59 """
60 def init(self, filename):
---> 61 self._fh = open(filename, 'rb')
62
63 try:
`

I tried to load the bytes as file-like object from SpooledTemporaryFile but this open in 'rb' format keeps giving the issue.

How should I load the bytes as file-like object ?

Deprecation warnings in gstdec.py

/usr/local/lib/python2.7/dist-packages/audioread/gstdec.py:126: PyGIDeprecationWarning: Since version 3.11, calling threads_init is no longer needed. See: https://wiki.gnome.org/PyGObject/Threading
  GObject.threads_init()
/usr/local/lib/python2.7/dist-packages/audioread/gstdec.py:146: PyGIDeprecationWarning: MainLoop is deprecated; use GLib.MainLoop instead
  self.loop = GObject.MainLoop()

Move `block_size` KWarg to initialization?

I'm browsing through the backends, and it looks kind of inconsistent how we sometimes hand block_size or block_samples to read_data, and sometimes we pass it to the initialization?

Furthermore, def audio_open(path): doesn't take a block_size parameter, so users can't use it unless they use a backend directly.

I think we could improve the lib by adding block_size to audio_open. For the existing backends that have read_data(blocksize=*) we could still allow them to override blocksize on the read_data level. It shouldn't be breaking change if we do it this way.

In memory decoding

Hi guys!
I have audio files contents stored in-memory and need to decode audio. In current version all backends accept pathlike argument (which is then passed to open()).

Are there any plans to extend your interface to also accept streams of data (e.g. BytesIO)?

audioread + Bash on Windows

Hi there,

I was using librosa on my Windows machine via Bash on Windows and came across this error:

File "venv/local/lib/python2.7/site-packages/librosa/core/audio.py", line 144, in load
    y.append(frame)
  File "venv/local/lib/python2.7/site-packages/audioread/ffdec.py", line 279, in __exit__
    self.close()
  File "venv/local/lib/python2.7/site-packages/audioread/ffdec.py", line 263, in close
    self.proc.kill()
  File "/usr/lib/python2.7/subprocess.py", line 1572, in kill
    self.send_signal(signal.SIGKILL)
  File "/usr/lib/python2.7/subprocess.py", line 1562, in send_signal
    os.kill(self.pid, sig)
OSError: [Errno 3] No such process
Exception OSError: (3, 'No such process') in <bound method FFmpegAudioFile.__del__ of <audioread.ffdec.FFmpegAudioFile object at 0x7fcae7a492d0>>
 ignored

I think other folks with this (admittedly odd) usage pattern have seen similar issues as well (librosa/librosa#536).

Any thoughts on this? Thanks!

Getting segmentation fault after using audioread for MP4s

I had been using audioread to get the audio from MP4 videos from different cameras, in order to synchronize them.

I have noticed that I am now getting a segmentation fault when all is done, and have debugged it to be something in audioread. Some minimal code to get this is included below. The expected behavior is it should open the MP4 file, do its thing, and exit; what I get is it does its thing but exits with a segmentation fault. I have commented out all remaining imports (cv2 and numpy) and I still get the segmentation fault. Platform is up-to-date Linux Ubuntu 14.04; the problem does not occur on a Mac. audioread is using gstdec to go through the MP4 and I tried both the

with audioread.audio_open() as f

and the current

try: (etc) finally: f.close()

syntax listed in the audioread docs. Perhaps there is a problem in how the stream is closed, or in gstreamer?

Any suggestions?
-Dennis

!/usr/bin/env python

import cv2

import audioread

import numpy as np

if name == "main":

# THIS PART IS OK
#blue = cv2.VideoCapture("blue.MP4")
#print ("Blue fps: {0}".format(blue.get(cv2.cv.CV_CAP_PROP_FPS)))
#blue = None

# THIS PART RUNS OK BUT.... 
temp = bytearray()
f = audioread.audio_open("blue.MP4")
try:
    samplerate = f.samplerate
    duration = f.duration
    channels = f.channels
    for block in f:
        #print np.frombuffer(block,dtype=np.int16)
        temp.extend(block)
finally:
    f.close()
    f = None

#signal = np.frombuffer(temp,dtype=np.dtype('<i2')) #.reshape(-1,channels)
print f
print samplerate,duration,channels
#print signal

# IT GIVES SEG FAULT HERE AT END OF RUNNING, UPON EXITING

Gstreamer/PyGObject breaks SIGINT handling

GLib.MainLoop.__init__ installs a SIGINT handler which calls GLib.MainLoop.quit(),
and then reraise a KeyboardInterrupt in that thread.
However, the main thread will not notice that, and continues whatever it is doing, which mostly means that it will hang as it is waiting for something.
What you would want is a KeyboardInterrupt in the main thread, as this is the original behavior when you press Ctrl+C.

I came up with this workaround / ugly monkey patch to just disable the SIGINT handler.
However, a better fix would be in PyGObject to raise the KeyboardInterrupt in the main thread.

def monkeyfix_glib():
  """
  Fixes some stupid bugs such that SIGINT is not working.
  This is used by audioread, and indirectly by librosa for loading audio.
  https://stackoverflow.com/questions/16410852/
  """
  try:
    import gi
  except ImportError:
    return
  try:
    from gi.repository import GLib
  except ImportError:
    from gi.overrides import GLib
  # Do nothing.
  # The original behavior would install a SIGINT handler which calls GLib.MainLoop.quit(),
  # and then reraise a KeyboardInterrupt in that thread.
  # However, we want and expect to get the KeyboardInterrupt in the main thread.
  GLib.MainLoop.__init__ = lambda *args, **kwargs: None

Do not use hardcoded scheme in GstAudioFile

GStreamer supports e.g. http-audiostreams, but the current implementation in gstdec.py prefixes everything with file://; if that prefix would be added only when there isn't any scheme already provided, GstAudioFile could be used for example with Internet radio streams (which was my original goal when I came across this library, since this nicely abstracts the gory details of GStreamer):

radio_stream = 'http://mp3channels.webradio.antenne.de/chillout'
with audioread.gstdec.GstAudioFile(radio_stream) as f:
  process_stream(f)

Obviously, it would be even nicer if the user of this library wouldn't even need to know what backend is used in the above case, and could just pass the URL in audioread.audio_open (unless this library is wanted to kept file-only for some reason).

Support for Seeking to a frame?

Hello,
Are there any plans to support seeking to a specific frame?

I'm writing a small app that shows a song's Hz spectograph and, and allows play/pausing of the song along with the spectograph. Play/pause works great, but I'd like a way to reset what frame we're reading from. (That would allow to the user to "stop" and set the time to 0, or click on a spot and seek to that spot.)

I found that the OSX AudioToolbox backend has ExtAudioFileSeek: https://developer.apple.com/documentation/audiotoolbox/1486821-extaudiofileread?language=objc

And Python aifc has:

aifc.rewind()
aifc.setpos(pos)

https://docs.python.org/3.6/library/aifc.html

Backends to investigate:

  • rawread.py/aifc (has aifc.setpos)
  • ffdec ffmpeg (has a seek option on command start. Audioread might have to close & restart the channel on seek?)
  • gstdec.py/Gstreamer / pygobject (has IOChannel.seek)
  • macca.py/AudioToolbox (has ExtAudioFileSeek)
  • maddec.py/MAD/pymad (has seek_time)

No backend with ffmpeg installed

Hi,

I'm running this implementation of WaveNet which uses librosa, which uses audioread. From python train.py --data_dir=corpus

Traceback (most recent call last):
  File "C:\Users\Skylar\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "C:\Users\Skylar\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Skylar\Documents\WaveNet-Playground\wavenet\audio_reader.py", line 158, in thread_main
    for audio, filename, category_id in iterator:
  File "C:\Users\Skylar\Documents\WaveNet-Playground\wavenet\audio_reader.py", line 59, in load_generic_audio
    audio, _ = librosa.load(filename, sr=sample_rate, mono=True)
  File "C:\Users\Skylar\AppData\Local\Programs\Python\Python36\lib\site-packages\librosa\core\audio.py", line 112, in load
    with audioread.audio_open(os.path.realpath(path)) as input_file:
  File "C:\Users\Skylar\AppData\Local\Programs\Python\Python36\lib\site-packages\audioread\__init__.py", line 116, in audio_open
    raise NoBackendError()
audioread.NoBackendError

Here's ffmpeg -version

C:\Users\Skylar>ffmpeg -version
ffmpeg version 3.4.2 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7.3.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libmfx --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth
libavutil      55. 78.100 / 55. 78.100
libavcodec     57.107.100 / 57.107.100
libavformat    57. 83.100 / 57. 83.100
libavdevice    57. 10.100 / 57. 10.100
libavfilter     6.107.100 /  6.107.100
libswscale      4.  8.100 /  4.  8.100
libswresample   2.  9.100 /  2.  9.100
libpostproc    54.  7.100 / 54.  7.100

I'm on Windows 10 64-bit using python 3.6.2, librosa 0.6.0, and audioread 2.1.5.

Other tests include

>>>import audioread
>>>obj = audioread.audio_open("p267.001.wav")
>>>print(obj)
<audioread.rawread.RawAudioFile object at 0x000001FF672F1E48>
>>>obj.close()

>>> import librosa
>>> y, sr = librosa.load("p267_001.wav")
>>> print(y)
[ 0.0028438   0.00509119  0.00463691 ... -0.00268854 -0.0024589  0.        ]
>>> print(sr)
22050

So, things seem to be working well in the libraries, perhaps it's a bug in the forked code?

Reading .wav file does not prefer rawread

Hi,

First off, I'm using audioread in a multiprocessing-forked process, which might cause some bugs.

However, the forked process tries to load a whole bunch of .wav files, but for all of them, it does not use the RawAudioFile. Mostly it uses FFmpegAudioFile, or even tries MadAudioFile, with sometimes weird results. After reading and testing a bit, it seems to use the RawAudioFile only for the AIFF format.

After some reading and playing around, it seems that adding self._fh.seek(0) in the exception handling of aifc fixes that problem, that is, in rawread.py, add on line 52:
except aifc.Error:
self._fh.seek(0) # add this

I hope you can include this fix in a following release. Thanks very much for all the neat work! Cheers!
Hedde

DecodeErrors leak file descriptors

I noticed this warning popping up in librosa's unit tests:

/home/travis/env/miniconda3.4/envs/test-environment/lib/python3.4/site-packages/audioread/__init__.py:80: ResourceWarning: unclosed file <_io.BufferedReader name='/home/travis/build/librosa/librosa/librosa/util/example_data/Kevin_MacLeod_-_Vibe_Ace.ogg'>

After digging into it, I think the problem is that the RawAudioFile object first opens the target file here and then later throws an exception if the file cannot be decoded here. The initial file descriptor (self._fh) is never explicitly closed; the warning pops up on python 3 when the object goes out of scope and gets garbage collected.

While this isn't a major problem since the descriptors are read-only and things do eventually get hit by the GC, it should be easily avoidable by closing the handle before raising the UnsupportedError exception.

gstreamer not getting duration

Hi,

I've installed beets on linux mint 17.3.

I'm trying to get the chroma plugin to work but I got an error during import with every mp3 file saying

'''chroma: fingerprinting of 'music_raw/foo.mp3' failed: audio could not be decoded'''

I tried digging a bit in ipython and got to this point:

In [10]: f = gstdec.GstAudioFile("Pearl Jam - I Am Mine.mp3")
---------------------------------------------------------------------------
MetadataMissingError                      Traceback (most recent call last)
<ipython-input-10-ae222d97b34d> in <module>()
----> 1 f = gstdec.GstAudioFile("Leona Lewis - Bleeding in Love.mp3")

/usr/local/lib/python2.7/dist-packages/audioread/gstdec.pyc in __init__(self, path)
    256             # An error occurred before the stream became ready.
    257             self.close(True)
--> 258             raise self.read_exc
    259 
    260     # Gstreamer callbacks.

MetadataMissingError: duration not available

I am able to play these files in other music players.

Not sure what information you need to reproduce the error but if you let know I'll post it.

Python libs:

$pip freeze
BeautifulSoup==3.2.1
Mako==0.9.1
MarkupSafe==0.18
PAM==0.4.2
Pillow==2.3.0
PyBluez==0.18
PyYAML==3.11
Twisted-Core==13.2.0
Twisted-Names==13.2.0
Twisted-Web==13.2.0
Unidecode==0.04.19
apt-xapian-index==0.45
apturl==0.4.1ubuntu4
argparse==1.2.1
audioread==2.1.2
beets==1.3.17
ccsm==0.9.11.3
chardet==2.0.1
colorama==0.2.5
command-not-found==0.3
compizconfig-python==0.9.11.3
configglue==1.1.2
configobj==4.7.2
debtagshw==0.1
decorator==3.4.0
defer==1.0.6
dirspec==13.10
dnspython==1.11.1
duplicity==0.6.23
enum34==1.1.6
feedparser==5.1.3
html5lib==0.999
httplib2==0.8
iotop==0.6
ipython==1.2.1
jellyfish==0.5.4
lockfile==0.8
lxml==3.3.3
munkres==1.0.7
musicbrainzngs==0.6
mutagen==1.32
oauthlib==0.6.1
oneconf==0.3.7.14.04.1
paramiko==1.10.1
pexpect==3.1
piston-mini-client==0.7.5
protobuf==2.5.0
pyOpenSSL==0.13
pyacoustid==1.1.0
pycrypto==2.6.1
pycups==1.9.66
pycurl==7.19.3
pygobject==3.12.0
pyinotify==0.9.4
pyserial==2.6
pysmbc==1.0.14.1
python-apt==0.9.3.5ubuntu2
python-debian==0.1.21-nmu2ubuntu2
python-xlib==0.14
pyxdg==0.25
reportlab==3.0
requests==2.2.1
sessioninstaller==0.0.0
simplegeneric==0.8.1
simplejson==3.3.1
six==1.5.2
system-service==0.1.6
trimage==1.0.2
uTidylib==0.2
urllib3==1.7.1
vboxapi==1.0
virtualenv==1.11.4
wsgiref==0.1.2
zope.interface==4.0.5

Gstreamer version:

$gst-play-1.0 --version
gst-play-1.0 version 1.2.4
GStreamer 1.2.4
https://launchpad.net/distros/ubuntu/+source/gst-plugins-base1.0

Any help will be appreciated!

ffdec should not assume s16le format

hi,

ffdec will silently fail (providing unreliable output) when fed with non s16le files cause we enforce it in ffdec.py

maybe just removing the option would allow for autodetection? not sure.

add PySoundFile backend, and even make it default

On my system, it was using Gstreamer, which had several issues (e.g. #57, #62 and #63).
Then I tried PySoundFile, which was even faster (0:04:31 vs 0:05:38), and does not have any of those issues.
A related discussion for librosa is here.
So, I think it would make sense for audioread to add PySoundFile as an additional backend, and even make it the default.

update version 2.1.5 on conda-forge?

The outdated version on conda-forge requires ffmpeg version as 2.8.*, which conflicts with lost of packages that depends on newer version of ffmpeg, including opencv. I have tried to update the recipe on conda-forge and made a pull request, but not all checks are passed and I am not familiar with that. Would the developers like to update the package on conda-forge to the newest 2.1.5? Thanks a lot.

ffmpeg backend mucks with standard input on `close()`

As discovered in beetbox/beets#2039, we appear to cause problems on f.close() in with the FFmpeg backend. Specifically, subsequent calls to read from standard input (i.e., raw_input() calls) no longer receive any keyboard input.

This is easy to reproduce with this tiny test script:

import audioread.ffdec
f = audioread.ffdec.FFmpegAudioFile('xxx.m4a')
f.close()
raw_input('prompt: ')

I was able to narrow down the problem to e31af0b, which was our fix for #9. If I change that line to send SIGTERM instead of SIGKILL to the ffmpeg process, everything works fine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.