services: move TTSService push_stop_frames to AsyncTTSService
This commit is contained in:
@@ -140,21 +140,15 @@ class TTSService(AIService):
|
|||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
aggregate_sentences: bool = True,
|
aggregate_sentences: bool = True,
|
||||||
# if True, subclass is responsible for pushing TextFrames and LLMFullResponseEndFrames
|
# if True, TTSService will push TextFrames and LLMFullResponseEndFrames,
|
||||||
|
# otherwise subclass must do it
|
||||||
push_text_frames: bool = True,
|
push_text_frames: bool = True,
|
||||||
# if True, TTSService will push TTSStoppedFrames, otherwise subclass must do it
|
# TTS output sample rate
|
||||||
push_stop_frames: bool = False,
|
|
||||||
# if push_stop_frames is True, wait for this idle period before pushing TTSStoppedFrame
|
|
||||||
stop_frame_timeout_s: float = 1.0,
|
|
||||||
sample_rate: int = 16000,
|
sample_rate: int = 16000,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self._aggregate_sentences: bool = aggregate_sentences
|
self._aggregate_sentences: bool = aggregate_sentences
|
||||||
self._push_text_frames: bool = push_text_frames
|
self._push_text_frames: bool = push_text_frames
|
||||||
self._push_stop_frames: bool = push_stop_frames
|
|
||||||
self._stop_frame_timeout_s: float = stop_frame_timeout_s
|
|
||||||
self._stop_frame_task: Optional[asyncio.Task] = None
|
|
||||||
self._stop_frame_queue: asyncio.Queue = asyncio.Queue()
|
|
||||||
self._current_sentence: str = ""
|
self._current_sentence: str = ""
|
||||||
self._sample_rate: int = sample_rate
|
self._sample_rate: int = sample_rate
|
||||||
|
|
||||||
@@ -199,7 +193,7 @@ class TTSService(AIService):
|
|||||||
if text:
|
if text:
|
||||||
await self._push_tts_frames(text)
|
await self._push_tts_frames(text)
|
||||||
|
|
||||||
async def _push_tts_frames(self, text: str, text_passthrough: bool = True):
|
async def _push_tts_frames(self, text: str):
|
||||||
text = text.strip()
|
text = text.strip()
|
||||||
if not text:
|
if not text:
|
||||||
return
|
return
|
||||||
@@ -239,6 +233,25 @@ class TTSService(AIService):
|
|||||||
else:
|
else:
|
||||||
await self.push_frame(frame, direction)
|
await self.push_frame(frame, direction)
|
||||||
|
|
||||||
|
|
||||||
|
class AsyncTTSService(TTSService):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
# if True, TTSService will push TTSStoppedFrames, otherwise subclass must do it
|
||||||
|
push_stop_frames: bool = False,
|
||||||
|
# if push_stop_frames is True, wait for this idle period before pushing TTSStoppedFrame
|
||||||
|
stop_frame_timeout_s: float = 1.0,
|
||||||
|
**kwargs):
|
||||||
|
super().__init__(sync=False, **kwargs)
|
||||||
|
self._push_stop_frames: bool = push_stop_frames
|
||||||
|
self._stop_frame_timeout_s: float = stop_frame_timeout_s
|
||||||
|
self._stop_frame_task: Optional[asyncio.Task] = None
|
||||||
|
self._stop_frame_queue: asyncio.Queue = asyncio.Queue()
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
async def flush_audio(self):
|
||||||
|
pass
|
||||||
|
|
||||||
async def start(self, frame: StartFrame):
|
async def start(self, frame: StartFrame):
|
||||||
await super().start(frame)
|
await super().start(frame)
|
||||||
if self._push_stop_frames:
|
if self._push_stop_frames:
|
||||||
@@ -287,15 +300,6 @@ class TTSService(AIService):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AsyncTTSService(TTSService):
|
|
||||||
def __init__(self, **kwargs):
|
|
||||||
super().__init__(**kwargs)
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def flush_audio(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class AsyncWordTTSService(AsyncTTSService):
|
class AsyncWordTTSService(AsyncTTSService):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user