Python:在语音识别中获取系统音频,而不是麦克风
我正在用python进行语音识别,但它只从Microphone获取输入。如何将来自扬声器的音频作为语音识别库的输入 代码如下所示:Python:在语音识别中获取系统音频,而不是麦克风,python,audio,speech-recognition,speaker,Python,Audio,Speech Recognition,Speaker,我正在用python进行语音识别,但它只从Microphone获取输入。如何将来自扬声器的音频作为语音识别库的输入 代码如下所示: import speech_recognition as sr with sr.Microphone() as source: # using microphone here, would like to use speaker instead print("Talk Something...") audio=r.listen(source)
import speech_recognition as sr
with sr.Microphone() as source: # using microphone here, would like to use speaker instead
print("Talk Something...")
audio=r.listen(source)
print("Time Over...")
import time
try:
t1=time.time()
print("Text: "+r.recognize_google(audio)) # prints after converting speech to text
t2=time.time()
print("T2-T1: ", t2-t1)
except:
print("Didn't understand the audio")
我在这里奋斗了这么长时间,任何帮助都将不胜感激。谢谢 您可以按照以下方式配置设备索引:
如果LINEIN不能作为单独的输入,您可以在“音频属性”中将其配置为录音源。它提供了以下输出:为
麦克风找到了名为“内置麦克风”的麦克风(设备索引=0)
为麦克风找到了名为“内置输出”的麦克风(设备索引=1)
为麦克风(设备索引=2)找到名为“AirBeamTV Audio”的麦克风
如何使用索引获取扬声器而不是微型麦克风作为语音识别的输入?使用sr.micros(设备索引=1)作为源
在使用“设备索引=1”时,我得到“OSError:[Errno-9998]无效的通道数”。您能告诉我如何解决这个错误吗?看起来设备1不支持录制。你可以改为在alsa配置中更改音频源,实际上不可能从库中切换。你能编辑答案并告诉我,怎么做吗?
import speech_recognition as sr
for index, name in enumerate(sr.Microphone.list_microphone_names()):
print("Microphone with name \"{1}\" found for `Microphone(device_index={0})`".format(index, name))