To make this easier for anyone else to try, here is a summary on how to get Amazon's
Ivona TTS working with the Pyvona python wrapper.
Thanks to Karl and Dave for helping me out with the coding, I am not a Python expert, so I needed a lot of help to get this working.
Since I got this working the Sonos plugin has been updated with support for the
Ivona voice. So the biggest benefit with the code below is that you can make static messages and store them locally. Then the announcement is independent of internet connection and the
Ivona servers. You can then just select the option play file in the Sonos plugin.
1
Install the Pyvona python wrapper. The easiest way is to run "sudo pip2.7 install pyvona " from terminal. This will install Pyvona under Python 2.7. 2.7 is required for it to work. Other info about the wrapper can be found on the developers site:
http://zacharybears.com/pyvona/2
Create a shell script that is called voiceToText.py and place it in the following folder:
- Code: Select all
'/Library/Application Support/Perceptive Automation/Indigo 6/Scripts/voiceToText.py'
This script is doing the talking with the Pyvona code, and should be like this:
- Code: Select all
import sys
import pyvona
text_to_speak = sys.argv[2]
filename = sys.argv[1]
try:
v = pyvona.create_voice('accessKey', 'secretKey')
v.voice_name = 'Liv'
v.codec = 'mp3'
v.fetch_voice(text_to_speak, filename)
sys.stdout.write("ok")
except:
sys.stdout.write("error")
In this script you can put in the voice you want to use. Liv is the Norwegian voive.
You also has to set up av developer account at
ivona.com, and replace your credentials with accessKey and secretKey.
3
Create 2 variables. "ttsSTRING" and " "ttsSTRING_return".
Content in the ttsSTRING will be the spoken text, and ttsSTRING_return is a status of the conversion (returns ok or error).
4
Now you have to create an action group/trigger etc that will fire a python script. This script should look like this:
- Code: Select all
import subprocess
textToSpeak= indigo.variables["ttsSTRING"].value
filename = '/Users/UserAccount/Music/Other/dynvoice.mp3'
returnText= subprocess.Popen("/usr/bin/python2.7 '/Library/Application Support/Perceptive Automation/Indigo 6/Scripts/voiceToText.py' '"+filename+"' '" + textToSpeak +"'", shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()
##returnText[0] = regular output of pathtopythonprogram
##returnText[1] = potential error text .. if it goes wrong , system generated, e.g. if bombs
# this will update variable "ttsSTRING_return" with ok or error
# it must already exist
indigo.variable.updateValue("ttsSTRING_return", returnText[0])
Here you have to set the path to the place you want the mp3 file stored.
That is more or less it. The text that is in the variable ttsSTRING will be stored in the specified folder as mp3 when the Indigo action is executed.