Skip to main content

Module gtts

Module gtts 

Source
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Β§

GttsError

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 default safe="/".
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.split on the combined, case-insensitive pattern.