-
-
Save stephenlb/7499d6ab4872743dc54dbe1d38884507 to your computer and use it in GitHub Desktop.
RPi Realtime Audio Broadcast
This file contains hidden or 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
| def _callback(message,channel): | |
| if message["type"]=="request" : | |
| print" Received message = ", message["play"] | |
| status=subprocess.call(["espeak","-s 120 -v en ",message["play"]], stdout=FNULL, stderr=subprocess.STDOUT) | |
| if status==0 : | |
| pubnub.publish().channel(pubnub_responsechannel).message(postive_response).async(publish_callback) | |
| elif status!=0 : | |
| pubnub.publish().channel(pubnub_responsechannel).message(negative_response).async(publish_callback) | |
| if message["type"]=="completed" : | |
| pubnub.publish().channel(pubnub_responsechannel).message(done).async(publish_callback) | |
| sys.exit() | |
| def publish_callback(result, status): | |
| pass | |
| # Handle PNPublishResult and PNStatus |
This file contains hidden or 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
| def process_request(): | |
| sentence = importData().split(".") | |
| for data in sentence : | |
| print "sending message: ",data | |
| request={"type" : "request" , "play" : data} | |
| pubnub.publish().channel(pubnub_requestchannel).message(request).async(publish_callback) | |
| lock.acquire() | |
| def publish_callback(result, status): | |
| pass | |
| # Handle PNPublishResult and PNStatus | |
| pubnub.publish().channel(pubnub_requestchannel).message(complete_sentence).async(publish_callback) |
This file contains hidden or 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
| def _callback(message,channel): | |
| if message["status"]== "positive": | |
| lock.release() | |
| elif message["status"]== "negative": | |
| print "error in response" | |
| elif message["status"]== "done": | |
| sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment