def main(args): # ------------------------------------------------------------------------ # Initialise the Connect SDK. # ------------------------------------------------------------------------ sdk = ChirpConnect() print(sdk.audio.query_devices()) print(str(sdk)) sdk.audio.output_device = args.o if args.network_config: sdk.set_config_from_network() if sdk.protocol_name != '16khz-mono': raise RuntimeError('Must use the 16khz-mono protocol ' + 'to be compatible with other Chirp Messenger apps.') # ------------------------------------------------------------------------ # Parse unicode and send as a chirp payload # ------------------------------------------------------------------------ message = args.message.encode('utf-8') payload = sdk.new_payload(message) sdk.volume = args.volume sdk.set_callbacks(Callbacks()) sdk.start() sdk.send(payload) try: # Process audio streams while True: time.sleep(0.1) except KeyboardInterrupt: print('Exiting') sdk.stop() sdk.close()
def main(args): # ------------------------------------------------------------------------ # Initialise the Connect SDK. # ------------------------------------------------------------------------ sdk = ChirpConnect() print(str(sdk)) if args.network_config: sdk.set_config_from_network() print('Protocol: {protocol} [v{version}]'.format( protocol=sdk.protocol_name, version=sdk.protocol_version)) # ------------------------------------------------------------------------ # Disable audio playback. # ------------------------------------------------------------------------ sdk.audio = None sdk.set_callbacks(Callbacks(args)) sdk.start(send=False, receive=True) w = wave.open(args.infile, 'r') data = w.readframes(w.getnframes()) sdk.input_sample_rate = w.getframerate() for f in range(0, len(data), CHIRP_SDK_BUFFER_SIZE): if w.getsampwidth() == 2: sdk.process_shorts_input(data[f: f + CHIRP_SDK_BUFFER_SIZE]) elif w.getsampwidth() == 4: sdk.process_input(data[f: f + CHIRP_SDK_BUFFER_SIZE]) sdk.stop()
def main(args): # ------------------------------------------------------------------------ # Initialise the Connect SDK. # ------------------------------------------------------------------------ sdk = ChirpConnect() print(str(sdk)) if args.network_config: sdk.set_config_from_network() print('Protocol: {protocol} [v{version}]'.format( protocol=sdk.protocol_name, version=sdk.protocol_version)) # ------------------------------------------------------------------------ # Disable audio playback. # ------------------------------------------------------------------------ sdk.audio = None sdk.start(send=True, receive=False) # ------------------------------------------------------------------------ # Encode payload # ------------------------------------------------------------------------ if args.unicode: message = args.unicode.encode('utf-8') payload = sdk.new_payload(message) elif args.hex: message = bytearray.fromhex(args.hex) payload = sdk.new_payload(message) else: payload = sdk.random_payload() # ------------------------------------------------------------------------ # Set transmission channel # ------------------------------------------------------------------------ if args.channel: if args.channel >= sdk.channel_count: raise ValueError('Channel %d is not available' % args.channel) sdk.transmission_channel = args.channel # ------------------------------------------------------------------------ # Process output # ------------------------------------------------------------------------ output_file = args.outfile if args.outfile else '%s.wav' % payload w = wave.open(output_file, 'w') w.setnchannels(1) w.setsampwidth(2) w.setframerate(sdk.output_sample_rate) sdk.send(payload) while sdk.state == CHIRP_CONNECT_STATE_SENDING: data = ar.array('h', [0] * CHIRP_SDK_BUFFER_SIZE) byte_data = bytearray(data.tobytes() if sys.version[0] == '3' else data.tostring()) sdk.process_shorts_output(byte_data) w.writeframes(byte_data) print('Wrote audio to output: %s' % output_file) w.close() sdk.stop()