Skip to content

Instantly share code, notes, and snippets.

@gerswin
Last active March 25, 2017 00:54
Show Gist options
  • Save gerswin/9b912667a68ec2a6809a06d1e2192980 to your computer and use it in GitHub Desktop.
Save gerswin/9b912667a68ec2a6809a06d1e2192980 to your computer and use it in GitHub Desktop.
from socketIO_client import SocketIO, LoggingNamespace
import pygame
import urllib
import subprocess
import glob
import os
#v5
def play(audio_file_path):
subprocess.call(["ffplay", "-nodisp", "-autoexit", audio_file_path])
for fl in glob.glob("*.mp4"):
os.remove(fl)
def on_connect():
print('connect')
def on_disconnect():
print('disconnect')
def on_reconnect():
print('reconnect')
def on_aaa_response(*args):
print('on_aaa_response', args)
def push_action(*args):
print('push', args)
pygame.mixer.init()
pygame.mixer.music.load("police.wav")
pygame.mixer.music.play()
while pygame.mixer.music.get_busy() == True:
continue
def voice_action(*args):
print('push', args)
file = args[0].split("/")[-1]
testfile = urllib.URLopener()
testfile.retrieve(args[0],file)
play(file)
socketIO = SocketIO('intrasocket.herokuapp.com', 80, LoggingNamespace)
#socketIO = SocketIO('localhost', 3000, LoggingNamespace)
socketIO.on('connect', on_connect)
socketIO.on('disconnect', on_disconnect)
socketIO.on('reconnect', on_reconnect)
# Listen
socketIO.on('time', on_aaa_response)
socketIO.on('push', push_action)
socketIO.on('voice', voice_action)
socketIO.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment