lasp/scripts/lasp_record

60 lines
1.5 KiB
Plaintext
Raw Normal View History

#!/usr/bin/python3
import argparse
parser = argparse.ArgumentParser(
description='Acquire data and store a measurement file'
)
parser.add_argument('filename', type=str,
help='File name to record to.'
' Extension is automatically added.')
parser.add_argument('--duration', '-d', type=float,
help='The recording duration in [s]')
device_help = 'DAQ Device to record from'
parser.add_argument('--input-daq', '-i', help=device_help, type=str,
default='Default')
args = parser.parse_args()
2019-10-27 13:19:26 +00:00
from lasp.lasp_avstream import AvStream
from lasp.lasp_record import Recording
from lasp.device import DAQConfiguration, RtAudio
2019-10-27 13:19:26 +00:00
config = DAQConfiguration.loadConfigs()[args.input_daq]
2019-10-27 13:19:26 +00:00
print(config)
rtaudio = RtAudio()
count = rtaudio.getDeviceCount()
devices = [rtaudio.getDeviceInfo(i) for i in range(count)]
input_devices = {}
for device in devices:
if device.inputchannels >= 0:
input_devices[device.name] = device
try:
input_device = input_devices[config.input_device_name]
except KeyError:
raise RuntimeError(f'Input device {config.input_device_name} not available')
2019-10-27 13:19:26 +00:00
print(input_device)
stream = AvStream(rtaudio,
None, # No output device
input_device,
config)
rec = Recording(args.filename, stream, args.duration)
rec.start()
print('Stopping stream...')
stream.stop()
print('Stream stopped')
print('Closing stream...')
stream.close()
print('Stream closed')