pndurette / gTTS

Python library and CLI tool to interface with Google Translate's text-to-speech API
http://gtts.readthedocs.org/
MIT License
2.26k stars 361 forks source link

2mn latency at the save step #425

Closed FockeOeuf closed 1 year ago

FockeOeuf commented 1 year ago

Prerequisites

Current Behaviour (steps to reproduce)

I'm using gTTS on a Rockpi4b which I just migrated from Debian 10 to 11. As I got rid from Python 2.7 in the process, I started to have big latency in gTTS files generation. So I decided to completely clean Python (uninstall all Python versions and erasing any remaining Python lib from /usr/local/lib), reinstall Python 3.9 and gTTS, but to no avail. When using either the API or gtts-cli, the mp3 file save takes around 1mn30s / 2mn. A simple

sudo gtts-cli "c'est la vie" --lang fr --nocheck --output cestlavie.mp3 --debug

hangs at this point

gtts.tts - DEBUG - text: c'est la vie
gtts.tts - DEBUG - tld: com
gtts.tts - DEBUG - lang: fr
gtts.tts - DEBUG - slow: False
gtts.tts - DEBUG - lang_check: False
gtts.tts - DEBUG - pre_processor_funcs: [<function tone_marks at 0x7f9ba98040>, <function end_of_line at 0x7f9ba98940>, <function abbreviations at 0x7f9ba989d0>, <function word_sub at 0x7f9ba98a60>]
gtts.tts - DEBUG - tokenizer_func: <bound method Tokenizer.run of re.compile('(?<=\\?).|(?<=!).|(?<=?).|(?<=!).|(?<!\\.[a-z])\\. |(?<!\\.[a-z]), |(?<!\\d):|;|…|,|\\(|\\\n|—|¿|‥|،|\\[|。|、|\\]|¡|:|\\)', re.IGNORECASE) from: [<function tone_marks at 0x7f9ba98c10>, <function period_comma at 0x7f9ba98ca0>, <function colon at 0x7f9ba98d30>, <function other_punctuation at 0x7f9ba98dc0>]>
gtts.tts - DEBUG - pre-processing: <function tone_marks at 0x7f9ba98040>
gtts.tts - DEBUG - pre-processing: <function end_of_line at 0x7f9ba98940>
gtts.tts - DEBUG - pre-processing: <function abbreviations at 0x7f9ba989d0>
gtts.tts - DEBUG - pre-processing: <function word_sub at 0x7f9ba98a60>
gtts.tts - DEBUG - text_parts: ["c'est la vie"]
gtts.tts - DEBUG - text_parts: 1
gtts.tts - DEBUG - data-0: f.req=%5B%5B%5B%22jQ1olc%22%2C%22%5B%5C%22c%27est%20la%20vie%5C%22%2C%5C%22fr%5C%22%2Cnull%2C%5C%22null%5C%22%5D%22%2Cnull%2C%22generic%22%5D%5D%5D&

After 2mn, success the file is generated as intended.

gtts.tts - DEBUG - headers-0: {'Referer': 'http://translate.google.com/', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36', 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8', 'Content-Length': '148'}
gtts.tts - DEBUG - url-0: https://translate.google.com/_/TranslateWebserverUi/data/batchexecute
gtts.tts - DEBUG - status-0: 200
gtts.tts - DEBUG - part-0 written to <_io.BufferedWriter name='cestlavie.mp3'>
gtts.tts - DEBUG - part-0 created

Expected Behaviour

On my Windows PC on the same network, using the same DNS, gTTS works fine without any latency during the save step.

Context

I detected the issue as I'm running a Jeedom plugin using gTTS. Any TTS command has a 2mn latency now, and I pinpointed the issue at gTTS save step.

Environment

FockeOeuf commented 1 year ago

There may be a lib version issue. I can't seem to find out which dependencies versions need to be installed and how to have a stable gtts install. I've started fresh after uninstalling and reinstalling python3 entirely, but same behavior as previously.

At some point it worked as intended, but I can't pinpoint what is wrong...

FockeOeuf commented 1 year ago

Ok this was a network issue, uninstalled ifupdown for network-manager and it is ok now...

pndurette commented 1 year ago

Ah, glad you figured it out!