From 09e4044c72ee6c9b798b81b6317fb562bb440639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Fri, 5 Apr 2024 13:34:01 -0700 Subject: [PATCH] transports: fix local transport read_audio_frames --- src/dailyai/transports/local_transport.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/dailyai/transports/local_transport.py b/src/dailyai/transports/local_transport.py index cf66345b2..abfc8dc5e 100644 --- a/src/dailyai/transports/local_transport.py +++ b/src/dailyai/transports/local_transport.py @@ -19,6 +19,7 @@ def __init__(self, **kwargs): self._sample_width = kwargs.get("sample_width") or 2 self._n_channels = kwargs.get("n_channels") or 1 self._tk_root = kwargs.get("tk_root") or None + self._pyaudio = None if self._camera_enabled and not self._tk_root: raise ValueError( @@ -51,7 +52,7 @@ def write_frame_to_mic(self, frame: bytes): if self._mic_enabled: self._audio_stream.write(frame) - def read_frames(self, desired_frame_count): + def read_audio_frames(self, desired_frame_count): bytes = b"" if self._speaker_enabled: bytes = self._speaker_stream.read( @@ -62,7 +63,8 @@ def read_frames(self, desired_frame_count): def _prerun(self): if self._mic_enabled: - self._pyaudio = pyaudio.PyAudio() + if not self._pyaudio: + self._pyaudio = pyaudio.PyAudio() self._audio_stream = self._pyaudio.open( format=self._pyaudio.get_format_from_width(self._sample_width), channels=self._n_channels, @@ -84,6 +86,8 @@ def _prerun(self): self._image_label.pack() if self._speaker_enabled: + if not self._pyaudio: + self._pyaudio = pyaudio.PyAudio() self._speaker_stream = self._pyaudio.open( format=self._pyaudio.get_format_from_width(self._sample_width), channels=self._n_channels,