我试图创建一个虚拟助理,但我无法让gTTS工作()工作,而且我似乎无法修复它
import os
import time
import playsound
import speech_recognition as sr
from gtts import gTTS
def speak(text):
tts = gTTS(text = text, lang="en")
filename = "voice.mp3"
tts.save(filename)
playsound.playsound(filename)
speak("hello i am bob"),这是我得到的错误
File "/Users/danielcaminero/Library/Mobile Documents/com~apple~CloudDocs/SJ-000/pyda/script.py", line 13, in <module>
speak("hello i am bob")
File "/Users/danielcaminero/Library/Mobile Documents/com~apple~CloudDocs/SJ-000/pyda/script.py", line 10, in speak
tts.save(filename)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gtts/tts.py", line 295, in save
self.write_to_fp(f)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gtts/tts.py", line 251, in write_to_fp
prepared_requests = self._prepare_requests()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gtts/tts.py", line 194, in _prepare_requests
part_tk = self.token.calculate_token(part)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gtts_token/gtts_token.py", line 28, in calculate_token
seed = self._get_token_key()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gtts_token/gtts_token.py", line 58, in _get_token_key
raise ValueError(
ValueError: Unable to find token seed! Did https://translate.google.com change?发布于 2020-11-10 10:33:11
我也有同样的错误,直到我升级了gTTS-token。
pip install gTTS-token --upgrade让我也告诉你,我有一台Windows机器,我在其中运行Linux终端。在这种情况下,我无法使它发挥作用(不过,如果这是您的情况,请尝试一下)。希望它能成功!
发布于 2021-02-08 14:56:15
发布于 2022-11-08 13:13:25
我在Windows上也有同样的问题。我刚刚卸载了模块gtts并重新安装了它(现在有了它的最后一个版本)
https://stackoverflow.com/questions/64760579
复制相似问题