fix: fixing issue with microphone channels numbering and status recovery on stop_recording
This commit is contained in:
parent
cb1a625617
commit
5267829b5a
lerobot/common/robot_devices/microphones
|
@ -207,7 +207,7 @@ class Microphone:
|
|||
else:
|
||||
self.sample_rate = int(actual_microphone["default_samplerate"])
|
||||
|
||||
if self.channels is not None:
|
||||
if self.channels is not None and len(self.channels) > 0:
|
||||
if any(c > actual_microphone["max_input_channels"] for c in self.channels):
|
||||
raise OSError(
|
||||
f"Some of the provided channels {self.channels} are outside the maximum channel range of the microphone {actual_microphone['max_input_channels']}."
|
||||
|
@ -216,13 +216,13 @@ class Microphone:
|
|||
self.channels = np.arange(1, actual_microphone["max_input_channels"] + 1)
|
||||
|
||||
# Get channels index instead of number for slicing
|
||||
self.channels = np.array(self.channels) - 1
|
||||
self.channels_index = np.array(self.channels) - 1
|
||||
|
||||
# Create the audio stream
|
||||
self.stream = sd.InputStream(
|
||||
device=self.microphone_index,
|
||||
samplerate=self.sample_rate,
|
||||
channels=max(self.channels) + 1,
|
||||
channels=max(self.channels),
|
||||
dtype="float32",
|
||||
callback=self._audio_callback,
|
||||
)
|
||||
|
@ -240,8 +240,8 @@ class Microphone:
|
|||
# Slicing makes copy unnecessary
|
||||
# Two separate queues are necessary because .get() also pops the data from the queue
|
||||
if self.is_writing:
|
||||
self.record_queue.put(indata[:, self.channels])
|
||||
self.read_queue.put(indata[:, self.channels])
|
||||
self.record_queue.put(indata[:, self.channels_index])
|
||||
self.read_queue.put(indata[:, self.channels_index])
|
||||
|
||||
@staticmethod
|
||||
def _record_loop(queue, event: Event, sample_rate: int, channels: list[int], output_file: Path) -> None:
|
||||
|
@ -253,7 +253,7 @@ class Microphone:
|
|||
output_file,
|
||||
mode="x",
|
||||
samplerate=sample_rate,
|
||||
channels=max(channels) + 1,
|
||||
channels=max(channels),
|
||||
subtype=sf.default_subtype(output_file.suffix[1:]),
|
||||
) as file:
|
||||
while not event.is_set():
|
||||
|
|
Loading…
Reference in New Issue