I'm gonna make a chatting platform in which two people can have voice chat in real-time. (Like skype). The question is that how can I have the sounddevice module always listening and recording? Look at the code below which I've got from an answer to this question: Play and record sound using pyaudio simultaneously
import sounddevice as sd
import numpy as np
import scipy.io.wavfile as wav
fs=44100
duration = 10 # seconds
# (I don't want it for 10 seconds, I want it to record as long as the user doesn't close the session)
myrecording = sd.rec(duration * fs, samplerate=fs, channels=2, dtype='float64')
print "Recording Audio for %s seconds" %(duration)
sd.wait()
print "Audio recording complete"
You can use
sd.rec()
only if the desired duration is known beforehand.If you want to record for a yet unknown time, you'll have to use the
Stream
(orInputStream
) API.For an example, see rec_unlimited.py.