我正在尝试使用 Google 的文本转语音 API 读取 .txt 文件。但是,当我尝试运行它时,它会给出一个我无法理解的错误。因此,您的帮助将不胜感激!
我的 Python 代码:
#Import the required module for text
from gtts import gTTS
#required to play the converted file
import os
#The file you want to convert
with open('/Users/humma/Desktop/python_projects/flowers.txt', 'r') as myFile:
fileRead = myFile.read()
#passing file and language to the engine
myObj = gTTS(text = fileRead, lang = 'en-US', slow = False)
myObj.save('flowers.mp3')
os.system("flowers.mp3")
我得到的错误:
File "c:/Users/humma/Desktop/python_projects/txt-to-speech/txt-to-spch.py", line 12, in <module>
myObj.save('flowers.mp3')
File "C:\ProgramData\Anaconda3\lib\site-packages\gtts\tts.py", line 312, in save
self.write_to_fp(f)
File "C:\ProgramData\Anaconda3\lib\site-packages\gtts\tts.py", line 294, in write_to_fp
raise gTTSError(tts=self, response=r)
gtts.tts.gTTSError: 200 (OK) from TTS API. Probable cause: Unknown
提前感谢您的时间:)