tgr*_*ray 11
你可以尝试这样的事情:
基于这个问题/答案
# 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
Run Code Online (Sandbox Code Playgroud)
您可能希望使用块大小和阈值,直到获得所需的行为.
编辑:
您可以使用内置的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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26314 次 |
| 最近记录: |