Skip to content

Commit

Permalink
creates audio pipeline abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
ajar98 committed Jul 10, 2024
1 parent 2b1f4c4 commit 52aebe1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
9 changes: 5 additions & 4 deletions vocode/streaming/streaming_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from loguru import logger
from sentry_sdk.tracing import Span

from vocode import conversation_id as ctx_conversation_id
from vocode.streaming.action.worker import ActionsWorker
from vocode.streaming.agent.base_agent import (
AgentInput,
Expand Down Expand Up @@ -61,6 +62,7 @@
enumerate_async_iter,
get_chunk_size_per_second,
)
from vocode.streaming.utils.audio_pipeline import AudioPipeline, OutputDeviceType
from vocode.streaming.utils.create_task import asyncio_create_task
from vocode.streaming.utils.events_manager import EventsManager
from vocode.streaming.utils.speed_manager import SpeedManager
Expand Down Expand Up @@ -107,10 +109,7 @@
LOW_INTERRUPT_SENSITIVITY_BACKCHANNEL_UTTERANCE_LENGTH_THRESHOLD = 3


OutputDeviceType = TypeVar("OutputDeviceType", bound=AbstractOutputDevice)


class StreamingConversation(Generic[OutputDeviceType]):
class StreamingConversation(AudioPipeline[OutputDeviceType]):
class QueueingInterruptibleEventFactory(InterruptibleEventFactory):
def __init__(self, conversation: "StreamingConversation"):
self.conversation = conversation
Expand Down Expand Up @@ -593,6 +592,8 @@ def __init__(
events_manager: Optional[EventsManager] = None,
):
self.id = conversation_id or create_conversation_id()
ctx_conversation_id.set(self.id)

self.output_device = output_device
self.transcriber = transcriber
self.agent = agent
Expand Down
21 changes: 21 additions & 0 deletions vocode/streaming/utils/audio_pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from abc import abstractmethod
from typing import Generic, TypeVar

from vocode.streaming.output_device.abstract_output_device import AbstractOutputDevice
from vocode.streaming.utils.events_manager import EventsManager
from vocode.streaming.utils.worker import AbstractWorker

OutputDeviceType = TypeVar("OutputDeviceType", bound=AbstractOutputDevice)


class AudioPipeline(AbstractWorker[bytes], Generic[OutputDeviceType]):
output_device: OutputDeviceType
events_manager: EventsManager
id: str

def receive_audio(self, chunk: bytes):
self.consume_nonblocking(chunk)

@abstractmethod
def is_active(self):
raise NotImplementedError

0 comments on commit 52aebe1

Please sign in to comment.