Skip to content

This Python script is for a voice interface chatbot named Jervis. It uses OpenAI's GPT-3.5-turbo-instruct model to respond to user input. The chatbot responds by Elevenlabs Voices. Conversation are saved to MongoDB, and MP3 file local and can be emailed if needed.

Notifications You must be signed in to change notification settings

davidtkeane/Jervis-ChatGPT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

45 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ Jervis-ChatGPT with ElevenLabs and MongoDB

Hi, guys! πŸ‘‹

This Python script is for a voice interface chatbot named Jervis. It uses OpenAI's GPT-3.5-turbo-instruct model to respond to user input. The user can interact with the chatbot through speech, and the chatbot responds with text and/or speech. The conversation can be saved as an MP3 file and emailed to a specified address. The conversation is also logged to a MongoDB database.

PowerShell GitHub last commit GitHub issues

Languages

Python

OS

Linux Windows


Image by MidJourney AI by Gia-Guar
This is the URL to the image
This is another version of Jervis called Jarvis by Gia-Guar, similar but a little different

GitHub last commit

Welcome to Jervis AI!

I'm Rangersmyth (internet name), and I'm currently learning Python and Bash coding.


🧐 About:

The script supports two types of voices: the local system's voice and a voice from ElevenLabs. The user can specify the voice, speech rate, and volume through command-line arguments. The script also supports sending the conversation via email and saving the conversation to an MP3 file.

The script uses several libraries, including pyttsx3 for text-to-speech, speech_recognition for speech-to-text, openai for the GPT-3.5-turbo-instruct model, pymongo for MongoDB interaction, and smtplib for sending emails.

The script logs errors and exceptions to a file and also logs the conversation history to a MongoDB database. The MongoDB connection details are fetched from environment variables.

The script also includes a function to send emails with an optional attachment, which can be used to send the conversation history as an MP3 file.

The script starts with a conversation loop where it listens for user input, processes the input, generates a response, and speaks the response.

I use python jervis.py --voice elevenlabs --save command to record the conversation and also to email it to my gmail account.

The conversation continues until the user says "goodbye".

πŸ” Advanced Summary:

The script continues with MongoDB integration for storing conversation logs, modifying the send_email function to use environment variables for email credentials and to handle attachments. It then enters a conversation loop, using speech recognition to convert user speech to text and processing it. The script handles various commands and exceptions, including a 'goodbye' command to end the conversation. It also includes error handling and logging, with the capability to test error logging by raising an exception.

The script initializes environment variables, sets up logging, and configures a speech engine. It includes an argument parser for command-line options and integrates with OpenAI and ElevenLabs APIs for voice synthesis. The script also contains a function to process user input using GPT, handle voice output (either through ElevenLabs or pyttsx3), and log conversations. Email credentials are retrieved from environment variables, and a function to log conversations and save audio data is defined. The script is prepared to handle text-to-speech, speech recognition, and email functionalities, with provisions for command-line arguments to customize behaviour.

The script continues with MongoDB integration for storing conversation logs, modifying the send_email function to use environment variables for email credentials and to handle attachments. It then enters a conversation loop, using speech recognition to convert user speech to text and processing it. The script handles various commands and exceptions, including a 'goodbye' command to end the conversation. It also includes error handling and logging, with the capability to test error logging by raising an exception.

πŸ†˜ Help on Install:

⚾ Installation Help Files:

1. Read the files in the help_files folder before hammering away to make this script work! Use the files in the single_python_setup_files_for_project and use these one at a time to get working first, once all files work and return 'connection established' then you are ready to go, remember to add all keys to the .env-clone file

2. This is the **README.md** file to provide more information on how to use the program. You will have to sign up to Prerequisites for keys, ID's and API keys, see below for more details.

3. Read the extra help files in the **help_files** folder for help with connecting to MongoDB and Gmail. The file **single_python_setup_files_for_project.md** has extra setup information on the different parts from Mongodb, Gmail, Elevenlabs, it can help you to connect to each service and test connection to Gmail, Elevenlabs and MongoDB if you have the correct API keys.

4. Add the keys to the .env-clone file inside the folder **single_python_setup_files_for_project** and leave the structure as it is.

Read the other instructions in the help_files for more information on how to use the program.

πŸ’» Modules Installation instructions:

    3 ways to install the required libraries to run the program:

  1. Option 1: Install using the requirements.txt file for the required libraries and versions to run the program. pip install -r requirements.txt
  2. Option 2: Run the install_jervis.bat file to install the required libraries and versions to run the program. install_jervis.bat
  3. Option 3: Run the install_jervis.py file to install the required libraries and versions to run the program. python install_jervis.py
  4. All modules listed below will be installed with either of the 3 files
