Using the Pyvona TTS Python Wrapper

Posted on
Thu Oct 29, 2015 5:44 am
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Using the Pyvona TTS Python Wrapper

I'm sorry to say that I don't see anything inherently wrong with the code we're trying.

I'm a little out of my element now, but I wonder if this is an issue with backwards compatibility with Python 2.6. I would suggest contacting the developer to see if he believes the version of pyvona you're using should be compatible with Python 2.6.

Sorry that I couldn't be more help.
Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Thu Oct 29, 2015 5:53 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Using the Pyvona TTS Python Wrapper

No worries Dave. Thank you for your help.
I have sent an email to the developer, so we will see what he responds...In the latest release he announsed that it was Python 3 compatible, so I would assume that Python 2 was originally supported.

So I will have to wait a little longer before my WU forecast can be spoken with the perfect Ivona voice :wink:

I will let you know if a solutions turns up :)

Håvard

Posted on
Thu Oct 29, 2015 7:09 am
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Using the Pyvona TTS Python Wrapper

Please report back on what you learn. I'm very curious!


Sent from my iPhone using Tapatalk

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Thu Oct 29, 2015 2:55 pm
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Using the Pyvona TTS Python Wrapper

Well, I have actually made some progress. I manage to install Pyvona on the python2.7 version on a Macbbok Air I have, and there I did not get the error as before. I got an error about a missing module to play sound, but that is expected.

So it might seam like it has to run under Python2.7. The big question then, is if there is any way to pass a variable (The text to speak) to a shell script that launches in Python2.7?

Håvard

Posted on
Thu Oct 29, 2015 3:30 pm
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Using the Pyvona TTS Python Wrapper

I haven't done it myself, but I believe there is. Then you could create the MP3 and play that wherever you like.

Good luck!
Dave


Sent from my iPhone using Tapatalk

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sun Nov 01, 2015 2:14 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Using the Pyvona TTS Python Wrapper

I am trying to run this script from terminal, but I get a syntax error when I try to define the filepath. Anyone that knows how to correctly define the complete file path?

Code: Select all
import pyvona
text_to_speak = "Hello World"
v = pyvona.create_voice('CODE1', 'CODE2')
v.voice_name('Liv')
v.fetch_voice(text_to_speak, «/Brukere/HA/Musikk/Other/filename.mp3»)


Code: Select all
>>> import pyvona
>>> text_to_speak = "Hello World"
>>> v = pyvona.create_voice('CODE1', 'CODE2')
>>> v.voice_name('Liv')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable
>>> v.fetch_voice(text_to_speak, /Users/HA/Musikk/Other/filename.mp3)
  File "<stdin>", line 1
    v.fetch_voice(text_to_speak, /Users/HA/Musikk/Other/filename.mp3)
                                 ^
SyntaxError: invalid syntax

Håvard

Posted on
Sun Nov 01, 2015 5:16 am
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Using the Pyvona TTS Python Wrapper

Hi Håvard -

Have a go with this:

Code: Select all
import pyvona
text_to_speak = "Hello World"
filepath = "/Brukere/HA/Musikk/Other/filename.mp3"
v = pyvona.create_voice('CODE1', 'CODE2')
v.voice_name('Liv')
v.fetch_voice(text_to_speak, filepath)

When sending values to a Python method (in this case, the method is 'v.fetch_voice()' you need to establish the values as "type appropriate" and separate them by commas. Strings go in 'single' or "double" quotes, numbers and booleans go by themselves. Here are some examples of what I mean:

Code: Select all
python_method(foo="bar", number=2, happy=True)
Code: Select all
python_method("bar", 2, True)
Code: Select all
var1 = "bar"
var2 = 2
var3 = True
python_method(var1, var2, var3)

Cheers,
Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Nov 02, 2015 3:20 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Using the Pyvona TTS Python Wrapper

Thank you for your reply Dave, that helps.
The developer is working on a fix, but to isolate the issues I need the wrapper to run under 2.7. Is there a way to do version specific pip installation? Because when I type in sudo pip install pyvona. The files is placed in the 2.6 folder.

Håvard

Posted on
Mon Nov 02, 2015 5:10 am
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Using the Pyvona TTS Python Wrapper

sudo pip2.7 install pyvona

You may have to install pip for 2.7, but I think you should be okay. There are instructions in the forum for installing version-specific stuff.

Dave


Sent from my iPhone using Tapatalk

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Nov 09, 2015 4:20 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Using the Pyvona TTS Python Wrapper

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.

Håvard

Posted on
Mon Nov 09, 2015 5:16 am
nlagaros offline
Posts: 1646
Joined: Dec 20, 2010

Re: Using the Pyvona TTS Python Wrapper

Very cool tool to create static files Haavard! I took a poor mans approach to dealing with passing parameters to the pyvona wrapper. From the main Sonos plugin, I write to a file everything that is needed by pyvona when the action is run. Then, the pyvona script can simply read that file to create the mp3 file. I'm not proud of this, but it works!

Posted on
Mon Nov 09, 2015 7:00 am
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Using the Pyvona TTS Python Wrapper

Works like a champ Håvard!
Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Nov 28, 2015 5:45 am
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Using the Pyvona TTS Python Wrapper

Hi Håvard. I have added a couple of very minor changes to the Pyvona scripts to: (1) create the necessary variables if they don't already exist (including a folder to suit my taste), (2) tweak the results logging, and (3) add an additional setting to allow the voice to be changed by a variable ('IvonaVoice').

pyvona trigger:
Code: Select all
import subprocess

folder_name = "Ivona Variables"
var_list    = ("IvonaVoice", "ttsSTRING", "ttsSTRING_return")

if folder_name not in indigo.variables.folders:
   indigo.variables.folder.create(folder_name)
for var_name in var_list:
    if var_name not in indigo.variables:
        indigo.variable.create(var_name, "", folder = folder_name)

filename    = '/Users/username/Music/Other/dynvoice.mp3'
textToSpeak = indigo.variables["ttsSTRING"].value
voice_name  = indigo.variables["IvonaVoice"].value
returnText  = subprocess.Popen("/usr/bin/python2.7 '/Library/Application Support/Perceptive Automation/Indigo 6/Scripts/voiceToText.py'  '" + filename + "' '" + textToSpeak + "' '" + voice_name + "'", shell = True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()

if returnText[0] == "ok":
    indigo.variable.updateValue("ttsSTRING_return", returnText[0])  # Regular output of python program
else:
    indigo.variable.updateValue("ttsSTRING_return", returnText[1])  # Potential error text

voiceToText.py:
Code: Select all
import sys
import pyvona

filename      = sys.argv[1]
text_to_speak = sys.argv[2]
voice_name    = sys.argv[3]

try:
    v = pyvona.create_voice('accessKey', 'secretKey')
    v.voice_name = voice_name
    v.codec = 'mp3'
    v.fetch_voice(text_to_speak, filename)
    sys.stdout.write("ok")
except:
    sys.stdout.write("error")

Cheers,
Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Who is online

Users browsing this forum: No registered users and 7 guests