services(stt): allow STT service to passthrough audio

This commit is contained in:
Aleix Conchillo Flaqué
2024-10-17 15:34:14 -07:00
parent 71c8c0dcdb
commit 12eb9437c1
2 changed files with 9 additions and 2 deletions

View File

@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Added `audio_passthrough` parameter to `STTService`. If enabled it allows
audio frames to be pushed downstream in case other processors need them.
- Added input parameter options for `PlayHTTTSService` and
`PlayHTHttpTTSService`.

View File

@@ -451,8 +451,9 @@ class WordTTSService(TTSService):
class STTService(AIService):
"""STTService is a base class for speech-to-text services."""
def __init__(self, **kwargs):
def __init__(self, audio_passthrough=False, **kwargs):
super().__init__(**kwargs)
self._audio_passthrough = audio_passthrough
self._settings: Dict[str, Any] = {}
@abstractmethod
@@ -490,8 +491,11 @@ class STTService(AIService):
if isinstance(frame, AudioRawFrame):
# In this service we accumulate audio internally and at the end we
# push a TextFrame. We don't really want to push audio frames down.
# push a TextFrame. We also push audio downstream in case someone
# else needs it.
await self.process_audio_frame(frame)
if self._audio_passthrough:
await self.push_frame(frame, direction)
elif isinstance(frame, STTUpdateSettingsFrame):
await self._update_settings(frame.settings)
else: