python - ValueError:找不到令牌种子!https://translate.google.com 有变化吗?
问题描述
我正在制作一个使用 gTTS 和 Google Speech 的助手,但出现了这个错误。语音识别很好,因为它可以毫无错误地识别。我用打印功能进行了测试,但是当我想要文本到语音时,这个错误就来了。...
import speech_recognition as sr
from time import ctime
import time
import playsound
import os
import random
from gtts import gTTS
import webbrowser
r = sr.Recognizer()
def record_audio(ask=False):
with sr.Microphone() as source:
if ask:
watson_speak(ask)
audio = r.listen(source)
voice_data = ''
try:
voice_data = r.recognize_google(audio)
except sr.UnknownValueError:
watson_speak("Sorry, I did not catch that")
except sr.RequestError:
watson_speak("I am offline right now")
return voice_data
def watson_speak(audio_string):
tts = gTTS(text=audio_string, lang='en')
r = random.randint(1, 10000000)
audio_file = 'audio-' + str(r) + '.mp3'
tts.save(audio_file)
playsound.playsound(audio_file)
print(audio_string)
os.remove(audio_file)
def respond(voice_data):
if 'what is your name' in voice_data:
watson_speak("My name is Watson")
if 'what time is it' in voice_data:
watson_speak(ctime())
if 'search' in voice_data:
search = record_audio("What do you want to search for?")
url = "https://duckduckgo.com/?t=ffnt&q=" + search
webbrowser.get().open(url)
watson_speak("Here is what I found for " + search)
if 'find location' in voice_data:
location = record_audio("What is the location?")
url = "https://google.nl/maps/place/" + location + "/&"
webbrowser.get().open(url)
watson_speak("Here is the location of " + location)
if 'exit' in voice_data:
exit()
time.sleep(1)
watson_speak("How can I help you?")
while 1:
voice_data = record_audio()
respond(voice_data)
...不知道我做错了什么。一些指导将不胜感激。它一直要求我不确定的令牌种子。
解决方案
推荐阅读
- python-3.x - 运行雅虎财务模块时出现错误
- ember.js - 如何在 Ember JS 的轮播中显示视频
- c# - 以 ASP.NET Core 3.1 作为后端的 VueJs SPA 使用外部 identityserver4 进行 OAuth/Oidc(两个 cookie 模式)
- deep-learning - ValueError:训练时每个通道预期超过 1 个值,得到输入大小 torch.Size([1, 256])
- node.js - woocommerce-rest-api 发布/放置/删除功能成功,但未添加产品
- terraform - 通过 terraform 逐步扩展 ASG 策略
- http-headers - 如何在 Workload Automation AE 中通过自定义端口配置 HSTS 标头
- java - 在 Ubuntu 20.04 上找不到 JRE
- python - 如何使用 sub 和 regex python 添加新行?
- database - 有人可以解释为什么 assertTrue 在这种情况下不会失败吗?