Skip to content

Instantly share code, notes, and snippets.

@kd8bxp
Created June 13, 2017 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kd8bxp/6520a4dcda1a43834a6cda402fa441d2 to your computer and use it in GitHub Desktop.
Save kd8bxp/6520a4dcda1a43834a6cda402fa441d2 to your computer and use it in GitHub Desktop.
Python Script for Raspberry PI Speech Synthesizer project
import paho.mqtt.client as paho
import os
device_id = '1'
device_secret = '1234'
random_client_id = '1234'
def on_connect(client, data, flags, rc):
print('Connected, rc: ' +str(rc))
#subscription event
def on_subscribe(client, userdata, mid, gqos):
print('Subscribed: ' + str(mid))
client.publish(out_topic, 'Ready')
#recieved message event
def on_message(client, obj, msg):
say=msg.payload
#os.system('espeak "' + say + '"')
os.system('flite ' + say )
print('Finished')
client.publish(out_topic, 'Finished')
#create the MQTT client
client = paho.Client(client_id=random_client_id, protocol=paho.MQTTv31)
#assign event callbacks
client.on_message = on_message
client.on_connect = on_connect
client.on_subscribe = on_subscribe
#topics
in_topic = 'Say' #receive messages
out_topic = 'Said' #publishing messages
#client connect
client.connect("localhost")
client.subscribe(in_topic, 0)
#Continue the network loop, exit when an error occurs
os.system('flite -t "Ready"')
rc = 0
while rc == 0:
rc = client.loop()
print('rc: ' + str(rc))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment