Merge pull request #102 from daily-co/examples-cleanup

examples cleanup
This commit is contained in:
Aleix Conchillo Flaqué
2024-04-05 08:02:57 +08:00
committed by GitHub
13 changed files with 59 additions and 87 deletions

View File

@@ -4,9 +4,6 @@ import io
import os
from PIL import Image
from dailyai.services.ai_services import ImageGenService
from dailyai.services.ai_services import ImageGenService
try:

View File

@@ -5,7 +5,6 @@ import signal
import threading
import types
from enum import Enum
from functools import partial
from typing import Any
@@ -120,8 +119,7 @@ class DailyTransport(ThreadedTransport, EventHandler):
raise e
def _webrtc_vad_analyze(self):
buffer = self.read_audio_frames(
int(self._vad_samples))
buffer = self.read_audio_frames(int(self._vad_samples))
if len(buffer) > 0:
confidence = self.webrtc_vad.analyze_frames(buffer)
# yeses = int(confidence * 20.0)

View File

@@ -48,13 +48,16 @@ class LocalTransport(ThreadedTransport):
)
def write_frame_to_mic(self, frame: bytes):
self._audio_stream.write(frame)
if self._mic_enabled:
self._audio_stream.write(frame)
def read_frames(self, desired_frame_count):
bytes = self._speaker_stream.read(
desired_frame_count,
exception_on_overflow=False,
)
bytes = b""
if self._speaker_enabled:
bytes = self._speaker_stream.read(
desired_frame_count,
exception_on_overflow=False,
)
return bytes
def _prerun(self):

View File

@@ -84,12 +84,13 @@ class ThreadedTransport(AbstractTransport):
except ModuleNotFoundError as e:
if self._has_webrtc_vad:
self._logger.debug(f"Couldn't load torch; using webrtc VAD")
self._logger.debug(
f"Couldn't load torch; using webrtc VAD")
self._vad_samples = int(self._speaker_sample_rate / 100.0)
else:
self._logger.error(f"Exception: {e}")
self._logger.error(
"In order to use VAD, you'll need to install the `torch` and `torchaudio` modules.")
"In order to use Silero VAD, you'll need to `pip install dailyai[silero].")
raise Exception(f"Missing module(s): {e}")
vad_frame_s = self._vad_samples / self._speaker_sample_rate
@@ -184,7 +185,6 @@ class ThreadedTransport(AbstractTransport):
pipeline.set_sink(self.send_queue)
source_queue = asyncio.Queue()
pipeline.set_source(source_queue)
pipeline.set_sink(self.send_queue)
pipeline_task = asyncio.create_task(pipeline.run_pipeline())
async def yield_frame(frame: Frame) -> AsyncGenerator[Frame, None]: