From 11af47482cf400facb226365b16c8be4f5e26fc3 Mon Sep 17 00:00:00 2001 From: Ajay Raj Date: Wed, 29 Mar 2023 01:54:26 -0700 Subject: [PATCH] google env fixes --- pyproject.toml | 2 +- vocode/streaming/streaming_conversation.py | 20 +++---------------- .../synthesizer/google_synthesizer.py | 7 +++++-- .../transcriber/google_transcriber.py | 5 ++++- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 56bbb70..4f56a0c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "vocode" -version = "0.1.61" +version = "0.1.63" description = "The all-in-one voice SDK" authors = ["Ajay Raj "] license = "MIT License" diff --git a/vocode/streaming/streaming_conversation.py b/vocode/streaming/streaming_conversation.py index 3dcf572..80d7cb7 100644 --- a/vocode/streaming/streaming_conversation.py +++ b/vocode/streaming/streaming_conversation.py @@ -1,19 +1,14 @@ import asyncio -from asyncio import Future -from ctypes import Union import queue -from typing import Callable, Awaitable, Optional, Any +from typing import Optional, Any import logging import threading import time -import secrets import random from vocode.streaming.agent.bot_sentiment_analyser import ( - BotSentiment, BotSentimentAnalyser, ) -from vocode.streaming.agent.information_retrieval_agent import InformationRetrievalAgent from vocode.streaming.factory import ( create_agent, create_synthesizer, @@ -21,26 +16,16 @@ from vocode.streaming.factory import ( ) from vocode.streaming.models.message import BaseMessage from vocode.streaming.output_device.base_output_device import BaseOutputDevice -from vocode.streaming.transcriber.assembly_ai_transcriber import AssemblyAITranscriber from vocode.streaming.utils.goodbye_model import GoodbyeModel from vocode.streaming.utils.transcript import Transcript -from vocode.streaming.models.transcriber import ( - TranscriberConfig, - TranscriberType, -) from vocode.streaming.models.agent import ( - AgentConfig, - AgentType, FillerAudioConfig, FILLER_AUDIO_DEFAULT_SILENCE_THRESHOLD_SECONDS, ) from vocode.streaming.models.synthesizer import ( - SynthesizerConfig, - SynthesizerType, TrackBotSentimentConfig, ) -from vocode.streaming.models.websocket import AudioMessage from vocode.streaming.constants import ( TEXT_TO_SPEECH_CHUNK_SIZE_SECONDS, PER_CHUNK_ALLOWANCE_SECONDS, @@ -104,7 +89,8 @@ class StreamingConversation: self.bot_sentiment_analyser = BotSentimentAnalyser( emotions=self.track_bot_sentiment_config.emotions ) - self.goodbye_model = GoodbyeModel() + if self.agent.get_agent_config().end_conversation_on_goodbye: + self.goodbye_model = GoodbyeModel() self.is_human_speaking = False self.active = False diff --git a/vocode/streaming/synthesizer/google_synthesizer.py b/vocode/streaming/synthesizer/google_synthesizer.py index f408c4a..f37fcc4 100644 --- a/vocode/streaming/synthesizer/google_synthesizer.py +++ b/vocode/streaming/synthesizer/google_synthesizer.py @@ -1,4 +1,5 @@ import io +import os import wave from typing import Any, Optional @@ -23,10 +24,12 @@ class GoogleSynthesizer(BaseSynthesizer): def __init__(self, synthesizer_config: GoogleSynthesizerConfig): super().__init__(synthesizer_config) # Instantiates a client - if not getenv("GOOGLE_APPLICATION_CREDENTIALS"): + credentials_path = getenv("GOOGLE_APPLICATION_CREDENTIALS") + if not credentials_path: raise Exception( - "GOOGLE_APPLICATION_CREDENTIALS environment variable must be set" + "Please set GOOGLE_APPLICATION_CREDENTIALS environment variable" ) + os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = credentials_path self.client = tts.TextToSpeechClient() # Build the voice request, select the language code ("en-US") and the ssml diff --git a/vocode/streaming/transcriber/google_transcriber.py b/vocode/streaming/transcriber/google_transcriber.py index 1eb482d..04d3880 100644 --- a/vocode/streaming/transcriber/google_transcriber.py +++ b/vocode/streaming/transcriber/google_transcriber.py @@ -1,4 +1,5 @@ import asyncio +import os import time import queue from google.cloud import speech @@ -19,10 +20,12 @@ class GoogleTranscriber(BaseTranscriber): super().__init__(transcriber_config) self._queue = queue.Queue() self._ended = False - if not getenv("GOOGLE_APPLICATION_CREDENTIALS"): + credentials_path = getenv("GOOGLE_APPLICATION_CREDENTIALS") + if not credentials_path: raise Exception( "Please set GOOGLE_APPLICATION_CREDENTIALS environment variable" ) + os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = credentials_path self.google_streaming_config = self.create_google_streaming_config() self.client = speech.SpeechClient() self.warmed_up = False