【问题标题】:Python speech_recognition not detecting audio from microphonePython Speech_recognition 未检测到来自麦克风的音频
【发布时间】:2016-10-02 01:24:03
【问题描述】:

我目前正在研究构建自己的可通过语音命令控制的家庭自动化系统。我了解了 SpeechRecognition 包,并决定这就是我与系统交互的方式。

在阅读了教程和来自 github 的参考页面,并查看了示例脚本后,我想出了以下代码:

import speech_recognition as sr
import pyaudio

r=sr.Recognizer()

    #Microphone(device_index=i, sample_rate=48000)
with sr.Microphone( sample_rate=48000) as source:
    print("Say Something!")
    audio=r.listen(source)

with open("microphone-results.wav", "wb") as f:
    f.write(audio.get_wav_data())

在测试我的代码时,它会运行并显示“说点什么!”但是,无论我对着麦克风说什么,或者代码运行了多长时间都没有发生任何事情,并且没有创建“microphone-results.wav”文件。

我知道我的麦克风可以正常工作,因为我可以使用命令 arecord -D plughw:1,0 test.wav 对其进行测试,并使用 aplay test.wav 播放文件>

我正在使用带有最新更新的 Rasbian 的 Raspberry Pi 3。

【问题讨论】:

  • 您需要重新配置 alsa 以便 pulghw:1,0 成为您的默认设备。或者你需要指向设备索引。否则,它只会记录静音并且永远不会返回。
  • 感谢您解决了问题!如果您想将其发布为问题的答案,我很乐意将其标记为答案

标签: python audio raspberry-pi speech-recognition microphone


【解决方案1】:

我也有同样的问题,但我终于找到了解决方案,这里是只检测一种频率声音的代码行 在 [print("Say something") 之后粘贴

r.pause_threshold=1
r.adjust_for_ambient_noise(source,duration=1) 

then you will get the message whatever you speak after 5 to 10 seconds 

【讨论】:

    猜你喜欢
    • 2021-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-10
    • 1970-01-01
    • 1970-01-01
    • 2015-11-26
    相关资源
    最近更新 更多