50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
|
|
class BaseMediaTransport(ABC):
|
|
def __init__(
|
|
self,
|
|
*,
|
|
transport_id: str,
|
|
sample_rate_hz: int = 8000,
|
|
frame_duration_ms: int = 20,
|
|
) -> None:
|
|
self._transport_id = transport_id
|
|
self._sample_rate_hz = sample_rate_hz
|
|
self._frame_duration_ms = frame_duration_ms
|
|
|
|
@property
|
|
def transport_id(self) -> str:
|
|
return self._transport_id
|
|
|
|
@property
|
|
def sample_rate_hz(self) -> int:
|
|
return self._sample_rate_hz
|
|
|
|
@property
|
|
def frame_duration_ms(self) -> int:
|
|
return self._frame_duration_ms
|
|
|
|
@property
|
|
def frame_bytes(self) -> int:
|
|
return int((self.sample_rate_hz * self.frame_duration_ms / 1000.0) * 2)
|
|
|
|
@property
|
|
@abstractmethod
|
|
def protocol(self) -> str:
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def receive_audio(self) -> bytes | None:
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def send_audio(self, audio_chunk: bytes) -> None:
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def close(self) -> None:
|
|
raise NotImplementedError
|