示例#1
0
def main():
    if __name__ == "__main__":
        #GPIO part
        GPIO.init(radio_on_cb=radio_cor_on_callback,radio_off_cb=radio_cor_off_callback)

        #Audio part
        global audio
        player = config_get_audio_player() #Could be None/aplay/sox
        audio = Audio(player=player,record_callback=recorder_callback)
        audio.open()

        global WS_DEBUG, ws
        if WS_DEBUG:
            websocket.enableTrace(True)
        else:
            websocket.enableTrace(False)
        callsign = config_get_callsign()
        print "CALLSIGN: %s" % callsign
        url = "ws://aprs.hamclub.net:20880/mtracker/talkbox0?type=sub&udid=" + callsign
        ws = websocket.WebSocketApp(url,
        #ws = websocket.WebSocketApp("ws://localhost:8080/mclub/talk0?type=sub&udid=bg5hxe",
                                   #on_message = ws_on_message,
                                    on_data = ws_on_data,
                                    on_error = ws_on_error,
                                    on_close = ws_on_close)
        ws.on_open = ws_on_open

        stopFlag = Event()
        timer = KeepAliveThread(stopFlag,ws)
        timer.start()

        ws.run_forever()
        stopFlag.set() #stop the timer

        audio.close()
        GPIO.cleanup()
import sys
import wave

if len(sys.argv) < 2:
    print "Usage: %s file_name player_type" % (sys.argv[0])
    sys.exit()

wf = wave.open(sys.argv[1], 'rb')

a = None
if len(sys.argv) >= 3:
    a = Audio(player=sys.argv[2])
else:
    a = Audio(player=None)

a.open()

chunk = 640
data = wf.readframes(chunk)
# play stream (looping from beginning of file to the end)
while data != '':
    # writing to the stream is what *actually* plays the sound.
    a.play(data)
    data = wf.readframes(chunk)

print "Play done."
i = 0
while True:
    time.sleep(0.1)
    i += 1
    if i > 50: