From e7548f9494cc8cd0ab27eba8dae53bb3c9f3af36 Mon Sep 17 00:00:00 2001 From: Mark Backman Date: Fri, 27 Sep 2024 08:02:44 -0400 Subject: [PATCH] Code review feedback --- src/pipecat/services/google.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/pipecat/services/google.py b/src/pipecat/services/google.py index 2a0a7d1e1..38af3e41f 100644 --- a/src/pipecat/services/google.py +++ b/src/pipecat/services/google.py @@ -8,11 +8,11 @@ import asyncio import json from typing import AsyncGenerator, List, Literal, Optional -import numpy as np from loguru import logger from pydantic import BaseModel from pipecat.frames.frames import ( + ErrorFrame, Frame, LLMFullResponseEndFrame, LLMFullResponseStartFrame, @@ -307,24 +307,13 @@ class GoogleTTSService(TTSService): await self.push_frame(TTSStartedFrame()) - # The audio produced by the TTS service has an audible click or pop at the beginning. - # This is due to the abrupt start of the audio waveform. To mitigate this, we apply a - # short fade-in effect to the audio data. - - # Convert the response to a mutable numpy array - audio_content = np.frombuffer(response.audio_content, dtype=np.int16).copy() - - # Apply a smooth, short fade-in - fade_duration = int(0.01 * self.sample_rate) # 10ms fade-in - fade_in = np.square( - np.linspace(0, 1, fade_duration) - ) # Quadratic fade for smoother start - audio_content[:fade_duration] = audio_content[:fade_duration] * fade_in + # Skip the first 44 bytes to remove the WAV header + audio_content = response.audio_content[44:] # Read and yield audio data in chunks chunk_size = 8192 for i in range(0, len(audio_content), chunk_size): - chunk = audio_content[i : i + chunk_size].tobytes() + chunk = audio_content[i : i + chunk_size] if not chunk: break await self.stop_ttfb_metrics() @@ -336,3 +325,7 @@ class GoogleTTSService(TTSService): except Exception as e: logger.exception(f"{self} error generating TTS: {e}") + error_message = f"TTS generation error: {str(e)}" + yield ErrorFrame(error=error_message) + finally: + await self.push_frame(TTSStoppedFrame())