-
Notifications
You must be signed in to change notification settings - Fork 4
/
voice.py
31 lines (26 loc) · 828 Bytes
/
voice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- coding: utf-8 -*-
#
# K9's Voice client
#
# authored by Richard Hopkins August 2023
#
# Licensed under The Unlicense, so free for public domain use
#
# This program interacts with the k9_speechserver.py program
# to give K9 a voice
import paho.mqtt.client as mqtt
class Voice():
'''
Simple client class so that K9 can speak
'''
def __init__(self) -> None:
self.client = mqtt.Client("k9-speech-client")
self.client.connect(host = "localhost", port = 1883)
self.client.on_publish = self.on_publish
self.client.loop_start()
def speak(self, speech:str) -> None:
print("Speech:",speech)
self.client.publish(topic="k9/events/speech", payload=speech, qos = 2, retain = False)
return
def on_publish(self, client, userdata, mid):
pass