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('Hello, world!', 'hello.wav')
Selecting a Voice
You can change the default voice by specifying the voice name and the language code:
tts = PollyTTS(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, like so:
tts.synth('Hello, <break time="3s"/> world!')
You don't need to wrap it with the <speak></speak>
tag as it is automatically used with the required parameters for each TTS service.
Learn which tags are available for each service: Polly, Google, Microsoft, and Watson.
Credentials
You need to setup credentials to access each service.
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:
from tts_wrapper import PollyTTS, AwsCredentials
tts = PollyTTS(creds=AwsCredentials('AWS_KEY_ID', 'AWS_ACCESS_KEY'))
Point to your Oauth 2.0 credentials file path:
from tts_wrapper import GoogleTTS
tts = GoogleTTS(creds='path/to/creds.json')
Microsoft
Just provide your subscription key, like so:
from tts_wrapper import MicrosoftTTS
tts = MicrosoftTTS(creds='TOKEN')
If your region is not "US-East", you must change the endpoint like so:
tts = MicrosoftTTS(creds='TOKEN', fetch_token_url='https://brazilsouth.api.cognitive.microsoft.com/sts/v1.0/issuetoken')
Watson
Pass your API key and URL to the initializer:
from tts_wrapper import WatsonTTS
tts = WatsonTTS(api_key='API_KEY', api_url='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 Distributions
Built Distribution
Hashes for TTS_Wrapper-0.5.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9cbaf253c2c56513ea23cf2610b5b3f817d9477fcaaf994a8ed8526314e8e2f |
|
MD5 | 689c8a78928493e06a4dbd695ec15e64 |
|
BLAKE2b-256 | eed65491cf2e9bd07519e96d84d99c0d268694adc037ead7586cf7b466a85fae |