yatts - yet another text to speech converter (and translator)
yatts is a text to speech converter (and translator) using Google’s TTS API
yatts allows you to easily take input from stdin or one or more files, translate input into another language, convert input to audio, and write audio to stdout or a file.
mpv is used in this example, but any media player capable of reading from stdin should work just fine.
$ echo "Hello, world." | yatts | mpv -
To translate that to French, we would do
$ echo "Hello, world." | yatts --translate-to='fr' | mpv -
The default Language is English (if not changed in the configuration file). To process another language (German in this example), we would do
$ echo "Hallo Welt." | yatts --lang='de' --translate-to='en' | mpv -
Output from yatts can also be written directly to a file
$ echo "Hello, world." | yatts --fout=hello_world.mp3
yatts can also read input from a file or files
yatts inputfile1.txt inputfile2.txt | mpv - yatts *.txt | mpv -
You can also use yatts directly in your python project.
>>> from yatts.google import TTS >>> tts = TTS(text='Hello, world.', language='en', translate_to='fr') >>> tts.save('hello_world.mp3') >>> >>> from yatts.google import Translator >>> translator = Translator(language_from='en', language_to='la') >>> for tt in translator.translate('Hello, world.'): ... print tt.text ... print tt.original_text ... Salve, universitas. Hello, world.
A config file can be used to avoid having to pass in non-default arguments to yatts. The default location for the config file is ~/.yatts.cfg. If you want to store your file somewhere else, pass in the path to –config.
Here is an example of a config file with all of the currently available options. Lines that start with a “#” are considered comments and are not read by yatts.
language = de translate_to_lang = fr http_proxy = http://user:password@localhost:1080
Values passed in as an argument to yatts will override settings in the config file.
usage: yatts.py [-h] [-f FOUT] [-l LANG] [--tt TRANSLATE_TO_LANG] [--lc] [--http-proxy HTTP_PROXY] [--config CONFIG_FILE] [file [file ...]] yatts - yet another text to speech converter (and translator) using Google's TTS API positional arguments: file input file to be processed. if - or empty, stdin will be read (default: ['-']) optional arguments: -h, --help show this help message and exit -f FOUT, --fout FOUT name of output file. if None, data is written to stdout (default: None) -l LANG, --lang LANG, --language LANG Language code (see --language-codes for a complete list) (default: None) --tt TRANSLATE_TO_LANG, --translate-to TRANSLATE_TO_LANG Language to translate to (default: None) --lc, --language-codes display a full list of language codes (default: False) --http-proxy HTTP_PROXY http proxy to route traffic through. http://[user:password@]proxyhost:port (default: None) --config CONFIG_FILE path to config file (default: ~/.yatts.cfg)
pip install yatts
Languages with TTS Support code language ====== ======== af Afrikaans sq Albanian ar Arabic hy Armenian ca Catalan zh-yue Chinese (Cantonese) zh-cn Chinese (Simplified) zh-tw Chinese (Traditional) hr Croatian cs Czech da Danish nl Dutch en English en-au English (Australia) en-uk English (United Kingdom) en-us English (United States) eo Esperanto fi Finnish fr French de German el Greek ht Haitian Creole hi Hindi hu Hungarian is Icelandic id Indonesian it Italian ja Japanese ko Korean la Latin lv Latvian mk Macedonian no Norwegian pl Polish pt Portuguese pt-br Portuguese (Brazil) ro Romanian ru Russian sr Serbian sk Slovak es Spanish es-es Spanish (Spain) es-us Spanish (United States) sw Swahili sv Swedish ta Tamil th Thai tr Turkish vi Vietnamese cy Welsh Languages with Text Translatation Support code language ====== ======== az Azerbaijani eu Basque be Belarusian bn Bengali bs Bosnian bg Bulgarian ceb Cebuano ny Chichewa et Estonian tl Filipino gl Galician ka Georgian gu Gujarati ha Hausa iw Hebrew hmn Hmong ig Igbo ga Irish jw Javanese kn Kannada kk Kazakh km Khmer lo Lao lt Lithuanian mg Malagasy ms Malay ml Malayalam mt Maltese mi Maori mr Marathi mn Mongolian my Myanmar (Burmese) ne Nepali fa Persian pa Punjabi st Sesotho si Sinhala sl Slovenian so Somali su Sundanese tg Tajik te Telugu uk Ukrainian ur Urdu uz Uzbek yi Yiddish yo Yoruba zu Zulu
- Updated available languages
- Added to tests to make sure all languages can be downloaded
- General cleanup and restructuring
- Added save method to TTS to make saving audio to file easier
- Updated list of supported TTS languages
- Fixed bug where too many args were being passed to TranslatedText
- Added support for translating input into another language
- Moved TTS logic into the google module to allow for easier reuse by others
- Added support for buffering the downloading of audio segments to avoid delays in playback
- Added support for connecting through an HTTP proxy
- Updated available languages
- Added a config file option to store default language
- Minor bug and formatting fixes
- Python 3.4 compatibility
- tox testing support
- Fixed import error of nltk in test_yatts.py
- Added MANIFEST.in so that all files will be included
- First Release