πŸ” Pip Modules to Install
  1. pyttsx3
  2. speech_recognition
  3. openai
  4. requests
  5. pymongo
  6. pydub
  7. pyaudio
  8. wave

πŸ₯·Prerequisites:

πŸ€ Signup to Gmail, Elevenlabs, MongDB and OpenAI:

There are instructions in the help_files folder and the file called # Jervis Install instructions in more detail.md will have more detailed instructions on how to connect to gmail and mongodb

You will have to sign up to:

You will need to get API keys and Voice Id and put them into the .env-clone file. Just replace Your with your info. Leave the structure the way it is, just replace the Your sections. In the test files, you will have to enter the API''s manually, as there is no .env-clone key in this folder and the scripts do not look for this file to check for private information. Once all the test files are working and all API info entered into the .env-clone file, we are ready to rumble.

πŸš€ Installation Steps

  1. Clone this repository to your local machine using git clone https://github.com/davidtkeane/Jervis-ChatGPT.git

  2. Go to the folder you have the github project saved and enter it.

  3. Next we install the modules for the script to work.

  4. Install the modules pip install -m requirements.txt (This will install all the modules needed to run the scripts) or python install_jervis.py (This version will also install the requirements and also checks for other programs like VS-Code and PowerShell is installed, and an option to upgrade)

  5. Now sign-up or sign back into Prerequisites.

πŸš€ Prerequisites Steps

  1. Once you have all the required keys, then move on to testing them with the scripts i made in the <b>single_python_setup_files_for_project </b> folder.

  2. Go into the folder <b>single_python_setup_files_for_project </b> and go through each one to test your connection is established and working, if you have your API keys, then you don't have to do this.

  3. Add all keys to the .env-clone file inside the <b>single_python_setup_files_for_project </b> folder as you go along.

  4. Once you have tested all the files, and added the keys and stuff into the .env-clone file.

  5. Copy the .env-clone file into the main folder <b>jervis_ChatGPT</b> then we are ready to run the jervis.py

  6. Once all scripts have been run, and files have appeared in the test folder for conformation and you have filled up the .env-clone.

  7. Copy this file .env-clone to the main jervis-ChatGPT folder with the file jervis.py, and rename .env-clone to .env

  8. python jervis.py ( add the switches )

  9. I use python jervis.py --voice elevenlabs --save command to record the conversation and also to email it to my gmail account.

πŸ“– Command --switches

Switch Description
--welcome Show welcome message
--voice Voice to use ("local" or "elevenlabs")
--rate Speech rate (words per minute)
--volume Speech volume (0.0 to 1.0)
--save Save conversation to an MP3 file
--email-n Do not email the conversation
--help Show help message
--version Show version message

πŸ‚ Examples of Commands:

Command Examples:

Command:

python jervis.py --voice elevenlabs

Description: This will use the ElevenLabs voice, it won't save the conversation to an MP3 file, and won't email the conversation to a specified email address.

Command:

python jervis.py --voice elevenlabs --save

Description: This will use the ElevenLabs voice, it will save the conversation to an MP3 file, and will email the conversation to a specified email address.

Command:

python jervis.py --voice elevenlabs --save --email-n

Description: This will use the ElevenLabs voice, save the conversation to an MP3 file, but won't email the conversation to a specified email address.

Command:

python jervis.py --voice local --save

Description: This will use the local computer's voice, this will save the conversation to an MP3 file, and email the conversation to a specified email address.

Command:

python jervis.py --voice local --save --email-n

Description: This will use the local computer's voice, save the conversation to an MP3 file, but won't email the conversation to a specified email address.

Command:

python jervis.py --help

Description: This will display the help message.

πŸ“ Error Logging

If an error occurs during the execution of the script, the error message and the line of code that caused the error will be written to the error.log file.

πŸ΄β€β˜ οΈ Upgrade Ideas and Suggestions

Use the Docker file to build a Docker image and run the program in a container.

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“œ License

This project is licensed under the MIT License.

πŸ“ž Contact

If you have any questions, feel free to reach out to me at rangersmyth.74@gmail.com

About

This Python script is for a voice interface chatbot named Jervis. It uses OpenAI's GPT-3.5-turbo-instruct model to respond to user input. The chatbot responds by Elevenlabs Voices. Conversation are saved to MongoDB, and MP3 file local and can be emailed if needed.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages