python - 麦克风之间的 Python 语音识别变化
问题描述
通过运行以下代码,我得到了所有可用的麦克风:
import speech_recognition as sr
for index, name in enumerate(sr.Microphone.list_microphone_names()):
print(f'{index}, {name}')
这些是我拥有的所有麦克风(和其他东西):
0, Microsoft Sound Mapper - Input
1, Microphone (Realtek(R) Audio)
2, Stereo Mix (Realtek(R) Audio)
3, Microsoft Sound Mapper - Output
4, Speakers (Realtek(R) Audio)
5, Primary Sound Capture Driver
6, Microphone (Realtek(R) Audio)
7, Stereo Mix (Realtek(R) Audio)
8, Primary Sound Driver
9, Speakers (Realtek(R) Audio)
10, Realtek ASIO
11, Speakers (Realtek(R) Audio)
12, Stereo Mix (Realtek(R) Audio)
13, Microphone (Realtek(R) Audio)
14, Speakers 1 (Realtek HD Audio output with SST)
15, Speakers 2 (Realtek HD Audio output with SST)
16, PC Speaker (Realtek HD Audio output with SST)
17, Microphone 1 (Realtek HD Audio Mic input with SST)
18, Microphone 2 (Realtek HD Audio Mic input with SST)
19, Microphone 3 (Realtek HD Audio Mic input with SST)
20, Stereo Mix (Realtek HD Audio Stereo input)
如何选择特定的麦克风进行语音识别,我需要在索引 1 和 2 的麦克风之间交换以进行测试我该怎么做。
参考代码:
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
print("Speak Anything!")
audio = r.listen(source)
r.energy_threshold = 300
r.pause_threshold = 1
try:
text = r.recognize_google(audio)
print("You said : {}".format(text))
except:
print("Sorry could not recognize what you said!")
有没有办法打印当前正在使用的麦克风?
解决方案
利用
mic = Microphone(device_index=1)
完整代码:
import speech_recognition as sr
r = sr.Recognizer()
mic = Microphone(device_index=1)
with mic as source:
print("Speak Anything!")
audio = r.listen(source)
推荐阅读
- c - 为什么不按位计算器程序打印?
- sql - 当前和未来 3 周的总计相同,而不是运行总计
- jquery - 向 Laravel DataTable 控制器函数发送参数
- django - Django - 带有休息框架的数据表ajax错误
- reactjs - 如何保证通过Functional Components传递的props总是被更新,而不是为每一层的props写一个useEflect?
- apache-nifi - NiFi - 合并分页 API 返回的数据
- flutter - 如何在颤动中制作带有视频文件的gif文件
- php - 文件未在 PHP 中上传,但没有可见错误
- r - 创建一个数据框,其中对应的值是 t 间隔
- asp.net - Hangfire 服务器在不活动时休眠