आप कुछ इस तरह की कोशिश कर सकते:
पर this question/answer
# this is the threshold that determines whether or not sound is detected
THRESHOLD = 0
#open your audio stream
# wait until the sound data breaks some level threshold
while True:
data = stream.read(chunk)
# check level against threshold, you'll have to write getLevel()
if getLevel(data) > THRESHOLD:
break
# record for however long you want
# close the stream
आप शायद जब तक आप वांछित व्यवहार मिलता है अपने हिस्सा आकार और सीमा मूल्यों के साथ खेलने के लिए चाहता हूँ आधारित।
संपादित करें:
आप उपयोग कर सकते हैं में निर्मित audioop पैकेज रूट मतलब वर्ग एक नमूना है, जो आम तौर पर है कि कैसे आप स्तर मिलेगा की (RMS) खोजने के लिए।
import audioop
import pyaudio
chunk = 1024
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16,
channels=1,
rate=44100,
input=True,
frames_per_buffer=chunk)
data = stream.read(chunk)
rms = audioop.rms(data, 2) #width=2 for format=paInt16