Package: watson-text-talker
watson-text-talkerAboutI created this interface for a voice-based-bot that I'm running on a Raspberry Pi 3B. I'm using the AIY Voice HAT, but I was very displeased with the robotic-voice that's supplied by Google. After studying a few other voice options I decided on IBM's Watson because of it's high quality cadence and intonation. I added some features for my purposes and decided others may find some benefit in my effort. The package should work in other internet-connected & sound-output-capable devices.Installationpip3 install watson-text-talker --userGetIBM credentialsfor Watson Text-To-Speech, Lite Plan isFREESimple Usefromwatson_text_talkerimport*text_talker=TextTalker(username='your-watson-tts-credentials-username',password='your-watson-tts-credentials-password')text_talker.say("Hello world!")FeaturesVoice file cacheinglowers cloud round-tripskeeps cost downPhrase groupingsegments phrases/sentenceseach segment can have it's own importance factorImportance factorsoptional percentage chance that a phrase will be voicedQuiet leveloptional quiet level factor can be applied to all optional phrasesincreases or decreases the likelihood that an optional phrase will be voicedUses high-quality Waston voicesvery realistic sounding, with appropriate cadence and intonationvoice selection:see here for selection availablefree tier plan: no credit card required, 10,000 characters per month at no costVoice file cacheingThe packagealwayscaches new phrases to a file. The cache directory defaults to./voice_mp3s, but can also be defined in TT_Config. To regulate the filename I slugify the phrase. This has the advantage of making it human readable. The only caveat is the phrase MUST be limited to 255 characters.Phrase groupingPhrase grouping is based on array of tuples.fromwatson_text_talkerimport*text_talker=TextTalker(username='credentials-username',password='credentials-password')importance=TT_Importance()grouping_example=[(importance.SAY_30_PERCENT,"I'm your assistant."),(importance.SAY_50_PERCENT,"How are you?"),(importance.SAY_ALWAYS,"Nice to meet you")]text_talker.say_group(grouping_example)Tuples are made up of the importance & the text phrase.Importance factors# TT_Importance is a class of numeric constantsSAY_ALWAYS=1SAY_90_PERCENT=2SAY_80_PERCENT=3SAY_70_PERCENT=4SAY_60_PERCENT=5SAY_50_PERCENT=6SAY_40_PERCENT=7SAY_30_PERCENT=8SAY_20_PERCENT=9SAY_10_PERCENT=10SAY_NEVER=11For the same as above we could have just as easily said:fromwatson_text_talkerimport*text_talker=TextTalker(username='credentials-username',password='credentials-password')grouping_example=[(8,"I'm your assistant."),(6,"How are you?"),(1,"Nice to meet you")]text_talker.say_group(grouping_example)Quiet levelThe package includes a globally appliedquite levelthat increases or decreases the likelihood that an optional phrase will be voiced.fromwatson_text_talkerimport*text_talker=TextTalker(username='credentials-username',password='credentials-password')importance=TT_Importance()grouping_example=[(importance.SAY_30_PERCENT,"I'm your assistant."),(importance.SAY_ALWAYS,"Nice to meet you")]text_talker.quiet_level=+2text_talker.say_group(grouping_example)In the above example theI'm your assistantphrase will only be said 10% of the time because of the +2 assigned to quiet level. TheNice to meet youis not effected.Configuse the TT_Config class to override configuration defaults# TT_Config's standard defaultsUSERNAME='--watson tts credentials username goes here--'PASSWORD='--watson tts credentials password goes here--'TTS_VOICE='en-US_AllisonVoice'TTS_ACCEPT='audio/mp3'CACHE_DIRECTORY='voice_mp3s'CACHE_DIRECTORY_IS_RELATIVE=TrueVOICE_FILE_EXTENSION='mp3'Use it like so:fromwatson_text_talkerimport*config=TT_Config()config.CREDENTIALS_USERNAME='your watson credentials'config.CREDENTIALS_PASSWORD='your watson password'config.TTS_Voice='en-US_MichaelVoice'congig.CACHE_DIRECTORY='custom_cache'text_talker=TextTalker(config=config)text_talker.say("Hello world!")Attributionspygameis used to process the mp3 voice filespython-slugifyis used to create cache file names