TTS-Wrapper
TTS-Wrapper is a hassle-free Python library that allows one to use text-to-speech APIs with the same interface.
Currently the following services are supported:
- AWS Polly
- Google TTS
- Microsoft TTS
- IBM Watson
Installation
Install using pip.
pip install TTS-Wrapper
Note: for each service you want to use, you have to install the required packages.
Example: to use google
and watson
:
pip install TTS-Wrapper[google, watson]
Usage
Simply instantiate an object from the desired service and call synth()
.
from tts_wrapper import PollyTTS
tts = PollyTTS()
tts.synth('<speak>Hello, world!</speak>', 'hello.wav')
Selecting a Voice
You can change the default voice and lang like this:
PollyTTS(voice='Camila', lang='pt-BR')
Check out the list of available voices for Polly, Google, Microsoft, and Watson.
SSML
You can also use SSML markup to control the output.
tts.synth('<speak>Hello, <break time="3s"/> world!</speak>', 'hello.wav')
As a convenience you can use the wrap_ssml
function that will create the correct boilerplate tags for each engine:
tts.synth(tts.wrap_ssml('Hello, <break time="3s"/> world!'), 'hello.wav')
Learn which tags are available for each service: Polly, Google, Microsoft, and Watson.
Credentials
To setup credentials to access each engine, use the credentials
argument.
Polly
If you don't explicitly define credentials, boto3
will try to find them in your system's credentials file or your environment variables. However, you can specify them with a tuple:
from tts_wrapper import PollyTTS
tts = PollyTTS(credentials=(region, aws_key_id, aws_access_key))
Point to your Oauth 2.0 credentials file path:
from tts_wrapper import GoogleTTS
tts = GoogleTTS(credentials='path/to/creds.json')
Microsoft
Just provide your subscription key, like so:
from tts_wrapper import MicrosoftTTS
tts = MicrosoftTTS(credentials='TOKEN')
If your region is not the default "useast", you can change it like so:
tts = MicrosoftTTS(credentials='TOKEN', region='brazilsouth')
Watson
Pass your API key and URL to the initializer:
from tts_wrapper import WatsonTTS
tts = WatsonTTS(credentials=('API_KEY', 'API_URL'))
License
Licensed under the MIT License.