It seems like there is a limit on how much you can use Google Translate through gTTS in a single day, since Google doesn't want you to hammer on their servers too much. What could be some potential ideas about how I could go about converting a lot of text (a few hundred megabytes) to speech with the Google Translate voices without waiting years (literally)? Just looking for someone to point me in the right direction. Thanks!
Google Translate/gTTS Limit
1.2k Views Asked by Robert At
2
There are 2 best solutions below
0

here is a workaround:
from gtts import gTTS, gTTSError
for attempt in range(max_retries):
try:
tts = gTTS(text, lang=language)
tts.save(audio_file_path)
return audio_file_path
except gTTSError as e:
if "429 (Too Many Requests)" in str(e):
print(f"Rate limit hit, retrying in {retry_delay} seconds...")
time.sleep(retry_delay)
retry_delay *= 2 # Exponential backoff
else:
raise
except Exception as e:
raise # Re-raise any other exceptions
raise RuntimeError("Failed to convert text to speech after retries")
ref: https://github.com/frknltrk/gTTS/blob/19e3ad555f0fc0da6ae8ff70ff72f9e801ba0da9/main.py#L33
Use the Google Cloud TTS Service API instead.
There is a python interface, and a free tier is available.
https://cloud.google.com/text-to-speech/docs/create-audio#text-to-speech-text-python
https://cloud.google.com/text-to-speech/pricing
Alternatively, you can try using another library (like pyttsx3). But the quality is not as good.
Amazon Polly also has a similar service, through AWS, which a similar free tier, and a python interface.
https://docs.aws.amazon.com/polly/latest/dg/get-started-what-next.html
https://aws.amazon.com/polly/pricing/
I have used Polly in the past, but my free tier has expired (only good for 1 year). It takes a bit of work to set up, but once set up, it is fast and easy to use.
Good luck. (Though, by now, you might already have found a solution...)