38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
import paho.mqtt.client as mqtt
|
|
import logging
|
|
import json
|
|
|
|
from src.generic.http_api import Http_api
|
|
|
|
def rhasspy_mqtt(ip, ratatouille):
|
|
|
|
def on_connect(client, userdata, flags, rc):
|
|
client.subscribe("hermes/intent/#")
|
|
logging.info("Connected. Waiting for intents.")
|
|
|
|
def on_disconnect(client, userdata, rc):
|
|
logging.info('yoda has been disconnected')
|
|
|
|
def on_message(client, userdata, msg):
|
|
print(str(msg.payload))
|
|
logging.info('get message on ' + msg.topic)
|
|
ratatouille.parse_rhasspy_command(json.loads(msg.payload))
|
|
|
|
client = mqtt.Client()
|
|
client.on_connect = on_connect
|
|
client.on_disconnect = on_disconnect
|
|
client.on_message = on_message
|
|
client.ratatouille = ratatouille
|
|
client.connect(ip, 1883)
|
|
client.loop_start()
|
|
|
|
class Rhasspy(Http_api):
|
|
|
|
def __init__(self,url):
|
|
super().__init__('Rhasspy',url)
|
|
|
|
def say(self,text):
|
|
response = self.build_request('api/text-to-speech','post',text)
|
|
|
|
# api rhasspy... (tts)
|