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)
...何が間違っていたのかわかりません。いくつかのガイダンスをいただければ幸いです。よくわからないトークンシードを要求し続けます。