在Linux系统上,如何在Pyaudio中记录可变长度片段,直到我停止在嘈杂的环境中使用流说话?
我正在尝试创建一个虚拟代理。我已经使用了以前记录可变长度命令的代码 - 但在更安静的环境中。现在,由于数据变量永远不会空,因此它不会超出WARE循环。
def listen():
WAVE_OUTPUT_FILENAME = "temp.wav"
CHUNK = 1024
audio = pyaudio.PyAudio()
stream = audio.open(format=pyaudio.paInt16, channels=1,rate=16000, input=Trueframes_per_buffer=1024)
frames = []
try:
while True:
data = stream.read(4000)
frames.append(data)
if len(data) == 0:
break
except KeyboardInterrupt:
pass
I'm trying to create a virtual agent. I've used code that records variable length commands before -- but in a quieter environment. Now it doesn't get beyond the while loop as the data variable is never empty.
def listen():
WAVE_OUTPUT_FILENAME = "temp.wav"
CHUNK = 1024
audio = pyaudio.PyAudio()
stream = audio.open(format=pyaudio.paInt16, channels=1,rate=16000, input=Trueframes_per_buffer=1024)
frames = []
try:
while True:
data = stream.read(4000)
frames.append(data)
if len(data) == 0:
break
except KeyboardInterrupt:
pass
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Len(数据)始终为4000;因此,这个想法只是错误的。对不起。我该如何解决这个问题?
len(data) is always 4000; so this idea is just wrongheaded. Sorry. How do I close this question?