How to record audio from Python on Mac?

S

skip

(I asked this on pythonmac-sig a couple days ago but got no response, so I'm
casting a broader net.)

Can I easily control audio record/playback from Python on my Mac? I know
zip about audio recording or about Apple APIs via Python. Pointers to
simple examples would be much appreciated.

Thanks,

Skip
 
K

Kevin Walzer

(I asked this on pythonmac-sig a couple days ago but got no response, so I'm
casting a broader net.)

Can I easily control audio record/playback from Python on my Mac? I know
zip about audio recording or about Apple APIs via Python. Pointers to
simple examples would be much appreciated.

Thanks,

Skip

You can probably access this functionality via PyObjC--it provides
access to the Cocoa frameworks.
 
K

Kevin Walzer

(I asked this on pythonmac-sig a couple days ago but got no response, so I'm
casting a broader net.)

Can I easily control audio record/playback from Python on my Mac? I know
zip about audio recording or about Apple APIs via Python. Pointers to
simple examples would be much appreciated.

Thanks,

Skip

You can probably access this functionality via PyObjC--it provides
access to the Cocoa frameworks.
 
D

David Thole

You can probably access this functionality via PyObjC--it provides
access to the Cocoa frameworks.

Another option you could use is calling Applescript from the command
line, to open, execute, and handle audio.

An easy example of this is with iTunes actually. Once you get iTunes
down, doing this for other apps should be easy (if they have
applescript bindings):
http://www.macosxhints.com/article.php?story=20011108211802830

You could probably also do what Kevin recommends, but depending on
your needs, this may be a whole lot more simple.

-David Thole
http://www.thedarktrumpet.com
 
H

has

Another option you could use is calling Applescript from the command
line, to open, execute, and handle audio.

For example, using QuickTime Player (which is a buggy, poorly designed
piece of junk, but might suffice if you only need something quick-n-
dirty and aren't too fussy):

#!/usr/bin/python

from time import sleep
from appscript import *

duration = 5 # seconds
outpath = '/Users/foo/test.aiff'

qtp = app('QuickTime Player')
qtp.new_audio_recording()
qtp.documents[1].start()
sleep(duration)
qtp.documents[1].stop()
qtp.documents[1].export(to=mactypes.File(outpath), as_=k.AIFF)

Or, if you're on Leopard and want something a bit more polished, you
could look into using the new QTKit framework via PyObjC. Dunno about
Python-specific examples, but I imagine you could dig up some ObjC
code if you search around a bit and then convert that over to Python
yourself.

HTH

has
 
C

Craig Allen

I want to do this as well, and also some other audio processing via
python. I have not tried yet, but much of my research points to
pyaudio, PortAudio bindings for python, which is supposed to be multi-
platform including Mac OS X, but as I say, I've not tried it yet.

Related to this are some examples that get the audio data into numpy
arrays for signal processing work. cheers, I'm interested to hear how
any of this works out, I'm trying to start a python audio project in
the next couple months.

cheers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top