在Python上使用gtts时的RecursionError

时间:2017-11-30 01:20:36

标签: python text-to-speech google-text-to-speech

我正在使用gtts(谷歌文本到语音)包将几个中文文本转换为语音。但是,我得到了很多RecursionError:超出了最大递归深度。

代码很简单:

from gtts import gTTS

tts = gTTS(text=sentence, lang='zh')
tts.save(r"E:\Project\audioData\zh%d.wav"%(1))

完整错误消息显示为照片 Error Messeage

Traceback (most recent call last):
File "E:\Independent Study\Project\test.py", line 3, in <module>
tts = gTTS(text=sentence, lang='zh')
File "C:\Users\Yuchen Liu\AppData\Local\Programs\Python\Python36\lib\site-
packages\gtts\tts.py", line 97, in __init__
text_parts = self._tokenize(text, self.MAX_CHARS)
File "C:\Users\Yuchen Liu\AppData\Local\Programs\Python\Python36\lib\site-
packages\gtts\tts.py", line 169, in _tokenize
min_parts += self._minimize(p, " ", max_size)
File "C:\Users\Yuchen Liu\AppData\Local\Programs\Python\Python36\lib\site-
packages\gtts\tts.py", line 178, in _minimize
return [thestring[:idx]] + self._minimize(thestring[idx:], delim, max_size)
File "C:\Users\Yuchen Liu\AppData\Local\Programs\Python\Python36\lib\site-
packages\gtts\tts.py", line 178, in _minimize
return [thestring[:idx]] + self._minimize(thestring[idx:], delim, max_size)
File "C:\Users\Yuchen Liu\AppData\Local\Programs\Python\Python36\lib\site-
packages\gtts\tts.py", line 178, in _minimize
return [thestring[:idx]] + self._minimize(thestring[idx:], delim, max_size)
[Previous line repeated 983 more times]
File "C:\Users\Yuchen Liu\AppData\Local\Programs\Python\Python36\lib\site-
packages\gtts\tts.py", line 176, in _minimize
if self._len(thestring) > max_size:
File "C:\Users\Yuchen Liu\AppData\Local\Programs\Python\Python36\lib\site-
packages\gtts\tts.py", line 154, in _len
return len(unicode(text))
RecursionError: maximum recursion depth exceeded

请帮助!

1 个答案:

答案 0 :(得分:0)

这可能有帮助:

from gtts import gTTS

tts = gTTS("sentence",lan = "zh")

tts.save("sentence.mp3")