Python: 在语音识别中获取系统音频而不是麦克风
Python: Get system audio in speech recognition instead of microphone
我正在 python 中进行语音识别,但它只能从 Micropohone 获取输入。如何将扬声器的音频作为语音识别库的输入?
代码如下:
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")
我在这里苦苦挣扎了很长时间,非常感谢任何帮助。谢谢!
您可以配置设备索引,如docs:
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))
如果 LINEIN 不能作为单独的输入,您可以在音频属性中将其配置为录音源。
我正在 python 中进行语音识别,但它只能从 Micropohone 获取输入。如何将扬声器的音频作为语音识别库的输入?
代码如下:
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")
我在这里苦苦挣扎了很长时间,非常感谢任何帮助。谢谢!
您可以配置设备索引,如docs:
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))
如果 LINEIN 不能作为单独的输入,您可以在音频属性中将其配置为录音源。