adds ability to pass in api key for every transcriber agent and synthesizer

This commit is contained in:
Ajay Raj 2023-03-28 23:33:36 -07:00
commit ecebe4c1a5
11 changed files with 71 additions and 17 deletions

View file

@ -52,14 +52,27 @@ class AzureSynthesizer(BaseSynthesizer):
OFFSET_MS = 100
def __init__(
self, synthesizer_config: AzureSynthesizerConfig, logger: logging.Logger = None
self,
synthesizer_config: AzureSynthesizerConfig,
logger: logging.Logger = None,
azure_speech_key: str = None,
azure_speech_region: str = None,
):
super().__init__(synthesizer_config)
self.synthesizer_config = synthesizer_config
# Instantiates a client
azure_speech_key = azure_speech_key or getenv("AZURE_SPEECH_KEY")
azure_speech_region = azure_speech_region or getenv("AZURE_SPEECH_REGION")
if not azure_speech_key:
raise ValueError(
"Please set AZURE_SPEECH_KEY environment variable or pass it as a parameter"
)
if not azure_speech_region:
raise ValueError(
"Please set AZURE_SPEECH_REGION environment variable or pass it as a parameter"
)
speech_config = speechsdk.SpeechConfig(
subscription=getenv("AZURE_SPEECH_KEY"),
region=getenv("AZURE_SPEECH_REGION"),
subscription=azure_speech_key, region=azure_speech_region
)
if self.synthesizer_config.audio_encoding == AudioEncoding.LINEAR16:
if self.synthesizer_config.sampling_rate == 44100:

View file

@ -24,7 +24,7 @@ ADAM_VOICE_ID = "pNInz6obpgDQGcFmaJgB"
class ElevenLabsSynthesizer(BaseSynthesizer):
def __init__(self, config: ElevenLabsSynthesizerConfig):
super().__init__(config)
self.api_key = getenv("ELEVEN_LABS_API_KEY")
self.api_key = config.api_key or getenv("ELEVEN_LABS_API_KEY")
self.voice_id = config.voice_id or ADAM_VOICE_ID
self.words_per_minute = 150

View file

@ -3,6 +3,7 @@ import wave
from typing import Any, Optional
from google.cloud import texttospeech_v1beta1 as tts
from vocode import getenv
from vocode.streaming.agent.bot_sentiment_analyser import BotSentiment
from vocode.streaming.models.message import BaseMessage
@ -22,6 +23,10 @@ class GoogleSynthesizer(BaseSynthesizer):
def __init__(self, synthesizer_config: GoogleSynthesizerConfig):
super().__init__(synthesizer_config)
# Instantiates a client
if not getenv("GOOGLE_APPLICATION_CREDENTIALS"):
raise Exception(
"GOOGLE_APPLICATION_CREDENTIALS environment variable must be set"
)
self.client = tts.TextToSpeechClient()
# Build the voice request, select the language code ("en-US") and the ssml