簡體   English   中英

使用 Google 進行 Raspberry Pi 語音識別有錯誤

[英]Raspberry Pi speech recognition with Google has errors

我有兩個使用 RP3 和 Google 進行語音識別的項目。第一個是從 google 檢索文本並將其發送到移動應用程序。另一個是用語音控制鼠標指針

我有一個舊版本的 Raspbian (Noobs).. 我將系統刷到 16 MB memory 卡然后啟動 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

然后基於 web 站點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

然后我嘗試了網站中提到的代碼..有時我得到錯誤,有時 output 是(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.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM