put api key in __init__.py

This commit is contained in:
Ajay Raj 2023-02-25 21:15:10 -08:00
commit 1902301863
3 changed files with 8 additions and 4 deletions

View file

@ -16,7 +16,6 @@ if __name__ == "__main__":
microphone_input, speaker_output = create_microphone_input_and_speaker_output(use_first_available_device=True) microphone_input, speaker_output = create_microphone_input_and_speaker_output(use_first_available_device=True)
conversation = Conversation( conversation = Conversation(
key=os.environ.get("VOCODE_API_KEY"),
input_device=microphone_input, input_device=microphone_input,
output_device=speaker_output, output_device=speaker_output,
transcriber_config=DeepgramTranscriberConfig.from_input_device(microphone_input), transcriber_config=DeepgramTranscriberConfig.from_input_device(microphone_input),

6
vocode/__init__.py Normal file
View file

@ -0,0 +1,6 @@
import os
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv("VOCODE_API_KEY")

View file

@ -12,6 +12,7 @@ from .models.transcriber import TranscriberConfig
from .models.agent import AgentConfig from .models.agent import AgentConfig
from .models.synthesizer import SynthesizerConfig from .models.synthesizer import SynthesizerConfig
from .models.websocket import ReadyMessage, AudioMessage, StartMessage, StopMessage from .models.websocket import ReadyMessage, AudioMessage, StartMessage, StopMessage
from . import api_key
VOCODE_WEBSOCKET_URL = f'wss://api.vocode.dev/conversation' VOCODE_WEBSOCKET_URL = f'wss://api.vocode.dev/conversation'
@ -19,14 +20,12 @@ class Conversation:
def __init__( def __init__(
self, self,
key: str,
input_device: BaseInputDevice, input_device: BaseInputDevice,
output_device: BaseOutputDevice, output_device: BaseOutputDevice,
transcriber_config: TranscriberConfig, transcriber_config: TranscriberConfig,
agent_config: AgentConfig, agent_config: AgentConfig,
synthesizer_config: SynthesizerConfig synthesizer_config: SynthesizerConfig
): ):
self.key = key
self.input_device = input_device self.input_device = input_device
self.output_device = output_device self.output_device = output_device
self.transcriber_config = transcriber_config self.transcriber_config = transcriber_config
@ -45,7 +44,7 @@ class Conversation:
self.active = False self.active = False
async def start(self): 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): async def sender(ws):
start_message = StartMessage( start_message = StartMessage(
transcriber_config=self.transcriber_config, transcriber_config=self.transcriber_config,