From 28b5587b73e5fdc27608d69295cc0f690d362229 Mon Sep 17 00:00:00 2001 From: Ajay Raj Date: Sat, 29 Jul 2023 20:38:47 -0700 Subject: [PATCH] change synthesizer factory api --- .../agent/restful_user_implemented_agent.py | 2 +- vocode/streaming/synthesizer/factory.py | 34 ++++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/vocode/streaming/agent/restful_user_implemented_agent.py b/vocode/streaming/agent/restful_user_implemented_agent.py index 212b8c919..126087dd0 100644 --- a/vocode/streaming/agent/restful_user_implemented_agent.py +++ b/vocode/streaming/agent/restful_user_implemented_agent.py @@ -33,7 +33,7 @@ async def respond( ) -> Tuple[Optional[str], bool]: config = self.agent_config.respond try: - # todo: cache session + # TODO: cache session async with aiohttp.ClientSession() as session: payload = RESTfulAgentInput( human_input=human_input, conversation_id=conversation_id diff --git a/vocode/streaming/synthesizer/factory.py b/vocode/streaming/synthesizer/factory.py index 729bb3e67..3c19c40ed 100644 --- a/vocode/streaming/synthesizer/factory.py +++ b/vocode/streaming/synthesizer/factory.py @@ -1,6 +1,7 @@ import logging from typing import Optional import typing +import aiohttp from vocode.streaming.models.synthesizer import ( AzureSynthesizerConfig, @@ -31,22 +32,39 @@ def create_synthesizer( self, synthesizer_config: SynthesizerConfig, logger: Optional[logging.Logger] = None, + aiohttp_session: Optional[aiohttp.ClientSession] = None, ): if isinstance(synthesizer_config, GoogleSynthesizerConfig): - return GoogleSynthesizer(synthesizer_config, logger=logger) + return GoogleSynthesizer( + synthesizer_config, logger=logger, aiohttp_session=aiohttp_session + ) elif isinstance(synthesizer_config, AzureSynthesizerConfig): - return AzureSynthesizer(synthesizer_config, logger=logger) + return AzureSynthesizer( + synthesizer_config, logger=logger, aiohttp_session=aiohttp_session + ) elif isinstance(synthesizer_config, ElevenLabsSynthesizerConfig): - return ElevenLabsSynthesizer(synthesizer_config, logger=logger) + return ElevenLabsSynthesizer( + synthesizer_config, logger=logger, aiohttp_session=aiohttp_session + ) elif isinstance(synthesizer_config, PlayHtSynthesizerConfig): - return PlayHtSynthesizer(synthesizer_config, logger=logger) + return PlayHtSynthesizer( + synthesizer_config, logger=logger, aiohttp_session=aiohttp_session + ) elif isinstance(synthesizer_config, RimeSynthesizerConfig): - return RimeSynthesizer(synthesizer_config, logger=logger) + return RimeSynthesizer( + synthesizer_config, logger=logger, aiohttp_session=aiohttp_session + ) elif isinstance(synthesizer_config, GTTSSynthesizerConfig): - return GTTSSynthesizer(synthesizer_config, logger=logger) + return GTTSSynthesizer( + synthesizer_config, logger=logger, aiohttp_session=aiohttp_session + ) elif isinstance(synthesizer_config, StreamElementsSynthesizerConfig): - return StreamElementsSynthesizer(synthesizer_config, logger=logger) + return StreamElementsSynthesizer( + synthesizer_config, logger=logger, aiohttp_session=aiohttp_session + ) elif isinstance(synthesizer_config, CoquiTTSSynthesizerConfig): - return CoquiTTSSynthesizer(synthesizer_config, logger=logger) + return CoquiTTSSynthesizer( + synthesizer_config, logger=logger, aiohttp_session=aiohttp_session + ) else: raise Exception("Invalid synthesizer config")