gTTS: Error if text > 200 char
I am currently running version 2.2.0
and it seems like if the text we are trying to convert is greater than 200 char, the conversion fails with the following message:
Traceback (most recent call last):
File "main.py", line 11, in <module>
myobj.save("audiobook.mp3")
File "/usr/local/lib/python3.8/dist-packages/gtts/tts.py", line 311, in save
self.write_to_fp(f)
File "/usr/local/lib/python3.8/dist-packages/gtts/tts.py", line 293, in write_to_fp
raise gTTSError(tts=self, response=r)
gtts.tts.gTTSError: 200 (OK) from TTS API. Probable cause: Unknown
Sample code to reproduce the problem:
from gtts import gTTS
finalChar = 201
language = 'en'
finalText = ""
for i in range(30):
finalText += "\n0123456789"
print(finalText[:finalChar])
myobj = gTTS(text=finalText[:finalChar], lang=language, slow=False)
myobj.save("audiobook.mp3")
if you change back finalChar
to 200
, the request works and the file is written on disk.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 23 (9 by maintainers)
Since zh is not a language, Chinese does not work at all.
from gtts import gTTS tts = gTTS(“说中文”, lang=“zh-CN”) tts.save(“helloch.mp3”) tts = gTTS(“說中文”, lang=“zh-TW”) tts.save(“helloch.mp3”)
Get “gtts.tts.gTTSError: 200 (OK) from TTS API. Probable cause: Unknown” on both tts.save()
@KelvinKramp, @srugai & @NikithaNimbalkar:
The accents are back, just obtained differently!
I’ve added updated documentation on how to obtain local accents with the combination of the right language code (
lang
) and top-level domain (tld
)! See: https://gtts.readthedocs.io/en/latest/module.html#localized-accents@KelvinKramp and @srugai
Hi there, you’re right, Google has removed upstream almost of the
<Lang>-<geo>
language coded that used to work (and yeah produce different accents).I’ve removed them, see #267, but since they’ve been part of the library for years, I’m adding a compatibility fallback (eg “en-CA” falls back to “en”).
I found the problem in my case, the translation accent was set to “en-ca” representing english canadian. After some debugging (sweat over my body, tears dropping down my head, axillary region all wet etc. 😃) I found it. Maybe you should check what happens if you change the speaking accent to English with “en”, I also removed slow=False. Check it out and let me know if it works out.
Thank you for the quick fix!
What to do if we actually want the accents…