Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read/write raw audio data in realtime (with python)?

I would like to be able to dynamically read and write audio data in realtime. I noticed the python "audioscope" which opens the unix/linux /dev/dsp file and reads raw bytes from it.

However, I am using a Mac OSX 10.5.8, and dual booting linux is quite difficult (I have tried.) I was wondering whether there was a particular 'standard' python module that could read and write audio data (perhaps storing snapshots of the data in numpy arrays.) I plan on having on thread read/store data, and another thread respond by sending new signals.

As of now, I want to use the audio jack in my computer, but at some point, I would like to be able to use usb sound cards in a similar manner. At that point, I would like to be able to control multiple signals (using a usb port expander.)

I have been looking around for a while, and I found a few libraries used for audio processing, but they are usually based around reading and writing files, not dynamic data processing. Perhaps the best library is not an audio library at all. I actually plan to use this to control circuits, but google lead me to audio as the best way to use my computer to do so.

Anyway, I was hoping for some suggestions.

like image 302
Alex Eftimiades Avatar asked Oct 24 '22 10:10

Alex Eftimiades


1 Answers

The Enthought Tool Suite has examples for real time audio processing. They are in the chaco/advanced example folder, spectrum.py, spec_waterfall.py. They use the chaco plotting library and pyaudio to do real-time audio. (Here's another live FFT based on pyaudio and the WCK Graph library.) They're really awesome, and will give you live feedback for what's happening on on your microphone. You can modify this data as it comes in, and do whatever you want to it before displaying it.

What is the end goal of what you'd like to do? You said 'control circuits', what kind of circuits would you like to control? If you post what you'd like to do, there may be a better way that someone can think of.

like image 80
MercuryRising Avatar answered Nov 02 '22 22:11

MercuryRising