A hassle-free Python library that allows one to use text-to-speech APIs with the same interface
Project description
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 by specifying the voice name and the language code:
tts.set_voice(voice_name='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 create_ssml_root
function that will create the correct boilerplate tags for each engine:
tts = PollyTTS()
tts.synth(tts.create_ssml_root().add('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 service, call the set_credentials()
method.
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()
tts.set_credentials((region, aws_key_id, aws_access_key))
Point to your Oauth 2.0 credentials file path:
from tts_wrapper import GoogleTTS
tts = GoogleTTS()
tts.set_credentials('path/to/creds.json')
Microsoft
Just provide your subscription key, like so:
from tts_wrapper import MicrosoftTTS
tts = MicrosoftTTS()
tts.set_credentials('TOKEN')
If your region is not the default "useast", you can change it like so:
tts = MicrosoftTTS(region='brazilsouth')
Watson
Pass your API key and URL to the initializer:
from tts_wrapper import WatsonTTS
tts = WatsonTTS
tts.set_credentials(('API_KEY', 'API_URL'))
License
Licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for tts_wrapper-0.6.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1dd3bab8b481094746018b3b3a6dfcf6f39fd212db566e31b021158d2ec182c7 |
|
MD5 | 6d49ea6711bde592290bfcf326197344 |
|
BLAKE2b-256 | b270d12f7a09be13d97b150fccdaee1d581f8cc7200549121a6e10fe805afbd0 |