#!/usr/bin/env python """ Simple script which demonstrates the capabilities and usage of fastaudio. Notes: The methods of the fastaudio stream object are strictly non-blocking, meaning that read() returns all the data received from audio input since the last read() (up to the limits specified in __init__). Also, write() simply enqueues data for sending. Also, instead of working with lists of frame tuples, fastaudio works strictly with strings, for reading and writing. To learn more about the available methods and functions, look in the fastaudio.pyx source file - the syntax is very python-like and readable, plus I've tried to make the doc strings helpful """ import time import fastaudio as f print "getting device info" print f.getInfo() print "what's the closest to 7500 frames/sec?" print f.closestRate(7500) # create fastaudio stream, # constructor will automatically get closest to 7500 f/s #s = f.stream(7500, # sample rate # 2, # number of channels # 'int16', # sample format, choose from 'int8', 'int16', 'int32'. # 4096, # frames per buffer # 16) # maximum number of input buffers # we can just go with defaults for now s = f.stream(11025) # warn the user print "Will start recording in 2 seconds..." time.sleep(2) # we *do* have to manually open/close, start/stop the stream - not hard s.open() s.start() print "Now recording 3 seconds of data" # allow 3 seconds worth of data to come in time.sleep(3) # now read all the available data from the input buffer (which should now # have 3 seconds worth of audio) x = s.read() # note - if you want to flush the input buffer, you can simply just call read(). # now, write the data back s.write(x) # wait for the data to play out time.sleep(4) # add 1 for good luck # note - you can freely get on with other processing if you like. The stream play # code in portaudio works in a background thread. # stop the stream s.stop() # and close it s.close()