This code is a simple chatbot(suzu_bot) that uses OpenAI's language generation API to generate responses based on user input. The user can interact with the chatbot through voice commands using the Speech Recognition and Pyttsx3 libraries.
- OpenAI: An AI research organization that provides access to a variety of powerful AI models via APIs.
- Speech Recognition: A library for performing speech recognition, with support for several engines and APIs.
- Pyttsx3: A Python library for converting text to speech.
-
Sign up for an OpenAI account at https://beta.openai.com/signup.
-
Verify your email address and log in to your OpenAI account.
-
Generate an API Key by navigating to the API Keys section in your account settings.
- Install the required libraries by running the following command in your terminal:
pip3 install openai speech_recognition pyttsx3
-
Set your OpenAI API key in the code.
-
Run the code using the following command:
python suzu_bot.py
-
The chatbot will ask for voice input using the text "Speak:". Speak your query after the prompt.
-
The chatbot will respond with a text and audio response.
-
Repeat the process as many times as desired. The chatbot will continue to listen for voice commands until you say "bye".
- The code sets the OpenAI API key.
- The
chatbot
function takes in a prompt and returns a response generated by OpenAI's language generation API. - The
get_audio_input
function listens for voice input and converts it to text. - The
play_audio_output
function converts text to speech and plays it back. - The main loop of the code continues to listen for voice input and respond with the chatbot's generated response until the user says "bye".