jdxi_editor.midi.utils.usb_recorder

USBRecorder

Records an input with sounddevice and writes a 16-bit WAV. sounddevice’s wheels carry PortAudio, so this does not use PyAudio.

Attributes

SAMPLE_WIDTH

Classes

_PcmStream

A sounddevice input whose read returns PCM bytes.

USBRecorder

A convenient class for recording audio from a USB input device.

Functions

_sounddevice()

The sounddevice module, or None when it did not import.

_query_devices()

sounddevice's device list, or None when it cannot be queried.

_query_hostapis() → list

sounddevice's host APIs, or [].

Module Contents

jdxi_editor.midi.utils.usb_recorder.SAMPLE_WIDTH = 2[source]
jdxi_editor.midi.utils.usb_recorder._sounddevice()[source]

The sounddevice module, or None when it did not import.

jdxi_editor.midi.utils.usb_recorder._query_devices()[source]

sounddevice’s device list, or None when it cannot be queried.

jdxi_editor.midi.utils.usb_recorder._query_hostapis() → list[source]

sounddevice’s host APIs, or [].

Windows lists one device once per host API under an identical name, so the API is what tells those entries apart. An empty list is tolerated: the labelling falls back to the position.

Returns:

list

class jdxi_editor.midi.utils.usb_recorder._PcmStream(stream)[source]

A sounddevice input whose read returns PCM bytes.

_stream[source]
_hold[source]
read(frames: int) → bytes[source]
stop_stream() → None[source]
close() → None[source]
class jdxi_editor.midi.utils.usb_recorder.USBRecorder(input_device_index: int = None, channels: int = 2, rate: int = 44100, frames_per_buffer: int = 1024)[source]

A convenient class for recording audio from a USB input device.

input_device_index = None[source]
channels = 2[source]
rate = 44100[source]
frames_per_buffer = 1024[source]
file_save_recording: bool = False[source]
usb_port_input_device_index = None[source]
sample_width = 2[source]
usb_recording_rates[source]
list_devices()[source]

Logs every PortAudio entry, and returns the lines.

This one is for diagnosing a report, not for choosing from, so it keeps the position and names the host API: the same device appears once per API on Windows, and which one was picked matters.

list_input_devices() → List[Tuple[str, int]][source]

Input-capable devices as (display label, PortAudio index).

Output-only entries are omitted so the UI cannot pick a device that cannot capture (a common cause of silent WAVs).

The label is the device’s name, told apart by host API when Windows lists it more than once, and the input-channel count. It used to lead with the PortAudio index, which was the only thing distinguishing three identical Windows entries and meant nothing to anyone reading the menu; the index is still what is selected with, in the combo’s item data.

input_info(index: int) → dict[source]

Name, input-channel count and default sample rate of device index.

Parameters:

index – int sounddevice device index

Returns:

dict

open_input() → _PcmStream[source]

Open the selected input as 16-bit PCM.

Tries stereo first when the device reports at least two inputs, then falls back to mono — matching InputDeviceSource in the Audio Monitor.

Returns:

_PcmStream

record(duration, output_file, rate='16bit')[source]

Records audio for the specified duration and saves to a .wav file.

close()[source]

Nothing to shut down; sounddevice keeps no session object.

stop_recording()[source]

stop_recording

Returns:

None