I am trying to write a gTTS python program that converts text to speech and accepts commands that it is told, but when I run the code, I get no response at all, no errors in the terminal and no sound is played, I am not sure what to do and I am not seeing any errors in my program. I am using Sublime Text on MacOS. Please help!!
from gtts import gTTS
import os
import time
import playsound
import speech_recognition as sr
def speak(text):
tts = gTTS(text=text, Lang="en")
filename = "voice.mp3"
tts.save(filename)
playsound.playsound(filename)
def get_audio():
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
said = ""
try:
said = r.recognize_google(audio)
print(said)
except Exception as e:
print("Exception: " + str(e))
return said
text = get_audio()
if "hello" in text:
speak("hello, how are you?")
if "What is your name" in text:
speak("My name is John")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…