Expand description
Google Translate TTS, driven exactly as gTTS 2.5 drives it.
Text is pre-processed and, past 100 characters, tokenised with gTTSβs
rules, then each chunk is posted to the batchexecute RPC and the
base64 audio in each answer is concatenated. The rules use regex
lookbehind, which the regex crate does not have, so they are written
out by hand below β in the same order and with the same alternation
priority as the compiled Python pattern.
EnumsΒ§
ConstantsΒ§
- ABBREVIATIONS π
- ALL_
PUNC π symbols.ALL_PUNC.- DEFAULT_
BASE_ URL - MAX_
CHARS π - RPC π
- TONE_
MARKS π - USER_
AGENT π
FunctionsΒ§
- clean_
tokens π - compact_
ascii π json.dumps(obj, separators=(",", ":"))β ASCII-escaped.- decode_
base64 π - is_
other_ πpunc - is_
punc_ πor_ space _ALL_PUNC_OR_SPACE.match(t)β nothing but punctuation and ASCII whitespace.- minimize π
_minimize(the_string, " ", max_size).- package_
rpc π gTTS._package_rpc(text)β the form body.- pp_
abbreviations π pre_processors.abbreviations: remove the period after each listed abbreviation (case-insensitive, no word boundary β gTTSβs own regex), one abbreviation per pass, each pass judged on that passβs input.- pp_
end_ πof_ line pre_processors.end_of_line: drop-\n.- pp_
tone_ πmarks pre_processors.tone_marks: a space after every tone mark.- pp_
word_ πsub pre_processors.word_sub:Esq.βEsquire, case-insensitive.- py_
strip π - Python
str.strip(). - quote π
urllib.parse.quote(s)with the defaultsafe="/".- reserialize_
tight π - Remove the spaces Pythonβs default separators add, outside strings.
- synthesize
gTTS(text=, lang=).save(path)β the concatenated MP3 bytes.- text_
parts gTTS._tokenize(text)β the chunks that become requests.- tokenize π
Tokenizer([tone_marks, period_comma, colon, other_punctuation]).run:re.spliton the combined, case-insensitive pattern.