lasp/scripts/lasp_record

59 lines
1.4 KiB
Python
Executable File

#!/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()
from lasp.lasp_avstream import AvStream, AvType
from lasp.lasp_record import Recording
from lasp.device import DAQConfiguration, RtAudio
config = DAQConfiguration.loadConfigs()[args.input_daq]
print(config)
rtaudio = RtAudio()
devices = rtaudio.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)
with rec:
pass
print('Stopping stream...')
stream.stop()
print('Stream stopped')
print('Closing stream...')
stream.close()
print('Stream closed')