Пример #1
0
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()
Пример #2
0
def main(args):
    # ------------------------------------------------------------------------
    # Initialise the Chirp SDK.
    # ------------------------------------------------------------------------
    sdk = ChirpSDK()
    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_SDK_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()
Пример #3
0
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()