Announcement

Collapse
No announcement yet.

Caching Speech routines using Amazon Polly

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • zwolfpack
    replied
    Originally posted by MattLau View Post
    is there any dif between using pollyc.py vs polly.py?

    I mean in therm a functionality and speed?
    I am not aware of a "polly.py". The archive in post #1 contains PollyC.py (python2) and PollyC.py3 (python3).

    My limited research indicates that the older 'jessie' Raspbian OS build only came with python2. Current 'stretch' build has both python2 and python3. No differences in functionality and any performance differences would be noise-level at best.

    The installer I've put together checks for presence of python3 and uses that if available. It pulls in all packages required, specifically mpg123, python-pip, python3-pip and boto3 (from AWS). (I may need to tweak it for running on jessie, since I'm guessing that python3-pip may not be available there and might throw an error).

    Leave a comment:


  • Guest
    Guest replied
    is there any dif between using pollyc.py vs polly.py?

    I mean in therm a functionality and speed?
    Last edited by ; September 24, 2018, 03:00 PM.

    Leave a comment:


  • zwolfpack
    replied
    Got voice out from Sonos! (uses speak_to_file.sh). Sounds as good as the IVONA voices I have on my production Windows system.

    Sonos expects .wav file which Polly doesn't provide, so used mpg123 to convert. Modified speak_to_file.sh checks if the provided output filename ends with .wav or .WAV and does the conversion if so.

    I wouldn't know Python if it bit me (see what I did there? ), but was able to add the voice into the hash calculation so that a change of voice is properly picked up.

    Also found the issue with PollyC.py3 -- mixup of keyid/key_id and accesskey/access_key in the code. So that's working now. I will post my changes and installer after some more testing.

    Leave a comment:


  • zwolfpack
    replied
    Installed python-pip, and boto3 - PollyC.py working! But PollyC.py3 still can't find boto3.

    BTW, I'm building an installer for this, will post once working.

    Edit: Voice selection (command line) doesn't seem to be working... always getting same voice.

    And another edit! Voice selection does work; however the same phrase with a different voice invokes the cache, so isn't generated.

    Also installed python3-pip and boto3, now PollyC.py3 is stuck at the "if not opts.__dict__[m]: ... KeyError: 'keyid' " problem.
    Last edited by zwolfpack; September 24, 2018, 02:40 AM.

    Leave a comment:


  • zwolfpack
    replied
    Giving this a try this evening, HS3 build 478 on Raspberry Pi. Starting with PollyC.py3. My initial speak.sh
    Code:
    #!/bin/sh
    # speak.sh
    
    exec > speak.log 2>&1
    
    mydir="$(dirname $0)"
    cachedir="$mydir/PollyCache"
    voice=Joanna
    keyid="KEYID"
    accesskey="ACCESSKEY"
    region="us-west-1"
    outfile="$mydir/pollyc.mp3"
    
    $mydir/PollyC.py3 --ofile "$outfile" --text "$1" --cache "$cachedir" --voiceid "$voice" --keyid "$keyid" --accesskey "$accesskey" --region "$region"

    run 1:
    Code:
    File "/opt/HomeSeer/./PollyC.py3", line 87
        print "mandatory option is missing\n"
                                            ^
    SyntaxError: Missing parentheses in call to 'print'
    Added parentheses...
    run 2:
    Code:
    Traceback (most recent call last):
      File "/opt/HomeSeer/./PollyC.py3", line 54, in <module>
        import boto3
    ImportError: No module named 'boto3'
    Get same message using PollyC.py.

    boto3 is an AWS entity?

    still on PollyC.py3, temp. comment out line 54...
    run 3:
    Code:
    Traceback (most recent call last):
      File "/opt/HomeSeer/./PollyC.py3", line 170, in <module>
        main(sys.argv[1:])
      File "/opt/HomeSeer/./PollyC.py3", line 86, in main
        if not opts.__dict__[m]:
    KeyError: 'keyid'
    No idea about this. Jumping to PollyC.py, again with import boto3 commented out,
    run 4:
    Code:
    Usage: PollyC.py [options]
    
    PollyC.py: error: no such option: --voiceid
    Appears long options not working. Got same thing for keyid when I removed voiceid.
    EDIT: not an issue - these options different from PollyC.py3 to PollyC.py

    changed to use short options, PollyC.py still...
    run 5:
    Code:
    Traceback (most recent call last):
      File "/opt/HomeSeer/./PollyC.py", line 170, in <module>
        main(sys.argv[1:])
      File "/opt/HomeSeer/./PollyC.py", line 147, in main
        polly = boto3.client('polly', region_name=a_region, aws_access_key_id=a_aws_
    access_key_id, aws_secret_access_key=a_aws_secret_access_key)
    NameError: global name 'boto3' is not defined
    So need the boto3 import to go further...

    Leave a comment:


  • RandyInLA
    replied
    The python part works great if I use it manually in a DOS window. However, the Windows version of HS doesn't use any script like "speak.sh" that the Linux version does, so I have no way of triggering the python script when using hs.speak(). Every time I use hs.speak(), it goes straight to the speaker.exe app directly. I need a process similar to speak.sh so I can hook in and make the call to the python script and then play the received audio file after.

    Leave a comment:


  • Timon
    replied
    My script should work if you have Python loaded on windows.

    Leave a comment:


  • RandyInLA
    replied
    Hey Timon is there a way to send TTS off to Polly on Windows? I've used the speak.sh method on linux but I have all of my devices and scripting on my Windows version of HS3 Pro. I know the speaker.exe program will play .mp3 files as easily as .wav, I just need to make the call somehow to Polly and then send the resulting .mp3 to speaker.exe. Can't seem to find any sort of hook to intercept the process once I call hs.speak(). Any help would be awesome!

    Leave a comment:


  • Timon
    replied
    There are two scripts, one for python and one for python 2

    Leave a comment:


  • Guest
    Guest replied
    In fact i cheked the python3 script : And this appered in the cli : mandatory option is missing

    It is the line 87 of you script.

    But in python 2 script it works 100 and no problem at all

    Leave a comment:


  • Guest
    Guest replied
    Timon I am running this on a x64 ubuntu server. I think both python 3 and 2 are iinstalled.

    python3 script didnt work. ( it says it was missing information in my credentials or something like that.)

    with the exact same setup the python 2 scriipt is working 100%.

    Is there a difference in running v3 vs v2?

    thanks
    Last edited by ; September 21, 2018, 03:24 PM.

    Leave a comment:


  • RandyInLA
    replied
    Bump: Anyone know how to have the Windows version of hs.speak() go through a speak.sh/bat/vb script just like the Linux version of HS does? Timon ? Thanks!

    Leave a comment:


  • Guest
    Guest replied
    TimonDeLicious BTW thanks To Both of you for this amazing script!
    I cheked the price for next year. And this will be almost free..so I do not see what would stop us of using it!.

    Leave a comment:


  • RandyInLA
    replied
    Thanks for working on this and sharing it!

    I'm trying to get this to work with Homeseer Pro 3.0.0.435 running on Windows 10. I'm 99% there.
    • Tweaked the PollyC.py3 script so it returns an mp3 file
    • Verified that it is caching in the pollycache folder
    • Found a DOS command line app called "cmdmp3" to play the .mp3 file
      • May not need cmdmp3 because I can enter the path to the mp3 file for a speak action and speaker.exe plays it locally or remotely via Hs3Touch on my iPhone
      • Click image for larger version  Name:	Screen Shot 2018-09-08 at 3.19.25 PM.png Views:	1 Size:	28.7 KB ID:	1246369
    • Created a batch file named speak.bat that calls PollyC.py3 and then plays the mp3 file via cmdmp3 (If I call it from inside a DOS window)
    Code:
    Python PollyC.py3 -o "temp.mp3" -t %1
    cmdmp3 "temp.mp3"


    How do I get HS to run speak.bat and pass it the string when I call, hs.speak "Speak this text, please" instead of calling speaker.exe directly? I used to use speak.sh on my Homeseer RPi but can't find any way to get HS to use a speak script on Windows. Ideally, I'd rather the mp3 play via speaker.exe, but if I can at least get the speak.bat file to run and play via cmdmp3, I'll be happy.

    Thanks in advance!
    Last edited by RandyInLA; September 8, 2018, 06:10 PM.

    Leave a comment:


  • Guest
    Guest replied
    I cheked the speaktofile from spud and adapted it :

    #!/bin/sh
    ./PollyC.py -o "$1_t" -t "$2" -c "./pollycache/" -k "xxxxxxxxxxxxxxxxxx" -a "xxxxxxxxxxxxxxxxxxxxxxxx"
    ffmpeg -i "$1_t" -y -ar 44100 "$1"
    rm "$1_t"


    this seems to do the tricks... But i would like to be able to tts with squeezebox plugin .
    pcp any idea?

    Leave a comment:

Working...
X