How to record audio from Python on Mac?

has has.temp3 at virgin.net
Tue Sep 9 17:44:58 EDT 2008


On 9 Sep, 19:55, David Thole <dth... at gmail.com> wrote:

> 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
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net




More information about the Python-list mailing list