Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python open raw audio data file

Tags:

python

audio

I have these files with the extension ".adc". They are simply raw data files. I can open them with Audacity using File->Import->Raw data with encoding "Signed 16 bit" and sample rate "16000 Khz".

I would like to do the same with python. I think that audioop module is what I need, but I can't seem to find examples on how to use it for something that simple.

The main goal is to open the file and play a certain location in the file, for example from the second 10 to the second 20. Is there something out there for my task ?

Thanx in advance.

like image 982
thelinuxer Avatar asked Jun 05 '09 16:06

thelinuxer


People also ask

How do I get raw data in Python?

You can use the function raw_input() to read from the standard input and then process as you need. Show activity on this post. use this raw_input() it's the basic python input function.

What is Audioop Python?

The audioop module contains some useful operations on sound fragments. It operates on sound fragments consisting of signed integer samples 8, 16, 24 or 32 bits wide, stored in bytes-like objects. All scalar items are integers, unless specified otherwise.

How is raw audio data stored?

A raw audio file is any file containing un-containerized and uncompressed audio. The data is stored as raw pulse-code modulation (PCM) values without any header information (such as sampling rate, bit depth, endian, or number of channels).


1 Answers

For opening the file, you just need file(). For finding a location, you don't need audioop: you just need to convert seconds to bytes and get the required bytes of the file. For instance, if your file is 16 kHz 16bit mono, each second is 32,000 bytes of data. So the 10th second is 320kB into the file. Just seek to the appropriate place in the file and then read the appropriate number of bytes.

And audioop can't help you with the hardest part: namely, playing the audio. The correct way to do this very much depends on your OS.

EDIT: Sorry, I just noticed your username is "thelinuxer". Consider pyAO for playing audio from Python on Linux. You will probably need to change the sample format to play the audio---audioop will help you with this (see ratecv, tomono/tostereo, lin2lin, and bias)

like image 55
Jacob B Avatar answered Sep 23 '22 00:09

Jacob B