首页 > 解决方案 > 使用 Google 进行 Raspberry Pi 语音识别有错误

问题描述

我有两个使用 RP3 和 Google 进行语音识别的项目..第一个是从 google 检索文本并将其发送到移动应用程序..另一个是用语音控制鼠标指针

我有一个旧版本的 Raspbian (Noobs) .. 我将系统刷到 16 MB 存储卡,然后启动 RP3

我对系统进行了更新和升级

sudo apt update
sudo apt upgrade

我连接了我的 USB 麦克风并测试了声音增益

arecord -l
aplay -l
arecord -D plughw:1,0 -d 3 test.wav && aplay test.wav
alsamixer

然后基于网站https://pythonspot.com/speech-recognition-using-google-speech-api/我安装了库:

git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
cd pyaudio
sudo python setup.py install
sudo python3 setup.py install
sudo apt-get install libportaudio-dev
sudo apt-get install python-dev
sudo apt-get install python3-dev
sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
sudo pip3 install SpeechRecognition

然后我尝试了网站中提到的代码..有时我得到错误,有时输出是(Say Something)然后冻结

#!/usr/bin/env python3
# Requires PyAudio and PySpeech.

import speech_recognition as sr

# Record Audio
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Say something!")
    audio = r.listen(source)

# Speech recognition using Google Speech Recognition
try:
    # for testing purposes, we're just using the default API key
    # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
    # instead of `r.recognize_google(audio)`
    print("You said: " + r.recognize_google(audio))
except sr.UnknownValueError:
    print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
    print("Could not request results from Google Speech Recognition service; {0}".format(e))

感谢您的回答和帮助

标签: pythonspeech-recognition

解决方案


你可以试试 Houndify 或 Wit.ai(有时默认识别 google 有问题)?两者都是免费的。至于它冻结可能是因为你的麦克风不工作。或者您可能需要为 r.listen() 设置时间限制。

audio = r.listen(source,timeout=4,phrase_time_limit=4)

如果这不起作用,请尝试:

r.record(source,duration=time)

不同之处(我认为)是第一个使用 VAD。VAD = 语音活动检测,完全符合其听起来的样子。当 r.listen() 中的 VAD 永远不会被触发时,就会出现问题。这导致它永远不会开始录制。如果这些都不起作用,则可能是您的麦克风有问题。您还可以查看模块的能量阈值。像这样:

r.energy_threshold = 300 #mess around with the number and see what works.

推荐阅读