Alexa - -Unsolicited TTS

Ah, very nice! Thanks for the tip.

I have managed to get a node-red flow working that lets me pass in the text to speech as a parameter. It is working well from a browser.

HTTP switch here I come...

@ogiewon @csteele

Were either of you able to make this work without manually copying the cookie in?

I didn't even try it based on your feedback. I had to use Firefox with the cookie.txt extension to save the .alexa.cookie file.

I had no cookie hurdle. It just worked... for now.

2 Likes

So here is what I have so far, however it never seems to connect via Telnet. Nothing is ever logged from the parse() routine. This is my first attempt at using the new Telnet Capability in Hubitat, so I am sure I am doing something wrong.

@bravenel - Bruce, can you take a look and provide me with a hint on what to change? Have you tested the telnet capability with a Raspberry Pi yet? Any special things to be aware of? When I click Save on the Device Details page, it tries to connect via Telnet, however my Chrome browser shows the web page constantly being loaded (spinning activity indicator on the tab for the device.)

/**
*   
*   File: Alexa_TTS_Driver.groovy
*   Platform: Hubitat
*   Modification History:
*       Date       Who              What
*       2018-08-26 Dan Ogorchock    Original creation for Hubitat
*
*  Copyright 2018 Dan Ogorchock
*
*  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
*  in compliance with the License. You may obtain a copy of the License at:
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
*  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
*  for the specific language governing permissions and limitations under the License.
*
*
*/
def version() {"v0.1.20180826"}

preferences {
		input "ip", "text", title: "RPi IP Address", description: "IP Address in form '192.168.1.142'", required: true, displayDuringSetup: true
		input "port", "text", title: "RPi Telnet Port", description: "port in form of '23'", required: true, displayDuringSetup: true
		input "username", "text", title: "RPi Username", description: "username in form of 'pi'", required: true, displayDuringSetup: true
		input "password", "text", title: "RPi Password", description: "password in form of 'raspberry'", required: true, displayDuringSetup: true
		input "echoName", "text", title: "Echo Device Name", description: "Name of your echo in form of 'Kitchen'", required: true, displayDuringSetup: true
}

metadata {
    definition (name: "Alexa TTS", namespace: "ogiewon", author: "Dan Ogorchock") {
        capability "Speech Synthesis"
        capability "Telnet"
    }
}

def installed() {
    initialize()
}

def updated() {
    log.debug "Attempting to close Telnet session"
    telnetClose()
    initialize()   
}

def initialize() {
    state.version = version()
    log.debug "Attempting to connect via Telnet - IP = ${ip}, Port = ${port.toInteger()}, Username = ${username}, Password = ${password}"
    telnetConnect([termChars:[13,10]], ip, port.toInteger(), username, password)
    //give it a chance to start
	pauseExecution(1000)
}

def speak(message) {
    def msg = '/home/pi/ha-alexa-tts/alexa_remote_control.sh -d "' + "${echoName}" + '" -e speak:"' + "${message}" + '"\r\n'
    sendMsg(msg)
}

def sendMsg(String msg) {
    log.debug "Sending msg = ${msg}"
	return new hubitat.device.HubAction(msg, hubitat.device.Protocol.TELNET)
}

def parse(String msg) {
// process incoming telnet messages
    log.debug "Telnet Parse = ${msg}"
}

Indications seems to point trouble for people in the US with this. I restarted my pi and had to redo the process - not optimal :frowning:

On an up note using @ogiewon http momentary switch driver as a base, and my node red flow, I can now trigger my echo to speak through hubitat.

1 Like

Try appending CR and LF to the string you're sending. I was having issue until I added it when trying to talk to the envisalink via Telnet.

Try this

//open telnet connection
		telnetConnect([termChars:[13,10]], ip, port, username, password)
1 Like

This sounds a lot like what I was going through.

@ogiewon Isn't this the same as Pushover? Yea, different destination, but basically just pushing text to a "foreign" website.

It is similar. There is no web service listening on the RPi for this specific integration. It works great from the command line on the RPi, and via a Telnet session to the RPi. So, it seems like @cwwilson08 's idea to use Hubitat's built-in Telnet device driver capability work work well for this use-case.

My development hub has slowed to a crawl... trying to restart it now...

I was not clear, sorry.. isn't this shell script just a tutorial on what to send to alexa.google? Cant just the text to speech be trimmed down and put into an App like you did for pushover and entirely eliminate the Pi ?

Exactly like what was happening to me lol.. At least it wasn't just me.

13 10 are the default term chars, they shouldn't be required within the term char option.

Possibly, but that is beyond my skill level. This technique to get Alexa to perform TTS is not using a published API from Amazon. So, you need to emulate an interactive browser session, I believe. Not sure if this is possible directly from the HE hub.

Pushover was using a very nice published Web-API, so it was much simpler.

strange because i ended up having to manually append cr and lf at the end of my string before sending it otherwise the envisalink wouldn't respond.

How did you append CRLF to the ends of your strings? Did you simply add a "\r\n" to end of each line?

cmdToSend = cmdToSend + "\r\n"

1 Like

It seems to be getting hung up on opening the telnet session. Need to get some sleep. Hopefully someone can figure this out. I have updated my code in the earlier post with my latest version.