Various code review tweaks.
This commit is contained in:
@@ -125,6 +125,8 @@ class GradiumSTTService(WebsocketSTTService):
|
|||||||
None (processing handled via WebSocket messages).
|
None (processing handled via WebSocket messages).
|
||||||
"""
|
"""
|
||||||
self._audio_buffer.extend(audio)
|
self._audio_buffer.extend(audio)
|
||||||
|
await self.start_ttfb_metrics()
|
||||||
|
await self.start_processing_metrics()
|
||||||
|
|
||||||
while len(self._audio_buffer) >= self._chunk_size_bytes:
|
while len(self._audio_buffer) >= self._chunk_size_bytes:
|
||||||
chunk = bytes(self._audio_buffer[: self._chunk_size_bytes])
|
chunk = bytes(self._audio_buffer[: self._chunk_size_bytes])
|
||||||
@@ -136,19 +138,6 @@ class GradiumSTTService(WebsocketSTTService):
|
|||||||
|
|
||||||
yield None
|
yield None
|
||||||
|
|
||||||
async def process_frame(self, frame: Frame, direction: FrameDirection):
|
|
||||||
"""Process frames for VAD and metrics handling.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
frame: Frame to process.
|
|
||||||
direction: Direction of frame processing.
|
|
||||||
"""
|
|
||||||
await super().process_frame(frame, direction)
|
|
||||||
if isinstance(frame, UserStartedSpeakingFrame):
|
|
||||||
await self.start_ttfb_metrics()
|
|
||||||
elif isinstance(frame, UserStoppedSpeakingFrame):
|
|
||||||
await self.start_processing_metrics()
|
|
||||||
|
|
||||||
@traced_stt
|
@traced_stt
|
||||||
async def _trace_transcription(self, transcript: str, is_final: bool, language: Language):
|
async def _trace_transcription(self, transcript: str, is_final: bool, language: Language):
|
||||||
"""Record transcription event for tracing."""
|
"""Record transcription event for tracing."""
|
||||||
|
|||||||
@@ -54,8 +54,7 @@ class GradiumTTSService(InterruptibleWordTTSService):
|
|||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
api_key: str,
|
api_key: str,
|
||||||
voice: Optional[str] = None,
|
voice_id: str = "YTpq7expH9539ERJ",
|
||||||
voice_id: Optional[str] = None,
|
|
||||||
url: str = "wss://eu.api.gradium.ai/api/speech/tts",
|
url: str = "wss://eu.api.gradium.ai/api/speech/tts",
|
||||||
model: str = "default",
|
model: str = "default",
|
||||||
json_config: Optional[str] = None,
|
json_config: Optional[str] = None,
|
||||||
@@ -64,13 +63,9 @@ class GradiumTTSService(InterruptibleWordTTSService):
|
|||||||
):
|
):
|
||||||
"""Initialize the Gradium TTS service.
|
"""Initialize the Gradium TTS service.
|
||||||
|
|
||||||
The voice used in the generation is specified by setting either the `voice` argument
|
|
||||||
for catalog voices or the `voice_id` argument for custom voices.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
api_key: Gradium API key for authentication.
|
api_key: Gradium API key for authentication.
|
||||||
voice: name for a catalog voice.
|
voice_id: the voice identifier.
|
||||||
voice_id: identifier for a custom voice.
|
|
||||||
url: Gradium websocket API endpoint.
|
url: Gradium websocket API endpoint.
|
||||||
model: Model ID to use for synthesis.
|
model: Model ID to use for synthesis.
|
||||||
json_config: Optional JSON configuration string for additional model settings.
|
json_config: Optional JSON configuration string for additional model settings.
|
||||||
@@ -85,22 +80,15 @@ class GradiumTTSService(InterruptibleWordTTSService):
|
|||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
if voice is None and voice_id is None:
|
|
||||||
raise ValueError("one of voice and voice_id has to be set")
|
|
||||||
if voice is not None and voice_id is not None:
|
|
||||||
raise ValueError("voice and voice_id cannot be set at the same time")
|
|
||||||
|
|
||||||
params = params or GradiumTTSService.InputParams()
|
params = params or GradiumTTSService.InputParams()
|
||||||
|
|
||||||
# Store service configuration
|
# Store service configuration
|
||||||
self._api_key = api_key
|
self._api_key = api_key
|
||||||
self._url = url
|
self._url = url
|
||||||
self._voice = voice
|
|
||||||
self._voice_id = voice_id
|
self._voice_id = voice_id
|
||||||
self._json_config = json_config
|
self._json_config = json_config
|
||||||
self._model = model
|
self._model = model
|
||||||
self._settings = {
|
self._settings = {
|
||||||
"voice": voice,
|
|
||||||
"voice_id": voice_id,
|
"voice_id": voice_id,
|
||||||
"model_name": model,
|
"model_name": model,
|
||||||
"output_format": "pcm",
|
"output_format": "pcm",
|
||||||
@@ -205,13 +193,10 @@ class GradiumTTSService(InterruptibleWordTTSService):
|
|||||||
setup_msg = {
|
setup_msg = {
|
||||||
"type": "setup",
|
"type": "setup",
|
||||||
"output_format": "pcm",
|
"output_format": "pcm",
|
||||||
|
"voice_id": self._voice_id,
|
||||||
}
|
}
|
||||||
if self._json_config is not None:
|
if self._json_config is not None:
|
||||||
setup_msg["json_config"] = self._json_config
|
setup_msg["json_config"] = self._json_config
|
||||||
if self._voice is not None:
|
|
||||||
setup_msg["voice"] = self._voice
|
|
||||||
if self._voice_id is not None:
|
|
||||||
setup_msg["voice_id"] = self._voice_id
|
|
||||||
await self._websocket.send(json.dumps(setup_msg))
|
await self._websocket.send(json.dumps(setup_msg))
|
||||||
ready_msg = await self._websocket.recv()
|
ready_msg = await self._websocket.recv()
|
||||||
ready_msg = json.loads(ready_msg)
|
ready_msg = json.loads(ready_msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user