This program is a voice assistant that utilizes OpenAI's API to generate responses to user inputs. The voice assistant listens to user input through a microphone, converts it to text using the SpeechRecognition library, and sends the conversation to the OpenAI API for generating a response. The response is then converted back to speech using the pyttsx3 library and played back to the user.
- Python 3.x
- SpeechRecognition library (
pip install SpeechRecognition
) - pyttsx3 library (
pip install pyttsx3
) - OpenAI API key
-
Clone the repository or download the source code files.
-
Install the required libraries by running the following command:
pip install SpeechRecognition pyttsx3
-
Obtain an OpenAI API key by signing up for the OpenAI GPT-3 service.
-
Replace
"Your API Key"
in the code with your actual OpenAI API key.
-
Connect a microphone to your computer.
-
Run the program by executing the python file run command in the terminal.
-
The voice assistant will start listening for your voice input.
-
Begin speaking your command or question after the assistant indicates that it is listening.
-
The voice assistant will process your input, send it to the OpenAI API, and generate a response.
-
The response will be spoken back to you by the assistant.
-
The conversation history will be displayed on the console, with user inputs prefixed by
user_name:
and assistant responses prefixed bybot_name:
. -
The assistant will continue to listen for new commands until you manually exit the program.
-
You can customize the
user_name
andbot_name
variables in the code to change the names used in the conversation history. -
Adjust the parameters in the
openai.Completion.create()
method to modify the behavior of the OpenAI API model. You can experiment with thetemperature
,max_tokens
,top_p
,frequency_penalty
, andpresence_penalty
parameters to control the output generated by the model.
Please note that the OpenAI GPT-3 model is a language model trained on a large corpus of text and may not always generate accurate or appropriate responses. Exercise caution when using the voice assistant for sensitive or critical tasks. The program is provided as-is without any warranties or guarantees.
- The voice assistant is built using the SpeechRecognition and pyttsx3 libraries.
- OpenAI for providing the GPT-3 API.