A simple text-to-speech client using azure TTS API(trial). 😆
TL;DR: This program uses trial auth token of Azure Cognitive Services to do speech synthesis for you.
You can try the Azure TTS API online: https://azure.microsoft.com/en-us/services/cognitive-services/text-to-speech
$ pip install --upgrade aspeak
usage: aspeak [-h] [-V | -L | [-t [TEXT] | -s [SSML]]] [-p PITCH] [-r RATE] [-S STYLE] [-f FILE] [-e ENCODING] [-o OUTPUT_PATH] [--mp3] [-l LOCALE] [-v VOICE]
This program uses trial auth token of Azure Cognitive Services to do speech synthesis for you
options:
-h, --help show this help message and exit
-V, --version show program's version number and exit
-L, --list-voices list available voices, you can combine this argument with -v and -l
-t [TEXT], --text [TEXT]
Text to speak. Left blank when reading from file/stdin
-s [SSML], --ssml [SSML]
SSML to speak. Left blank when reading from file/stdin
-f FILE, --file FILE Text/SSML file to speak, default to `-`(stdin)
-e ENCODING, --encoding ENCODING
Text/SSML file encoding, default to "utf-8"(Not for stdin!)
-o OUTPUT_PATH, --output OUTPUT_PATH
Output file path, wav format by default
--mp3 Use mp3 format instead of wav. (Only works when outputting to a file)
-l LOCALE, --locale LOCALE
Locale to use, default to en-US
-v VOICE, --voice VOICE
Voice to use
Options for --text:
-p PITCH, --pitch PITCH
Set pitch, default to 0
-r RATE, --rate RATE Set speech rate, default to 0.04
-S STYLE, --style STYLE
Set speech style, default to "general"
- If you don't specify
-o
, we will use your default speaker. - If you don't specify
-t
or-s
, we will assume-t
is provided. - You must specify voice if you want to use
-p
or-r
option.
$ aspeak -t "Hello, world!"
$ aspeak -L
$ aspeak -L -l zh-CN
$ aspeak -L -v en-US-SaraNeural
Output
Microsoft Server Speech Text to Speech Voice (en-US, SaraNeural)
Display Name: Sara
Local Name: Sara @ en-US
Locale: English (United States)
Gender: Female
ID: en-US-SaraNeural
Styles: ['cheerful', 'angry', 'sad']
Voice Type: Neural
Status: GA
$ aspeak -t "Hello, world!" -o output.wav
If you prefer mp3, you can use --mp3
option.
$ aspeak -t "Hello, world!" -o output.mp3 --mp3
$ cat input.txt | aspeak
or
$ aspeak -f input.txt
with custom encoding:
$ aspeak -f input.txt -e gbk
$ aspeak
or (more verbose)
$ aspeak -f -
maybe you prefer:
$ aspeak -l zh-CN << EOF
我能吞下玻璃而不伤身体。
EOF
$ aspeak -t "你好,世界!" -l zh-CN
$ aspeak -t "你好,世界!" -v zh-CN-YunjianNeural
$ aspeak -t "你好,世界!" -v zh-CN-XiaoxiaoNeural -p 1.5 -r 0.5 -S sad
- I found Azure TTS can synthesize nearly authentic human voice, which is very interesting 😆.
- I wrote this program to learn Azure Cognitive Services.
- And I use this program daily, because
espeak
andfestival
outputs terrible 😨 audio.- But I respect 🙌 their maintainers' work, both are good open source software and they can be used off-line.
- I hope you like it ❤️.