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

    #31
    The above has some pre-requisites:
    1. In the flow, it is expecting a mqtt message like Notify/6=this is a test This would send "this is a test" for a duration of 6 seconds to be displayed
    2. Look in the change nodes - there is a property called msg.server - this is the IP of your firestick
    3. You can set the filename to whatever you want - I have it set to show the last image from the netcam homeseer plugin

    Comment


      #32
      Originally posted by Furious View Post

      From the amazon store, install "notifications for fire tv" - install it, and run it, it then stays loaded even after reboot.
      This is basically a http server which listens on port 7676 - waiting for something to be posted to the server.

      So, next up , here's my flow which listens for the "Notify" topic and then triggers the call out to python:
      Code:
      [{"id":"f30bf535.f431e8","type":"function","z":"7b1d3f60.25be3","name":"Parse Message","func":" var tokens = msg.topic.split(\"/\");\n flow.set('mesg',msg.payload);\n flow.set('dura',tokens[1]);\n //flow.set('device',tokens[2]);\n return msg;","outputs":1,"noerr":0,"x":200,"y":140,"wires":[["bdfd1ea6.c36d9","95e86db8.5fc88","c430c66f.865108"]]},{"id":"c430c66f.865108","type":"debug","z":"7b1d3f60.25be3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":590,"y":40,"wires":[]},{"id":"853a5483.a4bb88","type":"debug","z":"7b1d3f60.25be3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":770,"y":140,"wires":[]},{"id":"d6af2709.e62048","type":"send_notify","z":"7b1d3f60.25be3","x":590,"y":140,"wires":[["853a5483.a4bb88"]]},{"id":"bdfd1ea6.c36d9","type":"change","z":"7b1d3f60.25be3","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"mesg","tot":"flow"},{"t":"set","p":"server","pt":"msg","to":"192.168.5.135","tot":"str"},{"t":"set","p":"duration","pt":"msg","to":"dura","tot":"flow"},{"t":"set","p":"file","pt":"msg","to":"C:\\Program Files (x86)\\HomeSeer HS3\\html\\netcam\\currentimage.jpg","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":140,"wires":[["d6af2709.e62048"]]},{"id":"95e86db8.5fc88","type":"change","z":"7b1d3f60.25be3","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"mesg","tot":"flow"},{"t":"set","p":"server","pt":"msg","to":"192.168.5.146","tot":"str"},{"t":"set","p":"duration","pt":"msg","to":"dura","tot":"flow"},{"t":"set","p":"file","pt":"msg","to":"C:\\Program Files (x86)\\HomeSeer HS3\\html\\netcam\\currentimage.jpg","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":200,"wires":[["d6af2709.e62048"]]},{"id":"20969819.9690e8","type":"mqtt in","z":"7b1d3f60.25be3","name":"","topic":"Notify/#","qos":"0","datatype":"auto","broker":"bc36b861.c8f2a8","x":100,"y":60,"wires":[["f30bf535.f431e8"]]},{"id":"bc36b861.c8f2a8","type":"mqtt-broker","z":"","name":"MQTTSERVER","broker":"127.0.0.1","port":"1883","clientid":"myClient","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
      Import this flow after you've installed the below:

      Next up - install pynodered:
      https://pypi.org/project/pynodered/

      So, you need to have a function to shell out to. Here's my two functions for notify and also send ADB commands - save it as notify.py somewhere:
      Code:
      from pynodered import node_red
      import base64
      import io
      import logging
      import sys
      
      import requests
      from requests.auth import HTTPBasicAuth, HTTPDigestAuth
      import voluptuous as vol
      import os
      import time
      
      @node_red(category="pyfuncs")
      def send_notify(node, msg):
      remoteip = msg['server']
      duration1 = msg['duration']
      message = msg['payload']
      fileup = msg['file']
      fontsize = 0
      position = 0
      transparency = 0
      color = "#607d8b"
      interrupt = False
      timeout = 5
      target=F"http://{remoteip}:7676"
      file_as_bytes = open(fileup, "rb")
      """Send a message to a Android TV device."""
      payload = dict(
      filename=(
      "image",
      file_as_bytes,
      "application/octet-stream",
      {"Expires": "0"},
      ),
      type="0",
      title="Notification",
      msg=message,
      duration=duration1,
      fontsize=0,
      position=0,
      bkgcolor=color,
      transparency=0,
      offset=0,
      app="Notifications for Fire TV",
      force="true",
      interrupt="False",
      )
      
      try:
      response = requests.post(target, files=payload, timeout=5)
      msg['payload'] = str(response)
      if response.status_code != 200:
      _LOGGER.error("Error sending message: %s", str(response))
      msg['payload'] = "Error sending message: %s", str(response)
      except requests.exceptions.ConnectionError as err:
      _LOGGER.error("Error communicating with %s: %s", target, str(err))
      msg['payload'] = "Error communicating with %s: %s", target, str(err)
      return msg
      
      @node_red(category="pyfuncs")
      def send_adb(node, msg):
      totaloutput = []
      remoteip = msg['server']
      cmdargs = msg['payload']
      path = msg['path']
      os.chdir(path)
      connect = os.popen("adb connect " + remoteip + ":5555" ).read()
      print(connect)
      length = len(cmdargs)
      for i in range(length):
      if "timeout" in cmdargs[i]:
      timsecs = cmdargs[i]
      timsecs2 = int(timsecs[-2:])
      time.sleep(timsecs2)
      else:
      output = os.system("adb -s " + remoteip + ":5555" + " " + cmdargs[i])
      print(output)
      totaloutput.append(output)
      msg['payload'] = totaloutput
      return msg
      Next up - you have to launch pynode red first so that node-red can load the function nodes.
      In my server startup script, I have the following to load them:
      Code:
      c:\scripts\pskill pynodered.exe
      start cmd /k "pynodered c:\scripts\python\notify.py"
      timeout /t 2
      start cmd /k "node-red"
      exit
      This ensures that node-red is called after pynodered is loaded, and also allows pynodered to load. Of course, you'll need to change the paths, as my stuff is in the c:\scripts\python directory
      I'm going to dive into this as soon as I get a chance, thanks!!

      Comment


        #33
        Once you get node-red installed, install the amazon echo stuff, you can control so much with it

        Comment


          #34
          Originally posted by Furious View Post
          Once you get node-red installed, install the amazon echo stuff, you can control so much with it
          I have experimented with the Echo stuff but I haven't put it to anything practical yet. I have the wemo stuff added in, that along with MQTT is way better than IFTTT.

          Comment


            #35
            Thanks to all who have shared in this thread. I worked through this over the weekend getting all the node red stuff installed on my HS box and I've been able to experiment a bit with having my various alexa devices speak. I also installed the mcsMQTT plugin but I am a complete novice with MQTT and node red, so would someone kindly share an example or two of how they have used a homeseer event to accomplish the TTS to Alexa?

            Thanks in advance

            Comment


              #36
              Assuming you're using the mosca node in node red...

              Ok, so you'll need something in HS to send mqtt - mcsmqtt plugin is good (and free!), I found the big 5 PI was a bit cpu intensive.
              In mcsmqtt, configure the server so you're connecting to the node red mosca in - if node red is on the same server as HS, then it'll be 127.0.0.1:1883
              In node red, in a flow where you have alexa already working - use a mosca in node. On that side, set the topic to be "announce" or "notify" or something that makes sense.
              then, connect that to a function node that parses the text from MQTT into whats needed. Take a look at my alexa flow:
              Code:
              [{"id":"9250a404.539ad8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"97f71a33.9495b8","type":"mqtt in","z":"9250a404.539ad8","name":"","topic":"Alexa/#","qos":"0","datatype":"auto","broker":"f549ea28.ce29a8","x":70,"y":120,"wires":[["cf765d95.d44c4"]]},{"id":"cf765d95.d44c4","type":"function","z":"9250a404.539ad8","name":"Parse Message","func":"        var tokens = msg.topic.split(\"/\");\n        msg.action = tokens[1];\n       if (tokens[2] == \"ALL\") {\n          msg.device = null;\n        } else {\n          msg.device = tokens[2];\n        }\n       if (tokens.length==4) {\n        msg.volume = tokens[3];\n        } else {\n        msg.volume = null\n        } \n        //msg.texttospeak = \"<speak><audio src='https://filedn.com/lv3NincPy9z7OvkmPJwLzW4/hail_allship_v2.mp3' />\" + msg.payload + \"</speak>\";\n        msg.texttospeak = msg.payload;\n        return msg;","outputs":1,"noerr":0,"x":200,"y":40,"wires":[["1355d6ed.36e149"]]},{"id":"4879f222.a8b9ec","type":"alexa-remote-routine","z":"9250a404.539ad8","name":"Announce","account":"33d8b78.2b3d048","routineNode":{"type":"speak","payload":{"type":"announcement","text":{"type":"msg","value":"texttospeak"},"devices":{"type":"msg","value":"device"}}},"x":700,"y":40,"wires":[[]]},{"id":"d131a2ac.ab6b7","type":"switch","z":"9250a404.539ad8","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":310,"y":160,"wires":[["4879f222.a8b9ec"],["69d7b875.df2fe8","76ae8c18.e31124"],["3c85baac.5da3d6"],[]]},{"id":"b8793842.a9cf78","type":"alexa-remote-routine","z":"9250a404.539ad8","name":"Whisper","account":"33d8b78.2b3d048","routineNode":{"type":"speak","payload":{"type":"ssml","text":{"type":"msg","value":"texttospeak"},"devices":{"type":"msg","value":"device"}}},"x":700,"y":160,"wires":[[]]},{"id":"3c85baac.5da3d6","type":"function","z":"9250a404.539ad8","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":550,"y":160,"wires":[["b8793842.a9cf78"]]},{"id":"3d01a174.bdc22e","type":"alexa-remote-routine","z":"9250a404.539ad8","name":"Announce","account":"33d8b78.2b3d048","routineNode":{"type":"speakAtVolume","payload":{"type":"regular","text":{"type":"msg","value":"texttospeak"},"volume":{"type":"msg","value":"volume"},"devices":{"type":"msg","value":"device"}}},"x":700,"y":220,"wires":[[]]},{"id":"abcb1f54.f23d6","type":"switch","z":"9250a404.539ad8","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":310,"y":240,"wires":[["3d01a174.bdc22e"],["1f1a2914.829ec7"],["4026c4f5.95710c"],[]]},{"id":"1f1a2914.829ec7","type":"alexa-remote-routine","z":"9250a404.539ad8","name":"Speak","account":"33d8b78.2b3d048","routineNode":{"type":"speakAtVolume","payload":{"type":"regular","text":{"type":"msg","value":"texttospeak"},"volume":{"type":"msg","value":"volume"},"devices":{"type":"msg","value":"device"}}},"x":690,"y":280,"wires":[[]]},{"id":"25563b23.e957d4","type":"alexa-remote-routine","z":"9250a404.539ad8","name":"Whisper","account":"33d8b78.2b3d048","routineNode":{"type":"speakAtVolume","payload":{"type":"ssml","text":{"type":"msg","value":"texttospeak"},"volume":{"type":"msg","value":"volume"},"devices":{"type":"msg","value":"device"}}},"x":700,"y":340,"wires":[[]]},{"id":"4026c4f5.95710c","type":"function","z":"9250a404.539ad8","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":550,"y":340,"wires":[["25563b23.e957d4"]]},{"id":"1355d6ed.36e149","type":"switch","z":"9250a404.539ad8","name":"","property":"volume","propertyType":"msg","rules":[{"t":"null"},{"t":"nnull"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":40,"wires":[["d131a2ac.ab6b7"],["abcb1f54.f23d6"]]},{"id":"69d7b875.df2fe8","type":"alexa-remote-routine","z":"9250a404.539ad8","name":"Speak to dots","account":"33d8b78.2b3d048","routineNode":{"type":"speak","payload":{"type":"regular","text":{"type":"msg","value":"texttospeak"},"devices":["G090VC0783770T8G"]}},"x":740,"y":80,"wires":[[]]},{"id":"76ae8c18.e31124","type":"alexa-remote-routine","z":"9250a404.539ad8","name":"Speak to dots","account":"33d8b78.2b3d048","routineNode":{"type":"speak","payload":{"type":"regular","text":{"type":"msg","value":"texttospeak"},"devices":["G090LF0964060HVR"]}},"x":740,"y":120,"wires":[[]]},{"id":"f549ea28.ce29a8","type":"mqtt-broker","z":"","name":"MQTTSERVER","broker":"192.168.5.150","port":"1883","clientid":"myClient","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"33d8b78.2b3d048","type":"alexa-remote-account","z":"","name":"CookieAccount","authMethod":"cookie","proxyOwnIp":"localhost","proxyPort":"3456","cookieFile":"","refreshInterval":"3","alexaServiceHost":"layla.amazon.co.uk","amazonPage":"amazon.co.uk","acceptLanguage":"en-GB","userAgent":"","useWsMqtt":"on","autoInit":"on"}]
              The function splits the mqtt message up so you can send to just one device, but I decided to just send it to those two dots.

              On the HS side, my events work like this:
              I created a virtual device called "Text notifications" - this device gets its string set by lots of other events
              I have an event using the easytrigger PI that is IF "text notifications" device string changes, then send a MQTT message of Alexa/Speak/Garden Room dot=$$DTR3):

              This is basically driving the node red flow.

              I mean you can try other things like using the http nodes to have your own little web server, but MQTT/MOSCA are good to have anyway, as it is a nice simple text platform as a broker and you don't need to mess around. It's also widely adopted, so allows for other IOT stuff to integrate

              Comment


                #37
                Originally posted by Furious View Post
                Assuming you're using the mosca node in node red...
                I got my TTS working a few days ago using examples in this thread. I'm new to node red and had never heard of mosca. I set up the windows version of mosquitto broker. Other than the obvious convenience of not having to run another piece of software are there any pros/cons using one or the other when it comes to features, resource usage, etc? Can mosca be secured with password and certs also? Unless there is some lack of features in mosca compared to mosquitto it sounds like I may be switching up my broker tonight.

                Comment


                  #38
                  Check the node info out for the server side - you can specify a username and password, and require SSL. I've since moved away from windows and gone to docker with a couple of raspberry pi 4s - being able to deploy apps with a yml file and not worry about interactions or interdependencies has really pushed me onto linux.

                  Currently one pi has openwrt on it which is now running snort and mwan3 to be able to share vpn connections based on source IP or destination..... steep learning curve, but way cool.

                  Comment


                    #39
                    Sounds like something I was going to attempt with pfSense and pfblocker. I haven't got around to it yet but the idea was to tunnel traffic based on destination to get around geoblocking so my wife could watch German content from some of their networks without forcing all of the streaming traffic from that device through the tunnel. Is there some kind of guide or write up you found useful when you were implementing you current solution?

                    Comment


                      #40
                      Not to scare people away too much as there's no hacking involved if you rather just run windows, I'm running my whole setup on a W2016 server
                      i.e. NodeRed, Mosquitto (for MQTT) and HS3 (plus Grafana and InfluxDB for logging / graphs). should work just fine on 2012 server or 2010

                      Somehow Pi's feel sketchier (lets not turn this into a windows joke thread, OK so I try to keep them on semi single duties.
                      One is my 1W controller, one is my doorbell and then the two ZNet's

                      Comment


                        #41
                        Originally posted by Statikk View Post
                        Sounds like something I was going to attempt with pfSense and pfblocker. I haven't got around to it yet but the idea was to tunnel traffic based on destination to get around geoblocking so my wife could watch German content from some of their networks without forcing all of the streaming traffic from that device through the tunnel. Is there some kind of guide or write up you found useful when you were implementing you current solution?
                        Sign up for YouTV on a PC, Roku, or FireTV and watch any German programming you want without hassle. You'll thank me later.


                        Sent from my Pixel 2 using Tapatalk

                        Comment


                          #42
                          Originally posted by mterry63 View Post
                          You'll thank me later.
                          You're right! Thank you!! I'll still do the set up to bypass geo-blocking for those random things here and there but that service is amazing and totally hassle free! I had been looking for something like that for awhile now so my in laws have more German stuff to watch than just NDR and the few things that aren't blocked on some of the mediatheks. Plus it has the added bonus of having a nice easy to use interface.

                          Comment


                            #43
                            Looks like I have to re-auth every few days. I've tried cookie mode and account mode. Is this a current limitation or did I do something wrong?

                            thx,
                            mike

                            Comment


                              #44
                              Originally posted by mjolsen View Post
                              Looks like I have to re-auth every few days. I've tried cookie mode and account mode. Is this a current limitation or did I do something wrong?

                              thx,
                              mike
                              Do you have the cookie mode set to write to a valid file?

                              Sent from my Pixel 2 using Tapatalk

                              Comment


                                #45
                                Originally posted by mterry63 View Post
                                Do you have the cookie mode set to write to a valid file?

                                Sent from my Pixel 2 using Tapatalk
                                didn't see any instructions on that nor did I find such options?

                                Comment

                                Working...
                                X