Created
June 13, 2017 01:52
-
-
Save kd8bxp/6520a4dcda1a43834a6cda402fa441d2 to your computer and use it in GitHub Desktop.
Python Script for Raspberry PI Speech Synthesizer project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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