试图在python语音识别中使用桌面输出作为麦克风输入



我试图创建一个识别实时音频的程序,如果该音频中有任何关键短语,该程序会执行x。

import speech_recognition as sr
import pyaudio
for index, name in enumerate(sr.Microphone.list_microphone_names()):
print(f'{index}, {name}')
rc = sr.Recognizer()

while True:
try:
with sr.Microphone(device_index = 0) as source:
rc.adjust_for_ambient_noise(source, duration = .2)
audio = rc.listen(source)
text = rc.recognize_google(audio)
text = text.lower()
print(text)
if badword in text:
print("don't say that!")
except:
continue

当使用除实际麦克风之外的任何设备进行device_index时,程序运行时不会出现错误消息,也不会打印任何内容。我已经尝试了所有列出的输出,我知道是可用的(插入(。

在任务栏中,右键单击声音图标->声音,然后转到录音选项卡。右键单击并激活,显示禁用的设备。在列表中找到";steromexer";右键单击,然后按activate。然后找出它的设备索引,并在设置麦克风时将其用作设备索引。

在我的列表中,当我打印出设备时,有多个立体混合器。我只是试了一下,如果那个不起作用,我只试了另一个。

最新更新