Skip to content

Commit

Permalink
Flush the audio
Browse files Browse the repository at this point in the history
  • Loading branch information
markbackman committed Dec 21, 2024
1 parent dac4468 commit 627c91f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/pipecat/services/fish.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ async def _receive_messages(self):
msg = ormsgpack.unpackb(message)
if isinstance(msg, dict):
event = msg.get("event")
print(f"Received event: {event}")
if event == "audio":
await self.stop_ttfb_metrics()
audio_data = msg.get("audio")
Expand Down Expand Up @@ -220,12 +219,23 @@ async def run_tts(self, text: str) -> AsyncGenerator[Frame, None]:
yield TTSStartedFrame()
self._request_id = str(uuid.uuid4())

# Send the text
text_message = {
"event": "text",
"text": text,
}
await self._get_websocket().send(ormsgpack.packb(text_message))
await self.start_tts_usage_metrics(text)
try:
await self._get_websocket().send(ormsgpack.packb(text_message))
await self.start_tts_usage_metrics(text)

# Send flush event to force audio generation
flush_message = {"event": "flush"}
await self._get_websocket().send(ormsgpack.packb(flush_message))
except Exception as e:
logger.error(f"{self} error sending message: {e}")
yield TTSStoppedFrame()
await self._disconnect()
await self._connect()

yield None

Expand Down

0 comments on commit 627c91f

Please sign in to comment.