lasp/scripts/lasp_record

79 lines
1.7 KiB
Python
Executable File

#!/usr/bin/python3
import argparse
import sys
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()
from lasp.lasp_avstream import AvStream, AvType
from lasp.lasp_record import Recording
from lasp.device import DAQConfiguration, RtAudio, UlDaq
configs = DAQConfiguration.loadConfigs()
for i, (key, val) in enumerate(configs.items()):
print(f'{i:2} : {key}')
daqindex = input('Please enter required config: ')
try:
daqindex = int(daqindex)
except:
sys.exit(0)
for i, (key, val) in enumerate(configs.items()):
if i == daqindex:
config = configs[key]
config = configs[key]
print(config)
# daq = RtAudio()
daq = UlDaq()
devices = daq.getDeviceInfo()
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')
print(input_device)
stream = AvStream(input_device,
AvType.audio_input,
config)
rec = Recording(args.filename, stream, args.duration)
stream.start()
with rec:
pass
print('Stopping stream...')
stream.stop()
print('Stream stopped')
print('Closing stream...')
print('Stream closed')