def main(block_name, input_device, output_device, block_size, sample_rate): # Initialise Chirp SDK sdk = ChirpSDK(block=block_name) print(str(sdk)) print('Protocol: {protocol} [v{version}]'.format( protocol=sdk.protocol_name, version=sdk.protocol_version)) print(sdk.audio.query_devices()) # Configure audio sdk.audio.input_device = input_device sdk.audio.output_device = output_device sdk.audio.block_size = block_size sdk.input_sample_rate = sample_rate sdk.output_sample_rate = sample_rate # Set callback functions sdk.set_callbacks(Callbacks()) # Generate random payload and send payload = sdk.random_payload() sdk.start(send=True, receive=True) sdk.send(payload) try: # Process audio streams while True: time.sleep(0.1) sys.stdout.write('.') sys.stdout.flush() except KeyboardInterrupt: print('Exiting') sdk.stop()
def main(block_name, input_device, output_device, block_size, sample_rate, filename): # Initialise ChirpSDK sdk = ChirpSDK(block=block_name) print(str(sdk)) print('Protocol: {protocol} [v{version}]'.format( protocol=sdk.protocol_name, version=sdk.protocol_version)) print(sdk.audio.query_devices()) # Configure audio sdk.audio.input_device = input_device sdk.audio.output_device = output_device sdk.audio.block_size = block_size sdk.input_sample_rate = sample_rate sdk.output_sample_rate = sample_rate # Set callback functions sdk.set_callbacks(Callbacks()) # Generate random payload and send payload = imgToHex(filename) parts = split_payload(payload) # Send payload sdk.start(send=True, receive=False) startmessage = codecs.encode(b'IMGBEG','hex-codec') endmessage = codecs.encode(b'IMGEND','hex-codec') print("\n\n#############") print("Total parts: {p}, ~{s} seconds".format( p=len(parts), s=len(parts)*5)) print("#############\n\n") sdk.send([1],blocking=True) sdk.send(startmessage, blocking=True) print(list(startmessage)) time.sleep(0.5) for part in parts: sdk.send(part, blocking=True) time.sleep(0.1) sdk.send(endmessage, blocking=True) time.sleep(1) print("Stopping...") sdk.stop()
def main(block_name, input_device, output_device, block_size, sample_rate, channel): # Initialise Chirp SDK sdk = ChirpSDK(block=block_name) print(str(sdk)) print('Protocol: {protocol} [v{version}]'.format( protocol=sdk.protocol_name, version=sdk.protocol_version)) print(sdk.audio.query_devices()) # Configure audio sdk.audio.input_device = input_device sdk.audio.output_device = output_device sdk.audio.block_size = block_size sdk.input_sample_rate = sample_rate sdk.output_sample_rate = sample_rate # Set callback functions sdk.set_callbacks(Callbacks()) # Set transmission channel for multichannel protocols if args.channel is not None: if args.channel >= sdk.channel_count: raise ValueError('Channel %d is not available' % args.channel) print('Writing to channel %d' % args.channel) sdk.transmission_channel = args.channel # Generate random payload and send payload = sdk.random_payload() sdk.start(send=True, receive=True) sdk.send(payload) try: # Process audio streams while True: time.sleep(0.1) sys.stdout.write('.') sys.stdout.flush() except KeyboardInterrupt: print('Exiting') sdk.stop()
def main(block_name, input_device, output_device, block_size, sample_rate): # Initialise ChirpSDK sdk = ChirpSDK(block=block_name) print(str(sdk)) print('Protocol: {protocol} [v{version}]'.format( protocol=sdk.protocol_name, version=sdk.protocol_version)) print(sdk.audio.query_devices()) # Configure audio sdk.audio.input_device = input_device sdk.audio.output_device = output_device sdk.audio.block_size = block_size sdk.input_sample_rate = sample_rate sdk.output_sample_rate = sample_rate # GLOBALS global IMG_PARTS global REC_IMG IMG_PARTS = [] REC_IMG = False # Set callback functions sdk.set_callbacks(Callbacks()) sdk.start(send=False, receive=True) try: # Process audio streams while True: time.sleep(0.1) except KeyboardInterrupt: print('Exiting') sdk.stop()
def main(block_name, input_device, output_device, block_size, sample_rate, channel): global payloadlength # Initialise Chirp SDK sdk = ChirpSDK(block=block_name) print(str(sdk)) print('Protocol: {protocol} [v{version}]'.format( protocol=sdk.protocol_name, version=sdk.protocol_version)) print(sdk.audio.query_devices()) # Configure audio sdk.audio.input_device = input_device sdk.audio.output_device = output_device sdk.audio.block_size = block_size sdk.input_sample_rate = sample_rate sdk.output_sample_rate = sample_rate # Set callback functions sdk.set_callbacks(Callbacks()) # Set transmission channel for multichannel protocols if args.channel is not None: if args.channel >= sdk.channel_count: raise ValueError('Channel %d is not available' % args.channel) # print('Writing to channel %d' % args.channel) sdk.transmission_channel = args.channel # Send a message # [we don't do random payload in this code] Generate random payload and send # payload = sdk.random_payload() # start from the user-supplied message in main args message = args.message.encode('utf-8') payload = sdk.new_payload(message) sdk.start(send=True, receive=True) sdk.send(payload) tom0 = 0 waittime = 0 try: # Process audio streams while True: tom = sdk.state if (tom == 2) & (tom0 == 4): # print('CHIRP RECEIVED') i = 0 # setup a new payload bytearray "pdata[]" pdata = bytearray(payloadlength) # print(payloadlength) for i in range(payloadlength): pdata[i] = rdata[i] msg = pdata.decode('utf-8') print('Received: {data}'.format(data=msg)) # print(msg) # code segment here to handle message response # first, send the received message to chat handler # and receive a response message response = eliza_chatbot.respond(msg) print('Response: {data}'.format(data=response)) # encode the response message newmsg = response.encode('utf-8') # load up the payload with the encoded message payload = sdk.new_payload(newmsg) # send the payload time.sleep(2) sdk.send(payload) # sdk.send(pdata) waittime = 0 time.sleep(0.1) # sys.stdout.write('.') sys.stdout.flush() tom0 = tom waittime += 1 # if no response for a long time (30 sec), ping if anyone is listening if waittime > 300: response = "Hello, anyone there?" print('Response: {data}'.format(data=response)) newmsg = response.encode('utf-8') payload = sdk.new_payload(newmsg) sdk.send(payload) waittime = 0 except KeyboardInterrupt: print('Exiting') sdk.stop()