Write wav file python


















Maybe some of you out there might find this useful. IMO this is the most comprehensive library for reading audio files in Python right now, although not without its faults. Reading a wav file:. The example is about reading a wav file, but PyDub can handle a lot of various formats out of the box.

The caveat is that it's based on both native Python wav support and ffmpeg, so you have to have ffmpeg installed and a lot of the pydub capabilities rely on the ffmpeg version. Usually if ffmpeg can do it, so can pydub which is quite powerful. Here's a Python 3 solution using the built in wave module [1], that works for n channels, and 8,16, Note, I've tried to make it readable rather than fast.

I found reading all the data at once was almost 2x faster. Although python-soundfile is roughly 2 orders of magnitude faster hard to approach this speed with pure CPython. How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group.

Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 12 years ago. Active 1 year ago. Viewed k times. BrechtDeMan 6, 3 3 gold badges 22 22 silver badges 25 25 bronze badges.

Roman Roman k gold badges silver badges bronze badges. Add a comment. Active Oldest Votes. Boris 9, 7 7 gold badges 72 72 silver badges 74 74 bronze badges. Alex Martelli Alex Martelli k gold badges silver badges bronze badges. You can combine this with command line conversion tools to open other formats. It seriously lacks the number of channels though.

How are you supposed to work with audio without knowing the number of channels? I think it's using struct. Does this library work? I run into a number of problems: scipy. Show 4 more comments. To read more than one frame e. Another option is to use the SciPy and NumPy libraries. In the below example, we produce a stereo wave file where the left channel has a low-frequency tone while the right channel has a higher-frequency tone.

How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?

Collectives on Stack Overflow. Learn more. How to write stereo wav files in Python? Ask Question. Asked 11 years, 4 months ago. Active 1 year, 1 month ago. Viewed 21k times. Jonathan Livni Jonathan Livni 90k 99 99 gold badges silver badges bronze badges.

Add a comment. Active Oldest Votes. Returns number of audio channels 1 for mono, 2 for stereo. Returns compression type 'NONE' is the only supported type. Human-readable version of getcomptype. Usually 'not compressed' parallels 'NONE'. Reads and returns at most n frames of audio, as a bytes object.

For seekable output streams, the wave header will automatically be updated to reflect the number of frames actually written. For unseekable streams, the nframes value must be accurate when the first frame data is written. An accurate nframes value can be achieved either by calling setnframes or setparams with the number of frames that will be written before close is called and then using writeframesraw to write the frame data, or by calling writeframes with all of the frame data to be written.

In the latter case writeframes will calculate the number of frames in the data and set nframes accordingly before writing the frame data. Make sure nframes is correct, and close the file if it was opened by wave. This method is called upon object collection. It will raise an exception if the output stream is not seekable and nframes does not match the number of frames actually written.

Changed in version 3.



0コメント

  • 1000 / 1000