From 19023018630ede9aa2c9898aa8502274f932a2a2 Mon Sep 17 00:00:00 2001 From: Ajay Raj Date: Sat, 25 Feb 2023 21:15:10 -0800 Subject: [PATCH] put api key in __init__.py --- simple_conversation.py | 1 - vocode/__init__.py | 6 ++++++ vocode/conversation.py | 5 ++--- 3 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 vocode/__init__.py diff --git a/simple_conversation.py b/simple_conversation.py index 3bab478..7da9e09 100644 --- a/simple_conversation.py +++ b/simple_conversation.py @@ -16,7 +16,6 @@ if __name__ == "__main__": microphone_input, speaker_output = create_microphone_input_and_speaker_output(use_first_available_device=True) conversation = Conversation( - key=os.environ.get("VOCODE_API_KEY"), input_device=microphone_input, output_device=speaker_output, transcriber_config=DeepgramTranscriberConfig.from_input_device(microphone_input), diff --git a/vocode/__init__.py b/vocode/__init__.py new file mode 100644 index 0000000..f726bd5 --- /dev/null +++ b/vocode/__init__.py @@ -0,0 +1,6 @@ +import os +from dotenv import load_dotenv + +load_dotenv() + +api_key = os.getenv("VOCODE_API_KEY") \ No newline at end of file diff --git a/vocode/conversation.py b/vocode/conversation.py index 558171f..856da4c 100644 --- a/vocode/conversation.py +++ b/vocode/conversation.py @@ -12,6 +12,7 @@ from .models.transcriber import TranscriberConfig from .models.agent import AgentConfig from .models.synthesizer import SynthesizerConfig from .models.websocket import ReadyMessage, AudioMessage, StartMessage, StopMessage +from . import api_key VOCODE_WEBSOCKET_URL = f'wss://api.vocode.dev/conversation' @@ -19,14 +20,12 @@ class Conversation: def __init__( self, - key: str, input_device: BaseInputDevice, output_device: BaseOutputDevice, transcriber_config: TranscriberConfig, agent_config: AgentConfig, synthesizer_config: SynthesizerConfig ): - self.key = key self.input_device = input_device self.output_device = output_device self.transcriber_config = transcriber_config @@ -45,7 +44,7 @@ class Conversation: self.active = False async def start(self): - async with websockets.connect(f"{VOCODE_WEBSOCKET_URL}?key={self.key}") as ws: + async with websockets.connect(f"{VOCODE_WEBSOCKET_URL}?key={api_key}") as ws: async def sender(ws): start_message = StartMessage( transcriber_config=self.transcriber_config,