Selaa lähdekoodia

[voice] fix google voice exception issue

master
wanggang 1 vuosi sitten
vanhempi
commit
1711a5c064
2 muutettua tiedostoa jossa 7 lisäystä ja 2 poistoa
  1. +1
    -1
      README.md
  2. +6
    -1
      voice/google/google_voice.py

+ 1
- 1
README.md Näytä tiedosto

@@ -73,7 +73,7 @@ pip3 install itchat-uos==1.5.0.dev0
pip3 install --upgrade openai

如果使用google的语音识别,需要安装speech_recognition和依赖的ffmpeg
pip3 install speech_recognition
pip3 install SpeechRecognition
--在MacOS中安装ffmpeg,brew install ffmpeg
--在Windows中安装ffmpeg,下载ffmpeg.exe
--在Linux中安装ffmpeg,apt-get install ffmpeg


+ 6
- 1
voice/google/google_voice.py Näytä tiedosto

@@ -18,4 +18,9 @@ class GoogleVoice(Voice):
subprocess.call('ffmpeg -i ' + voice_file + ' -acodec pcm_s16le -ac 1 -ar 16000 ' + new_file, shell=True)
with speech_recognition.AudioFile(new_file) as source:
audio = self.recognizer.record(source)
return self.recognizer.recognize_google(audio, language='zh-CN')
try:
return self.recognizer.recognize_google(audio, language='zh-CN')
except speech_recognition.UnknownValueError:
return "抱歉,我听不懂。"
except speech_recognition.RequestError as e:
return "抱歉,无法连接到 Google 语音识别服务;{0}".format(e)

Loading…
Peruuta
Tallenna