chatgptguru / AI-voice-assistant-using-GPT3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Introduction

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.

Libraries used

  • 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.

Getting an OpenAI API Key

  1. Sign up for an OpenAI account at https://beta.openai.com/signup.

  2. Verify your email address and log in to your OpenAI account.

  3. Generate an API Key by navigating to the API Keys section in your account settings.

How to use

  1. Install the required libraries by running the following command in your terminal:

pip3 install openai speech_recognition pyttsx3

  1. Set your OpenAI API key in the code.

  2. Run the code using the following command:

python suzu_bot.py

  1. The chatbot will ask for voice input using the text "Speak:". Speak your query after the prompt.

  2. The chatbot will respond with a text and audio response.

  3. Repeat the process as many times as desired. The chatbot will continue to listen for voice commands until you say "bye".

Code structure

  • 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".

About


Languages

Language:Python 100.0%