diff --git a/README.md b/README.md index 8fa91c5..f3b9ac0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Sample AI assistant +You need an `OPENAI_API_KEY` and a `GOOGLE_API_KEY` to run this code. Store them in a `.env` file in the root directory of the project, or set them as environment variables. + + If you are running the code on Apple Silicon, run the following command: ``` @@ -18,5 +21,5 @@ $ pip install -r requirements.txt Run the assistant: ``` -$ python assistant.py +$ python3 assistant.py ``` \ No newline at end of file diff --git a/assistant.py b/assistant.py index 3795e4a..50501bb 100644 --- a/assistant.py +++ b/assistant.py @@ -2,6 +2,7 @@ import base64 from threading import Lock, Thread import cv2 +import openai from cv2 import VideoCapture, imencode from dotenv import load_dotenv from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder @@ -10,7 +11,6 @@ from langchain_community.chat_message_histories import ChatMessageHistory from langchain_core.output_parsers import StrOutputParser from langchain_core.runnables.history import RunnableWithMessageHistory from langchain_google_genai import ChatGoogleGenerativeAI -from openai import audio from pyaudio import PyAudio, paInt16 from speech_recognition import Microphone, Recognizer, UnknownValueError @@ -79,12 +79,13 @@ class Assistant: print("Response:", response) - self._tts(response) + if response: + self._tts(response) def _tts(self, response): player = PyAudio().open(format=paInt16, channels=1, rate=24000, output=True) - with audio.speech.with_streaming_response.create( + with openai.audio.speech.with_streaming_response.create( model="tts-1", voice="alloy", response_format="pcm",