I've been using Amazon Polly to create speech file manually but it's been a pain. And I knew I needed something better.
Thanks to some great initial work by DeLicious and his Polly.py program I'm now releasing a fully caching version called PollyC. It's available for both Python2 and Python3 versions. Use whichever version of Python you normally use. For RaspberryPi users Python2 is loaded by default so it's easiest to go with PollyC.py.
PollyC will cache all speech requests so it only has to go to Amazon's Polly servers when the speech isn't in the local cache.
It will also take advantage of ssml marker language so you can create much better TTS than you can with straight text.
It will work with HS speaker clients and should work with Spuds AirplaySpeak although it's not yet been tested.
It's be releasing this as Open Source with the only requirement being to keep the credits for DeLicious and me in the flies.
Since it's written in Python is should be portable to both windows and linux.
If there are any feature request or comments please leave them below.
Here is my speak.sh file. Since aplay can't play mp3's you need an mp3 player such as mpg123
Here is my speak_to_file.sh file.
A little note about why there are two speak routines. The module speak.sh is used only to speak through the local systems audio channel. The module speak_to_file.sh is used whenever any remote system such as HS speaker clients or Spuds AirplaySpeak is used. If both are used both will be called which would then make 2 requests to Amazon Polly if the cacheing was not in place.
If the cacheing directory is specified but it does not exist it will be created.
PollyC.py3 and PollyC.py should also go in the HomeSeer directory.
Release Status
0.9.0 Thu 21 Jun 06:45:51 PDT 2018
Thanks to some great initial work by DeLicious and his Polly.py program I'm now releasing a fully caching version called PollyC. It's available for both Python2 and Python3 versions. Use whichever version of Python you normally use. For RaspberryPi users Python2 is loaded by default so it's easiest to go with PollyC.py.
PollyC will cache all speech requests so it only has to go to Amazon's Polly servers when the speech isn't in the local cache.
It will also take advantage of ssml marker language so you can create much better TTS than you can with straight text.
It will work with HS speaker clients and should work with Spuds AirplaySpeak although it's not yet been tested.
It's be releasing this as Open Source with the only requirement being to keep the credits for DeLicious and me in the flies.
Since it's written in Python is should be portable to both windows and linux.
If there are any feature request or comments please leave them below.
Code:
--------------------------------- Usage Information --------------------------------- PollyC This modual is used to call the Amazon Polly system to convert an incomming string to a audio file. PollyC must be located in the HomeSeer directory Calling sequence ./scripts/PollyC.py3 -o "outupt_file" -t "the text to speak" -c "./pollycache/" -k "key_ID" -a Key" arguments -o or --ofile Output file name -t or --text Text to speak -v or --voiceid The Polly voice to use (default = Joanna) see https://docs.aws.amazon.com/polly/latest/dg/voicelist.html -f or --format Output format (default - mp3) -c or --cache cache directory, full, relative path or none If no cache is specified then cacheing is disabled -k or --keyid Amazon AWS Access Key ID, mandatory -a or --accesskey Amazon AWS Access Key, mandatory -r or --region Amazon Region (defaults to us-west-1) see https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html PollyC will auto switch to ssml if it detects the string "<speak>" in the text to be converted. For instructions on how to encode ssml speach see https://docs.aws.amazon.com/polly/latest/dg/supported-ssml.html Future additions to PollyC Select voice on call There is no provision in Amazon Polly to set the voice in the text string. However PollyC has the ability to do this: If you specify at the beginning of the text string, either plain text or ssml text, <voice-id="voice name"> then that voice will be used and the tag deleted from the string. This tag MUST be at the beginning of the string. Example: '<voice-id="Matthew">This is a test' '<voice-id="Matthew"><speak>This is a test</speak>' Don't cache this call. Currently PollyC will cache only if a caching directory is specified. This addition will allow each call to be cached or not. Usage: '<no-cache/>This is a test' '<no-cache/><speak>This is a test</speak>' This program is free to use and distribute as long as the credits are not removed. ---------------------------------------------------------------------------------------
Code:
#!/bin/sh # For Python2 change ./PollyC.py3 to ./PollyC.py ./PollyC.py3 -o "temp.mp3" -t "$1" -c "./pollycache/" -k "your key_id" -a "your key" mpg123 -q temp.mp3
Code:
#!/bin/sh # For Python2 change ./PollyC.py3 to ./PollyC.py ./PollyC.py3 -o "$1" -t "$2" -c "./pollycache/" -k "your key_id" -a "your key"
If the cacheing directory is specified but it does not exist it will be created.
PollyC.py3 and PollyC.py should also go in the HomeSeer directory.
Release Status
0.9.0 Thu 21 Jun 06:45:51 PDT 2018
Initial Release
0.9.1 Sat 23 Jun 16:49:59 PDT 2018Updates include creation of cache directory if it does not exist.
Caching will only be preformed if cacheing directory is specified.
Additional error handling.
-h or --help is now included for easier use.
Caching will only be preformed if cacheing directory is specified.
Additional error handling.
-h or --help is now included for easier use.
Comment