Speech_recognition内置麦克风无法识别语音求助(M1 Ventura13.4)
内置麦克风无法触发Speech Recognition的排查方案(M1 Ventura 13.4)
检查系统麦克风权限
打开「系统设置」→「隐私与安全性」→「麦克风」,确认运行代码的Python环境(比如Terminal、PyCharm)已勾选麦克风权限,没开的话勾选后重启程序再测试。指定内置麦克风设备
Speech Recognition默认可能没选中内置麦克风,先列出所有可用设备:import speech_recognition as sr for index, name in enumerate(sr.Microphone.list_microphone_names()): print(f"麦克风设备 {index}: {name}")找到内置麦克风对应的索引,修改代码指定设备:
# 替换成实际查到的内置麦克风索引 with sr.Microphone(device_index=你的索引值) as source: print("Listening...") speak("Listening...") r.pause_threshold = 1 audio = r.listen(source)调高麦克风输入音量
打开「系统设置」→「声音」→「输入」,选中内置麦克风,拖动滑块调高输入音量,说话时确保音量条有明显波动。优化噪音处理
内置麦克风易受环境噪音干扰,要么换安静环境测试,要么给代码加噪音调整:with sr.Microphone() as source: print("Listening...") speak("Listening...") r.adjust_for_ambient_noise(source, duration=0.5) # 提前适配环境噪音 r.pause_threshold = 1 audio = r.listen(source)更新依赖库
终端执行命令更新Speech Recognition和PyAudio:pip install --upgrade speechrecognition pyaudioM1芯片安装PyAudio前需先通过Homebrew装portaudio:
brew install portaudio
内容的提问来源于stack exchange,提问作者Ansh Tyagi
相关产品推荐
相关产品推荐

