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.
Languages
OS
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
Welcome to Jervis AI!
I'm Rangersmyth (internet name), and I'm currently learning Python and Bash coding.
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".
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.
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.
- Option 1: Install using the requirements.txt file for the required libraries and versions to run the program.
pip install -r requirements.txt
- Option 2: Run the install_jervis.bat file to install the required libraries and versions to run the program.
install_jervis.bat
- Option 3: Run the install_jervis.py file to install the required libraries and versions to run the program.
python install_jervis.py
- All modules listed below will be installed with either of the 3 files
3 ways to install the required libraries to run the program:
- pyttsx3
- speech_recognition
- openai
- requests
- pymongo
- pydub
- pyaudio
- wave
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:
- OpenAI - https://platform.openai.com/ - This has a small charge every time, but 5 USD lasts me a month with normal usage, if you go mad, it can get expensive.
- MongoDB Online Database - https://www.mongodb.com/ - This is free
- ElevenLabs - https://elevenlabs.io/ - There is a free version with voices or pay and clone your own to use.
- Gmail - https://www.google.com/gmail/ - This is free
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.
-
Clone this repository to your local machine using
git clone https://github.com/davidtkeane/Jervis-ChatGPT.git
-
Go to the folder you have the github project saved and enter it.
-
Next we install the modules for the script to work.
-
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)
-
Now sign-up or sign back into Prerequisites.
-
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. -
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. -
Add all keys to the .env-clone file inside the
<b>
single_python_setup_files_for_project</b>
folder as you go along. -
Once you have tested all the files, and added the keys and stuff into the .env-clone file.
-
Copy the .env-clone file into the main folder
<b>jervis_ChatGPT</b>
then we are ready to run the jervis.py -
Once all scripts have been run, and files have appeared in the test folder for conformation and you have filled up the .env-clone.
-
Copy this file .env-clone to the main jervis-ChatGPT folder with the file jervis.py, and rename .env-clone to .env
-
python jervis.py ( add the switches )
-
I use python jervis.py --voice elevenlabs --save command to record the conversation and also to email it to my gmail account.
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 |
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.
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.
Use the Docker file to build a Docker image and run the program in a container.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.
If you have any questions, feel free to reach out to me at rangersmyth.74@gmail.com