Trouble with text-to-speech over MQTT

Opps, actually confused your log with romkabouter’s, re: the speechengine. sorry. My suggestion about MQTT.fx is really focused on testing the string. After you connect to your mosquitto broker, and subscribe to the topic, you can publish to the same topic, which bypasses your code. (not saying that there’s any incorrect, but I’ve found trying to isolate the the simplistic configuration helps). I had a lot of issue originally learning MQTT & python, and it really helped me to understand what I needed to do. If you copy/paste a work json to do tts, and you don’t get it to work, then something’s happening on the rhasspy end. if it does work, then you can look at your code. Just my two cents, and let me know if there is anything I can do to help.

Life’s gotten derailed a bit and I am just now finally taking a look at MQTT.fx. It appears that it has become a commercial product with licensing fees. Are you using an older version you got from somewhere? It certainly looks helpful.

You can still download version 1.7 here

http://www.jensd.de/apps/mqttfx/1.7.1/

But there are other good tools out there I think.

Thanks for that. The results were very interesting. As expected, I was able to use MQTT.fx to subscribe to the text-to-speech topic, and if I took a message generated by the web interface, I could copy it and publish it to the topic and generate speech. However, if I published using my application, I would see a message that looked identical when I looked in MQTT.fx. If I then copied that message and published it inside of MQTT.fx, speech was also generated. I also copied this successful message text into Visual Studio, and I spot no character differences in the message. This is bizarre, because if the message wasn’t published, I wouldn’t be able to copy it and republish it from MQTT.fx. And yet somehow when I published from my application using mosquitto, no speech is generated.

If I ask for the library version, I’m getting version number 1.5.7 in my application, and in MQTT.fx, so I’m guessing that’s the version of the broker? From what I’m seeing online, that version is too early to be using protocol version 5, which I’m not attempting to do in my application. So again I have absolutely no idea what’s going wrong. If anyone has any further ideas, please share them!

Are you using the same credentials on the broker? Not sure if it matters, but just to verify

I’m just using the internal Rhasspy MQTT broker, which I didn’t think needed credentials. And all of the topics subscription stuff is working just fine. And even the publishing is working, except that it doesn’t produce speech, whereas the other methods of publishing are working.

What does “mosquitto -v” say?
If it’s version 2.x, this might help:
https://community.rhasspy.org/t/bullseye-mosquitto-and-authentification-for-remote-access/3444

Hey Light, I’m a fan of trying to start with the simplest possible script, and building from there. I’m sure your programming skills are far beyond mine, but since you’re having such an unusual issue, maybe just seeing if you can connect to the broker and publish a message, and then put in your json?

import paho.mqtt.client as mqtt #import the client

def on_connect(client, userdata, flags, rc):
  print("Connected with result code " + str(rc)) # for debugging, uncomment to check if connected, should be result code 0
  client.subscribe("hermes/tts/say/#")

def on_publish(client,userdata,result): #create function for callback
    print("data published \n")

def on_message(client, userdata, message):
    print("message received " ,str(message.payload.decode("utf-8"))) # for debugging, uncomment to check message
    print("message topic=",message.topic) # for debugging, uncomment to check topic
    print("message qos=",message.qos) # for debugging, uncomment to check quality of service
    print("message retain flag=",message.retain) # for debugging, uncomment to check retained message flag

client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("XXX.XXX.XXX.XXX", 1883, 60)
client.publish("hermes/tts/say","Hello")
client.loop_forever()

Actually, I don’t have the mosquitto command. I guess I haven’t installed the package that it comes from. Sadly, I don’t really remember what I did to get things compiling in the first place. I usually try to take notes, but I think I failed to do that this time.

Yeah, regardless of our abilities, starting simple is certainly the way to go. As you suggest, I am able to publish messages, which I have confirmed multiple ways. But for whatever reason the messages don’t produce speech, despite looking correct as far as I can tell. I’m starting to feel a sneaking suspicion that I’m going to feel rather silly once this finally gets figured out.

Yes, I feel silly. I finally figured out the issue, although I’m not quite sure why it matters. It’s actually present in my initial code snippet, when I’m calculating the size of the message payload. I use strlen + 1, because I was under the impression the payload size needed to include the null terminator. However, if I remove the +1, the message publishes successfully and speech is generated. I guess something about including this character in the message throws off the parsing of the message on the Rhasspy side of things.

Great that you found the issue. Always a pain when you’re trying to solve it.
Good work :slight_smile:

congrats! glad you solved it.

@romkabouter @JeffC Thank you both, and everyone else who provided suggestions.