View Single Post
Posts: 33 | Thanked: 37 times | Joined on Jul 2012
#4312
Originally Posted by Leinad View Post
What about this?
http://people.csail.mit.edu/hubert/pyaudio/

MIT License and seems to be pretty easy to record audio:

Code:
""" Record a few seconds of audio and save to a WAVE file. """

import pyaudio
import wave
import sys

chunk = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output.wav"

p = pyaudio.PyAudio()

stream = p.open(format = FORMAT,
                channels = CHANNELS,
                rate = RATE,
                input = True,
                frames_per_buffer = chunk)

print "* recording"
all = []
for i in range(0, RATE / chunk * RECORD_SECONDS):
    data = stream.read(chunk)
    all.append(data)
print "* done recording"

stream.close()
p.terminate()

# write data to WAVE file
data = ''.join(all)
wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(data)
wf.close()
That not a bad start but i doubt you would want to send wave files. The audio should still be converted to mp3 or some other compressed format.