当前位置: 首页 > 工具软件 > gTTS > 使用案例 >

python 文本转语音播放失败_python - 文本语音Raspberry pi错误-gtts.tts.gTTSError:令牌计算期间的连接错误 - 堆栈内存溢出...

钦英发
2023-12-01

我正在编写代码,将Raspberry Pi 3上的“ questions.txt”文件中的某些英语行通过google text-to-speech转换为语音。我正在使用Python的gTTS库执行上述操作。 但是我的代码返回以下错误

Starting Conversion

Traceback (most recent call last):

File "tts.py", line 21, in

getAudioQues()

File "tts.py", line 16, in getAudioQues

myobj.save("../data/quesAudio/"+str(quesNo)+".mp3")

File "/home/pi/.local/lib/python2.7/site-packages/gtts/tts.py", line 247, in save

self.write_to_fp(f)

File "/home/pi/.local/lib/python2.7/site-packages/gtts/tts.py", line 192, in write_to_fp

str(e))

gtts.tts.gTTSError: Connection error during token calculation: HTTPSConnectionPool(host='translate.google.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

我的代码如下:

from gtts import gTTS

import os

language = 'en'

def getAudioQues():

quesNo=1

f=open("../data/questions.txt","r")

f1=f.readlines()

print "Starting Conversion"

os.mkdir("../data/quesAudio")

for x in f1:

mytext = x

myobj = gTTS(text=mytext, lang=language, slow=False)

myobj.save("../data/quesAudio/"+str(quesNo)+".mp3")

quesNo+=1

f.close()

getAudioQues()

 类似资料: