Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support audio with frame rates over 48k #134

Closed
jiaaro opened this issue Apr 20, 2016 · 4 comments · Fixed by #262
Closed

Support audio with frame rates over 48k #134

jiaaro opened this issue Apr 20, 2016 · 4 comments · Fixed by #262
Labels

Comments

@jiaaro
Copy link
Owner

jiaaro commented Apr 20, 2016

Related to: #129

Python (and by extension, pydub) cannot handle audio with frame rates over 48k. That's a bummer.

We could use ffmpeg to convert the framerate down to 48k in those cases, but users with 96k files on disk are probably not going to be happy with that solution.

I wonder if there is a way to solve this without reimplementing the functionality in audioop. Maybe if we just lie about the framerate to audioop it will work fine?

@jiaaro jiaaro added the todo label Apr 20, 2016
@fnielsen
Copy link

fnielsen commented Jul 4, 2016

I am surprised that this limitation is in the standard wave module.

>>> import wave
>>> wave.open("tmp96k.wav")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/wave.py", line 509, in open
    return Wave_read(f)
  File "/usr/lib/python2.7/wave.py", line 164, in __init__
    self.initfp(f)
  File "/usr/lib/python2.7/wave.py", line 144, in initfp
    self._read_fmt_chunk(chunk)
  File "/usr/lib/python2.7/wave.py", line 273, in _read_fmt_chunk
    raise Error, 'unknown format: %r' % (wFormatTag,)
wave.Error: unknown format: 65534
>>> wave.open("tmp48k.wav")
<wave.Wave_read instance at 0x7fcc0ad647a0>

The reader of scipy has not the problem:

>>> import scipy.io.wavfile
>>> scipy.io.wavfile.read('tmp96k.wav')
(96000, array([[  55, -323],
       [  56, -328],
       [  61, -321],
       ..., 
       [ 198,  174],
       [ 203,  168],
       [ 202,  176]], dtype=int16))

But I suppose you do not want to have dependencies on scipy?

@fnielsen
Copy link

fnielsen commented Jul 4, 2016

Has the problem anything to do with the frame rate? Isn't it due to WAVE_FORMAT_EXTENSIBLE (65534) for the format tag. That is what is being checked in line 269 of wave.py.

$ showriff tmp96k.wav | grep format
format       = 65534
$ showriff tmp48k.wav | grep format
format       = 1

It is unclear to me if monkey patching _read_fmt_chunk is sufficient to get around the issue.

@jiaaro
Copy link
Owner Author

jiaaro commented Jul 5, 2016

@fnielsen Yeah, right now pydub can work on raw audio data (i.e., wave files) without needing to install any dependencies. That's a pretty nice deal and it's the main reason not to require scipy.

I'm not familiar with WAVE_FORMAT_EXTENSIBLE, have you tried the monkey patch?

@maelp
Copy link

maelp commented Nov 29, 2017

I have the same bug, it seems some libraries exist which reimplement the whole .wav parsing, it might be possible to do something similar, or to give an option when loading pydub to monkey-patch the wav reading and writing with those libs or with scipy if the user has it installed already

https://github.com/tuffy/python-audio-tools/blob/master/audiotools/wav.py
https://github.com/melizalab/py-ewave/blob/master/ewave.py

antlarr added a commit to antlarr/pydub that referenced this issue Mar 23, 2018
This allows pydub to open files having more than 48KHz
and/or 32-bit data.

If scipy is not available, falls back to using the standard
wave module as before.

Fixes jiaaro#134
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants