Announcement

Collapse
No announcement yet.

Alexa TTS that works better (IMHO) than the solution for Home Assistant.

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

  • Alexa TTS that works better (IMHO) than the solution for Home Assistant.

    OK, so there's many ways to skin a cat and I personally find this better than the solution for HomeAssistant and better than the ChromeCast Plugin ( it is for me, not here to start a debate). While I got HomeAssistant kind of, sort of working semi well I had issues with cookies and the interface (or lack there of) was limiting.
    Chromecast works beautifully on a Google Home, but I'm stuck in the Amazon echo-system and using it for announcements having both in a box kind of works but the sound quality is poor and there's a long delay, so...

    This solution requires Node-Red
    Maybe you can port it, but then again, a PI Zero W is $5 so it's hardly worth the hassle even if you'd only run this application.
    I find myself using it as a DB Writer between Homeseer and InfluxDB, I use it to pull weather from DarkSky, I have one as a 1W interface, etc. etc. so there's a lot of usages for it.

    The Package is this:
    https://flows.nodered.org/node/node-...-alexa-remote2

    The nice thing about this package (which uses this package https://github.com/Apollon77/alexa-remote for Alexa functions) is that all the functions are easily accessed.
    you can set up an event trigger that reports all events (i.e. if you tell Alexa to do something it will trigger an event that contains all the information about what just happened so you can capture it and build actions based on said events).

    It has a built in proxy-login and generates it's own cookie if you use it, or you can enter the cookie manually once captured (easier that way if you do a lot of debugging since you have to enter your credentials every time you deploy your NodeRed settings).

    You can issue different speak/TTS commands, "Speak" as the name applies had Alexa saying the text you send, "Announce" does the same thing but adds the dingdong notification (and only to the device you specify). If you don't specify a device, it will speak/announce on all devices automatically (no need for groups).
    You can utilize Amazons SSML (https://developer.amazon.com/docs/cu...reference.html) so that you can change the way Alexa speaks (faster, slower, different pitch, volume, etc.) What I find "coolest" is that you can have her Whisper.
    You can issue speak with volume commands so that it sets the device to a certain volume, says whatever it was you wanted it to say and then restores the previous volume,
    this does not work for automatic "ALL" but it's useful for individual devices.

    There's a home automation branch as well that I haven't had a chance to dig into, but the TTS portion alone is great.

    I have a flow set up that reads MQTT commands from HomeSeer, so I can issue these... as an example...

    Alexa/Announce/ALL=Good Morning Announces to All Devices
    Alexa/Announce/Office=Good Morning Announces in Office
    Alexa/Speak/Office=Good Morning Speaks in Office
    Alexa/Whisper/Office=Good Morning Whispers in Office
    Alexa/Announce/Office/100=Good Morning Announces in Office w. volume set to 100

    Here's the flow, kind of messy, but it works

    Code:
    [{"id":"954df900.e1a6f8","type":"mqtt in","z":"42f0fc95.1cc554","name":"","topic":"Alexa/#","qos":"2","datatype":"auto","broker":"caca23a1.454e3","x":90,"y":120,"wires":[["6a139895.75c2c8"]]},{"id":"6a139895.75c2c8","type":"function","z":"42f0fc95.1cc554","name":"Parse Message","func":"        var tokens = msg.topic.split(\"/\");\n        msg.action = tokens[1];\n       \n\n       \n       \n       if (tokens[2] == \"ALL\") {\n          msg.device = null;\n        } else {\n          msg.device = tokens[2];\n        }\n       \n       if (tokens.length==4) {\n        msg.volume = tokens[3];\n        } else {\n        msg.volume = null\n        } \n       \n\n        msg.texttospeak = msg.payload;\n\n        return msg;","outputs":1,"noerr":0,"x":260,"y":120,"wires":[["603d87ad.199e08","505588d9.c80308"]]},{"id":"a80c8b99.d286f8","type":"debug","z":"42f0fc95.1cc554","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":530,"y":40,"wires":[]},{"id":"603d87ad.199e08","type":"debug","z":"42f0fc95.1cc554","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":250,"y":180,"wires":[]},{"id":"e118d577.349ee8","type":"alexa-remote-routine","z":"42f0fc95.1cc554","name":"Announce","account":"A-Account","routineNode":{"type":"speak","payload":{"type":"announcement","text":{"type":"msg","value":"texttospeak"},"devices":{"type":"msg","value":"device"}}},"x":920,"y":40,"wires":[[]]},{"id":"2cb04fee.cdd7c","type":"switch","z":"42f0fc95.1cc554","name":"","property":"action","propertyType":"msg","rules":[{"t":"eq","v":"Announce","vt":"str"},{"t":"eq","v":"Speak","vt":"str"},{"t":"eq","v":"Whisper","vt":"str"},{"t":"eq","v":"PlayMP3","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":590,"y":120,"wires":[["e118d577.349ee8","a80c8b99.d286f8"],["fa6de01e.9c9a","a80c8b99.d286f8"],["ff7ceee9.fa875"],[]]},{"id":"fa6de01e.9c9a","type":"alexa-remote-routine","z":"42f0fc95.1cc554","name":"Speak","account":"A-Account","routineNode":{"type":"speak","payload":{"type":"regular","text":{"type":"msg","value":"testtospeak"},"devices":{"type":"msg","value":"device"}}},"x":910,"y":120,"wires":[[]]},{"id":"3324a643.0d98ea","type":"alexa-remote-routine","z":"42f0fc95.1cc554","name":"Whisper","account":"A-Account","routineNode":{"type":"speak","payload":{"type":"ssml","text":{"type":"msg","value":"texttospeak"},"devices":{"type":"msg","value":"device"}}},"x":920,"y":200,"wires":[[]]},{"id":"ff7ceee9.fa875","type":"function","z":"42f0fc95.1cc554","name":"","func":"\n        msg.texttospeak = '<speak><amazon:effect name=\"whispered\">' + msg.texttospeak + '</amazon:effect></speak>';\n        \n        return msg;\n","outputs":1,"noerr":0,"x":730,"y":160,"wires":[["3324a643.0d98ea","a80c8b99.d286f8"]]},{"id":"2b19924b.163b3e","type":"debug","z":"42f0fc95.1cc554","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":610,"y":220,"wires":[]},{"id":"a5263ef3.9b6b8","type":"alexa-remote-routine","z":"42f0fc95.1cc554","name":"Announce","account":"A-Account","routineNode":{"type":"speakAtVolume","payload":{"type":"regular","text":{"type":"msg","value":"texttospeak"},"volume":{"type":"msg","value":"volume"},"devices":{"type":"msg","value":"device"}}},"x":920,"y":260,"wires":[[]]},{"id":"1483ad36.6409c3","type":"switch","z":"42f0fc95.1cc554","name":"","property":"action","propertyType":"msg","rules":[{"t":"eq","v":"Announce","vt":"str"},{"t":"eq","v":"Speak","vt":"str"},{"t":"eq","v":"Whisper","vt":"str"},{"t":"eq","v":"PlayMP3","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":590,"y":320,"wires":[["a5263ef3.9b6b8","2b19924b.163b3e"],["fa147497.696a88"],["aa1de5d6.f99cd8"],[]]},{"id":"fa147497.696a88","type":"alexa-remote-routine","z":"42f0fc95.1cc554","name":"Speak","account":"A-Account","routineNode":{"type":"speakAtVolume","payload":{"type":"regular","text":{"type":"msg","value":"texttospeak"},"volume":{"type":"msg","value":"volume"},"devices":{"type":"msg","value":"device"}}},"x":910,"y":320,"wires":[[]]},{"id":"bb586cab.e42c8","type":"alexa-remote-routine","z":"42f0fc95.1cc554","name":"Whisper","account":"A-Account","routineNode":{"type":"speakAtVolume","payload":{"type":"ssml","text":{"type":"msg","value":"texttospeak"},"volume":{"type":"msg","value":"volume"},"devices":{"type":"msg","value":"device"}}},"x":920,"y":400,"wires":[[]]},{"id":"aa1de5d6.f99cd8","type":"function","z":"42f0fc95.1cc554","name":"","func":"\n        msg.texttospeak = '<speak><amazon:effect name=\"whispered\">' + msg.texttospeak + '</amazon:effect></speak>';\n        \n        return msg;\n","outputs":1,"noerr":0,"x":750,"y":360,"wires":[["bb586cab.e42c8"]]},{"id":"505588d9.c80308","type":"switch","z":"42f0fc95.1cc554","name":"","property":"volume","propertyType":"msg","rules":[{"t":"null"},{"t":"nnull"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":120,"wires":[["2cb04fee.cdd7c"],["1483ad36.6409c3"]]},{"id":"caca23a1.454e3","type":"mqtt-broker","z":"","name":"MQTTSERVER","broker":"127.0.0.1","port":"1883","clientid":"myClient","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"A-Account","type":"alexa-remote-account","z":"","name":"CookieAccount","authMethod":"cookie","proxyOwnIp":"localhost","proxyPort":"3456","cookieFile":"","refreshInterval":"3","alexaServiceHost":"pitangui.amazon.com","amazonPage":"amazon.com","acceptLanguage":"en-US","userAgent":"","useWsMqtt":"on","autoInit":"on"}]

  • #2
    Well mr.Magoo now you have sparked my interest. I have all the gear setup as you described but need help with what should be the simplest part. Authenticating my Alexa account.

    Everything I try seams to fail.

    Thanks

    B

    Comment


    • #3
      1-5 for simple login (but you have to login every time you deploy) , 1-7 to grab the cookie

      You might have to change the host/page depending on what you guys use down under.


      Add this flow
      Code:
      [{"id":"8c611665.a086c8","type":"alexa-remote-init","z":"95ab52ba.bdd6d","name":"","account":"24975ac8.2d8616","option":"refresh","x":420,"y":560,"wires":[["d8ab29f.307b4d8"]]},{"id":"29bc7e29.6017c2","type":"inject","z":"95ab52ba.bdd6d","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":620,"wires":[["8c611665.a086c8"]]},{"id":"d8ab29f.307b4d8","type":"debug","z":"95ab52ba.bdd6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":630,"y":500,"wires":[]},{"id":"24975ac8.2d8616","type":"alexa-remote-account","z":"","name":"MyAlexa","authMethod":"proxy","proxyOwnIp":"192.x.x.x","proxyPort":"3456","cookieFile":"","refreshInterval":"3","alexaServiceHost":"pitangui.amazon.com","amazonPage":"amazon.com","acceptLanguage":"en-US","userAgent":"","useWsMqtt":"on","autoInit":"on"}]

      1. Double click the Alexa Init / Refresh node and give it a name, and update the account settings (pen)

      Click image for larger version  Name:	1.PNG Views:	0 Size:	17.4 KB ID:	1321197

      2. Change the IP to the IP of your device, if you're on a machine where you have a local webbrowser you can leave it as blank/local host but if you need to access it from another device you need to enter the IP it should listen from / bind to.
      Click image for larger version  Name:	image_81173.png Views:	3 Size:	40.0 KB ID:	1321195

      3. Point your browser to your IP :3456 and it'll open up the alexa login
      Click image for larger version  Name:	3.PNG Views:	0 Size:	15.7 KB ID:	1321193



      4. Login (it'll say "Amazon Alexa Cookie successfully retrieved. You can close the browser." when done
      Click image for larger version  Name:	image_81180.png Views:	3 Size:	47.6 KB ID:	1321202


      5. There appears there's a bug so the cookie gets "lost" from the debug window the first time, so once the status says "ready" you can insert and have it refresh the cookie

      Click image for larger version  Name:	5.PNG Views:	0 Size:	15.1 KB ID:	1321196


      6. Open the debug window and copy everything in the Local Cookie string (between the " ")
      Click image for larger version  Name:	6.png Views:	0 Size:	18.1 KB ID:	1321194

      7. Create a new account and set the method to Cookie and paste your cookie into the cookie field
      Click image for larger version  Name:	image_81181.png Views:	3 Size:	26.3 KB ID:	1321203

      Comment


      • #4
        Hi mr.Magoo, Thank you for the detailed instruction, I would never have got there without this help.

        Ok here is where i'm up to. Basically I'm now stuck on step 3. I get the open xxx in your browser. but the Browser will not open the page. I have tried on numerous computers win10 (using different browsers) rpi, and ios safari. even tried to open port 3456 to the Alexa. I'm running a Unifi network and also tried turning off the firewall. is there another way to get this cookie info in there?

        Comment


        • #5
          Did you change the ip and the ip listed when it says "open... :3456" matches that of your node red device

          The ip is the ip of the device running node-red, not your alexa device.

          Comment


          • #6
            Thanks that was spot on, advanced to the next stage. Completed the amazon login. got the "ready" status but nothing but an error in debug.


            TypeError: failed to initialise smarthome colors: "Cannot read property 'parameters' of undefined" at AlexaRemoteExt.initSmarthomeColorsExt (/home/pi/.node-red/node_modules/node-red-contrib-alexa-remote2/lib/alexa-remote-ext.js:307:35) at process._tickCallback (internal/process/next_tick.js:68:7)

            Comment


            • #7
              Disregard the error, it's a part of the bug I'm talking about in #5 (FWIW, I'm NOT the developer of any of the packages)

              Does the Node say "Ready" ?
              Click image for larger version

Name:	ready.PNG
Views:	229
Size:	13.7 KB
ID:	1321264


              Technically you're done at that point and if you have other Alexa-Nodes using the same account/login method they should all be "ready" and you can start to test it,

              The Cookie (which I still recommend using, at least during the debug/test phase) is only to make life easier during debug.

              Comment


              • #8
                Finally some success, thank you for your patients and support.

                I must say even though its still a work in progress it does work very well.

                I had some mixed success with the flow you presented. Mostly it worked, and better than I could have done on my own.

                I have two devices. and the Announce/All did not work at all. I was able to post a Alexa/Announce/Office (using my device name instead of Office) but did not get the Chime, sounded the same as Speak. all the others where the device name was specified worked ok (except the announce chime)

                For what I need its working very well. Now hopefully they can fix the cookie bug to make this even better.


                Comment


                • #9
                  The bug isn't related to the cookie, it just happens to affect the debug log that way.... but yes, its work in progress and both developers have been very helpful and fast to fix any issues.

                  It's odd that yours doesn't work the same as mine, but that might be down to my parse which is pretty crude.
                  Which mqtt plugin do you use to send the messages ?

                  For fun, try and add a routine node and manually configure it to announce and what to say and just use a single inject to trigger it (to rule out mqtt/parsing).
                  If you leave the device (in the node settings) as an empty string it should announce to all.

                  My parse requires you (I think, can't verify right now) to name it ALL (all caps), if you do "All" it won't work.

                  Comment


                  • #10
                    I use the MQTT Lens software, its a Chrome plugin. Using "ALL" in the Announce. also tried using MQTT from HS3 still no difference. Really puzzling, but not a show stopper.

                    Comment


                    • #11
                      Click image for larger version

Name:	Capture.PNG
Views:	175
Size:	7.5 KB
ID:	1322541

                      I've used Lens for debugging a few times so I'm familiar with it - using this setting works for me.
                      If you enable the debug flags in NodeRed it should hopefully tell you what's going on.

                      Comment


                      • #12
                        I got to this to work! Have you messed with the SSML modes any? I would like to use the the whisper mode but haven't had any luck.

                        Mike

                        Comment


                        • #13
                          Yes I'm using it, my flow (posted in the first post) should work with Whisper if you send it as:
                          Alexa/Whisper/Office=Good Morning

                          Or - if you're using some other method, just use a function to alter the message:


                          msg.texttospeak = '<speak><amazon:effect name="whispered">' + msg.texttospeak + '</amazon:effect></speak>';

                          return msg;


                          The only thing that doesn't work right now (sadly) is to play stored media, i.e. sound effects etc. Theoretically you should be able to do that with SSML too, but it doesn't work just yet. Playing regular music as normal with Alexa works just fine.

                          Comment


                          • #14
                            Just tested it and it works fine...

                            I you do anything by volume and get an "unexpected response while getting volume:" then that's thrown me off in the past.

                            What the code does is that it will first read the current volume, then set the desired volume, do whatever it is you're asking it to do (speak, announce, whisper...) and then restore the volume back to the original setting.

                            However, the part where it is reading the current volume is reading a section of the media handling and if you haven't played any media in a while it's "forgotten" and everything is blank and as a result the Node gets a bit upset... the quick and dirty way to remedy this is to simply have Alexa play some tunes for a second or two so that her memory gets restored.

                            Comment


                            • #15
                              Originally posted by thomauto@aol.com View Post
                              I got to this to work! Have you messed with the SSML modes any? I would like to use the the whisper mode but haven't had any luck.

                              Mike
                              I'm able to have alexa speak by manual triggering it in node-red but not having any luck through mqtt. I setup a mqtt input and i can see it in the debug messages but i cant pass or trigger tts. Any advice?

                              new to node-red and somewhat new to mqtt.

                              Comment

                              Working...
                              X