python - 使用 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))
感谢您的回答和帮助
解决方案
你可以试试 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.
推荐阅读
- python - 安装 deauth-detector 的问题
- c# - C# 从另一个微服务调用一个微服务
- c++ - FishEye 镜头校准提供失真矩阵零
- java - Hazelcast:无法进行远程调用:com.hazelcast.map.impl.operation.GetOperation
- sql - SQL如果缺少日期,如何填写时间序列的最后一个值
- javascript - 更新数组 useState 反应钩子(Next.js)
- sql - 计算一个值在 SQL 中的列中存在的次数,如果它不基于两列,则为 0
- javascript - 如何将项目(对象)添加到firestore中的数组
- c++ - find_package(OpenSSL) 无法找到特定的 libssl 版本
- hyperledger-fabric - 如何捕获 Hyperledger Fabric 上的事务生成的事件?