这是代码(我使用Spyder),并且每个具有相同错误的问题都没有帮助
from gtts import gTTS
import speech_recognition as sr
import os
import webbrowser
import smtplib
def talkToMe(audio):
print(audio)
tts = gTTS(text=audio, lang='en')
tts.save('audio.mp3')
os.system('mpg123 audio.mp3')
def myCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print('I am ready for your next command')
r.pause_threshhold = 1
r.adjust_for_ambient_noise(source, duration = 1)
audio = r.listen(source)
try:
command = r.recognize_google(audio)
print('You said: ' + command + '/n')
except sr.UnknownValueError:
assistant(myCommand())
return command
def assistant(command):
if 'open YouTube' in command:
chrome_path = '/usr/bin/google-chrome'
url = 'https://www.youtube.com/'
webbrowser.get(chrome_path).open(url)
if 'what\'s' in command:
talkToMe('Chillin bro')
if 'email' in command:
talkToMe('who is the recipient')
recipient = myCommand()
if 'Diana' in recipient:
talkToMe('What should I say')
content = myCommand()
#init gmail SMTP
mail = smtplib.SMTP('smtp.gmail.com', 587)
#identify to server
mail.ehlo()
#encrypt
mail.starttls()
#login
mail.login('christopherlocascio264@gmail.com', 'my password')
#send message
mail.sendmail('Diana Brown', 'di.527@hotmail.com', content)
#close connenction
mail.close()
talkToMe('Email sent')
talkToMe('I am ready for your command')
while True:
assistant(myCommand())
错误是 “ gTTSError:令牌计算过程中的连接错误:HTTPSConnectionPool(host ='translate.google.com',port = 443):url超过了最大重试次数:/(由SSLError(”引起,由于SSL模块无法连接到HTTPS URL不可用。“))”
任何人都可以帮助