Skip to content

Commit

Permalink
Merge pull request #105 from daily-co/local-tranport-read-audio-frames
Browse files Browse the repository at this point in the history
transports: fix local transport read_audio_frames
  • Loading branch information
aconchillo authored Apr 5, 2024
2 parents efdfb74 + 09e4044 commit 3022463
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/dailyai/transports/local_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 3022463

Please sign in to comment.