Skip to content

Commit ef56542

Browse files
committed
clean up input stream creation
1 parent 72f546f commit ef56542

File tree

2 files changed

+10
-30
lines changed

2 files changed

+10
-30
lines changed

livekit-rtc/livekit/rtc/audio_mixer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ async def _mixer(self) -> None:
169169
await self._queue.put(None)
170170

171171
async def _get_contribution(
172-
self, stream: AsyncIterator[AudioFrame], buf: np.ndarray
172+
self, stream: AsyncIterator[AudioFrame | AudioFrameEvent], buf: np.ndarray
173173
) -> _Contribution:
174174
had_data = buf.shape[0] > 0
175175
exhausted = False

livekit-rtc/livekit/rtc/media_devices.py

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -403,35 +403,15 @@ def _input_callback(
403403
channels_arg = 1
404404
mapping = [int(input_channel_index) + 1]
405405

406-
# Build kwargs and conditionally include 'mapping' based on sounddevice version
407-
stream_kwargs: dict[str, Any] = {
408-
"callback": _input_callback,
409-
"dtype": "int16",
410-
"channels": channels_arg,
411-
"device": input_device,
412-
"samplerate": self._in_sr,
413-
"blocksize": self._blocksize,
414-
}
415-
try:
416-
init_params = inspect.signature(sd.InputStream.__init__).parameters
417-
if "mapping" in init_params and mapping is not None:
418-
stream_kwargs["mapping"] = mapping
419-
elif mapping is not None:
420-
logging.getLogger(__name__).warning(
421-
"sounddevice.InputStream does not support 'mapping' in this version; "
422-
"ignoring input_channel_index=%s",
423-
input_channel_index,
424-
)
425-
except Exception:
426-
# If inspection fails for any reason, fall back without mapping
427-
if mapping is not None:
428-
logging.getLogger(__name__).warning(
429-
"Unable to inspect sounddevice.InputStream.__init__; "
430-
"ignoring input_channel_index=%s",
431-
input_channel_index,
432-
)
433-
434-
input_stream = sd.InputStream(**stream_kwargs)
406+
input_stream = sd.InputStream(
407+
callback=_input_callback,
408+
dtype="int16",
409+
channels=channels_arg,
410+
device=input_device,
411+
samplerate=self._in_sr,
412+
blocksize=self._blocksize,
413+
mapping=mapping,
414+
)
435415
input_stream.start()
436416

437417
async def _pump() -> None:

0 commit comments

Comments
 (0)