我想为使用 gTTS 的语音助手创建 python 代码。我运行了代码,但它没有像它显示的那样工作,
回溯(最近一次调用最后一次):
文件“/Users/niallquadros/Desktop/voiceassistant.py”,第 1 行,来自
<module>gTTS 导入 gTTSModuleNotFoundError:没有名为“gTTS”的模块
相反,它应该给我结果,并充当语音助手。
这是我在 MacBook Air 2019 上使用 python (3.7.4) 编写的代码
from gTTS import gTTS
import speech_recognition as sr
import os
import webbrowser
import satplib
def talkToMe(audio):
print (audio)
tts = gTTs(text=audio, lang='en')
tts.save('audio.mp3')
os.system('mpg123 audio.mp3')
#Listen for commands
def myCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print('I am ready for your next command')
r.pause_threshold = 1
r.adjust_for_ambient_noise(source, duration = 1)
audio = r.listen(source)
try:
command = …Run Code Online (Sandbox Code Playgroud)