From 05844ce7dddf99553bf9b602ba1261348db67fdf Mon Sep 17 00:00:00 2001 From: Ajay Raj Date: Fri, 4 Aug 2023 13:39:41 -0700 Subject: [PATCH] creates aiohttp client session in task and tears it down in task --- playground/streaming/synthesizer/synthesize.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/playground/streaming/synthesizer/synthesize.py b/playground/streaming/synthesizer/synthesize.py index 71b593e8f..b299a9640 100644 --- a/playground/streaming/synthesizer/synthesize.py +++ b/playground/streaming/synthesizer/synthesize.py @@ -1,6 +1,7 @@ import time import argparse from typing import Optional +import aiohttp from vocode.streaming.agent.bot_sentiment_analyser import BotSentiment from vocode.streaming.models.message import BaseMessage from vocode.streaming.models.synthesizer import ( @@ -38,6 +39,8 @@ async def speak( synthesizer.get_synthesizer_config().audio_encoding, synthesizer.get_synthesizer_config().sampling_rate, ) + # ClientSession needs to be created within the async task + synthesizer.aiohttp_session = aiohttp.ClientSession() synthesis_result = await synthesizer.create_speech( message=message, chunk_size=chunk_size, @@ -88,6 +91,7 @@ async def main(): print("Message sent: ", message_sent) except KeyboardInterrupt: print("Interrupted, exiting") + await synthesizer.tear_down() speaker_output = SpeakerOutput.from_default_device()