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(block_name, input_device, output_device, block_size, sample_rate): # Initialise ConnectSDK sdk = ChirpConnect(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, string): # Initialise ConnectSDK sdk = ChirpConnect(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 = 44100 # Set callback functions sdk.set_callbacks(Callbacks()) # print("type your message") #msg = "" print(string) divideMsg8(string) #print(divMsg) # window = Tk() # messages = Text(window) # messages.pack() # # input_user = StringVar() # # input_field = Entry(window, text=input_user) # input_field.pack(side=BOTTOM, fill=X) # def Enter_pressed(event): # input_get = input_field.get() # global msg, divMsg # msg = input_get # divMsg = divideMsg8(string) # #print(input_get) # messages.insert(INSERT, '%s\n' % input_get) # # label = Label(window, text=input_get) # input_user.set('') # # label.pack() # return "break" # frame = Frame(window) # , width=300, height=300) # input_field.bind("<Return>", Enter_pressed) # frame.pack() # window.mainloop() #initialize SDK to SEND ONLY sdk.start(send=True, receive=True) timeLapse = 0 # numMsgSent = 0; try: # Process audio streams while True: if string != "xS$9!a6@": time.sleep(0.1) # sys.stdout.write('.') sys.stdout.flush() timeLapse += 1 if timeLapse % 50 == 0: timeLapse = 0 # if numMsgSent <= len(divMsg): if len(divMsg) > 0: # identifier = divMsg[numMsgSent] identifier = divMsg[0] payload = bytearray([ord(ch) for ch in identifier]) sdk.send(payload) divMsg.pop(0) # numMsgSent += 1 else: identifier = "@6a!9$Sx" payload = bytearray([ord(ch) for ch in identifier]) sdk.send(payload) time.sleep(5) break else: time.sleep(0.1) # sys.stdout.write('.') sys.stdout.flush() break except KeyboardInterrupt: print('Exiting') sdk.stop()