From b9b0bcdcbd16be8dfde2c1c2462cea4e63198fb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Tue, 2 Jul 2024 10:11:35 -0700 Subject: [PATCH] services(azure): close the audio stream on exit --- src/pipecat/services/azure.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pipecat/services/azure.py b/src/pipecat/services/azure.py index 873934abb..013129d1d 100644 --- a/src/pipecat/services/azure.py +++ b/src/pipecat/services/azure.py @@ -19,12 +19,11 @@ from pipecat.frames.frames import ( ErrorFrame, Frame, StartFrame, - StartInterruptionFrame, SystemFrame, TranscriptionFrame, URLImageRawFrame) from pipecat.processors.frame_processor import FrameDirection -from pipecat.services.ai_services import AIService, AsyncAIService, TTSService, ImageGenService +from pipecat.services.ai_services import AsyncAIService, TTSService, ImageGenService from pipecat.services.openai import BaseOpenAILLMService from loguru import logger @@ -83,7 +82,7 @@ class AzureTTSService(TTSService): return True async def run_tts(self, text: str) -> AsyncGenerator[Frame, None]: - logger.debug(f"Generating TTS: {text}") + logger.debug(f"Generating TTS: [{text}]") await self.start_ttfb_metrics() @@ -148,9 +147,11 @@ class AzureSTTService(AsyncAIService): async def stop(self, frame: EndFrame): self._speech_recognizer.stop_continuous_recognition_async() + self._audio_stream.close() async def cancel(self, frame: CancelFrame): self._speech_recognizer.stop_continuous_recognition_async() + self._audio_stream.close() def _on_handle_recognized(self, event): if event.result.reason == ResultReason.RecognizedSpeech and len(event.result.text) > 0: