Merge pull request #3555 from pipecat-ai/mb/speechmatics-stt-ttfb
Align Speechmatics STT TTFB metrics with STT classes
This commit is contained in:
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
import time
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, AsyncGenerator
|
from typing import Any, AsyncGenerator
|
||||||
|
|
||||||
@@ -598,9 +597,6 @@ class SpeechmaticsSTTService(STTService):
|
|||||||
if segments:
|
if segments:
|
||||||
await self._send_frames(segments)
|
await self._send_frames(segments)
|
||||||
|
|
||||||
# Update metrics
|
|
||||||
await self._emit_metrics(message.get("metadata", {}).get("processing_time", 0.0))
|
|
||||||
|
|
||||||
async def _handle_segment(self, message: dict[str, Any]) -> None:
|
async def _handle_segment(self, message: dict[str, Any]) -> None:
|
||||||
"""Handle AddSegment events.
|
"""Handle AddSegment events.
|
||||||
|
|
||||||
@@ -804,28 +800,6 @@ class SpeechmaticsSTTService(STTService):
|
|||||||
yield ErrorFrame(f"Speechmatics error: {e}")
|
yield ErrorFrame(f"Speechmatics error: {e}")
|
||||||
await self._disconnect()
|
await self._disconnect()
|
||||||
|
|
||||||
async def _emit_metrics(self, processing_time: float) -> None:
|
|
||||||
"""Create TTFB metrics.
|
|
||||||
|
|
||||||
The TTFB is the seconds between the person speaking and the STT
|
|
||||||
engine emitting the first partial. This is only calculated at the
|
|
||||||
start of an utterance.
|
|
||||||
"""
|
|
||||||
# Skip if metrics not available
|
|
||||||
if not self._metrics or processing_time == 0.0:
|
|
||||||
return
|
|
||||||
|
|
||||||
# Calculate time as time.time() - ttfb (which is seconds)
|
|
||||||
start_time = time.time() - processing_time
|
|
||||||
|
|
||||||
# Update internal metrics
|
|
||||||
self._metrics._start_ttfb_time = start_time
|
|
||||||
self._metrics._start_processing_time = start_time
|
|
||||||
|
|
||||||
# Stop TTFB metrics
|
|
||||||
await self.stop_ttfb_metrics()
|
|
||||||
await self.stop_processing_metrics()
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# HELPERS
|
# HELPERS
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user