Fixed ultravox service bugs (#1420)

This commit is contained in:
milo157
2025-03-21 03:55:43 +02:00
committed by GitHub
parent 09c62d939a
commit 3b4d91e1c1
3 changed files with 27 additions and 18 deletions

View File

@@ -14,6 +14,7 @@ from loguru import logger
from runner import configure from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
from pipecat.audio.vad.vad_analyzer import VADParams
from pipecat.pipeline.pipeline import Pipeline from pipecat.pipeline.pipeline import Pipeline
from pipecat.pipeline.runner import PipelineRunner from pipecat.pipeline.runner import PipelineRunner
from pipecat.pipeline.task import PipelineParams, PipelineTask from pipecat.pipeline.task import PipelineParams, PipelineTask

View File

@@ -17,6 +17,13 @@ from loguru import logger
from pipecat.frames.frames import ( from pipecat.frames.frames import (
AudioRawFrame, AudioRawFrame,
LLMFullResponseEndFrame,
LLMFullResponseStartFrame,
LLMTextFrame,
TranscriptionFrame,
TextFrame,
StartFrame,
EndFrame,
CancelFrame, CancelFrame,
EndFrame, EndFrame,
ErrorFrame, ErrorFrame,
@@ -339,6 +346,12 @@ class UltravoxSTTService(AIService):
# Concatenate audio frames - all should be int16 now # Concatenate audio frames - all should be int16 now
audio_data = np.concatenate(audio_arrays) audio_data = np.concatenate(audio_arrays)
audio_int16 = audio_data # Already in int16 format
# Save int16 audio
# Convert int16 to float32 and normalize for model input
audio_float32 = audio_int16.astype(np.float32) / 32768.0
# Generate text using the model # Generate text using the model
if self._model: if self._model:
try: try:
@@ -349,11 +362,11 @@ class UltravoxSTTService(AIService):
await self.start_ttfb_metrics() await self.start_ttfb_metrics()
await self.start_processing_metrics() await self.start_processing_metrics()
async for response in self._model.generate( async for response in self.model.generate(
messages=[{"role": "user", "content": "<|audio|>\n"}], messages=[{"role": "user", "content": "<|audio|>\n"}],
temperature=self._temperature, temperature=self.temperature,
max_tokens=self._max_tokens, max_tokens=self.max_tokens,
audio=audio_data, audio=audio_float32,
): ):
# Stop TTFB metrics after first response # Stop TTFB metrics after first response
await self.stop_ttfb_metrics() await self.stop_ttfb_metrics()
@@ -369,18 +382,13 @@ class UltravoxSTTService(AIService):
await self.stop_processing_metrics() await self.stop_processing_metrics()
logger.info(f"Generated text: {full_response}") logger.info(f"Generated text: {full_response}")
# Create a transcription frame with the generated text # Create a transcription frame with the generated text
transcription = full_response.strip() yield LLMFullResponseStartFrame()
if transcription:
yield TranscriptionFrame( text_frame = LLMTextFrame(text=full_response.strip())
user_id="", yield text_frame
text=transcription,
timestamp=time_now_iso8601(), yield LLMFullResponseEndFrame()
)
else:
logger.warning("Empty transcription result")
yield ErrorFrame("Empty transcription result")
except Exception as e: except Exception as e:
logger.error(f"Error generating text from model: {e}") logger.error(f"Error generating text from model: {e}")

View File

@@ -86,9 +86,9 @@ class TestUserIdleProcessor(unittest.IsolatedAsyncioTestCase):
expected_down_frames=expected_down_frames, expected_down_frames=expected_down_frames,
) )
assert not callback_called.is_set(), ( assert (
"Idle callback was called even though bot speaking frames reset the timer" not callback_called.is_set()
) ), "Idle callback was called even though bot speaking frames reset the timer"
async def test_idle_retry_callback(self): async def test_idle_retry_callback(self):
"""Test that retry count increases until user activity resets it.""" """Test that retry count increases until user activity resets it."""