How To Convert ChatGPT Into An Advanced Voice Assistant
ChatGPT-3 needs no introduction. You ask it any question and it replies in a flash. But the answer comes in the form of text. What if you could talk with it, just like you do with any voice assistant like Siri?
- Suitable forB.Tech Embedded students
- Build time3-4 weeks
- LevelBeginner
- Available atAjvika Labs, Kakinada
About this project
ChatGPT-3 needs no introduction. You ask it any question and it replies in a flash. But the answer comes in the form of text. What if you could talk with it, just like you do with any voice assistant like Siri?
It’s no secret that ChatGPT has revolutionised the world of AI. Unlike other AI bots, it is able to understand the context of a conversation and respond, and it makes you feel like you are chatting with a human and not a machine.
This thought gave me the idea of programming ChatGPT so that it could be used as a voice assistant called VoiceGPT. I began by using natural language processing (NLP) to recognise the voice, and then transferring the recognised voice to the ChatGPT engine as a query using the API. After getting an intelligent reply from ChatGPT, I again used NLP to convert it into a human voice.
I needed a good NLP tool for this and OpenAI itself provides one, that is, Whisper. But due to limited time and space, I ended up using Google Natural Language API.
A step-by-step guide to making VoiceGPT
We need to begin by combining the NLP for the ttX service with ChatGPT. For this we need a machine to run the open API, transfer the query gathered from NLP, and reprocess the answer given by ChatGPT into a human voice using NLP.
You can use any laptop, but I chose the Raspberry Pi to run all this. For capturing the voice for recognition, I attached the voice bonnet; a USB microphone can also be used with Raspberry Pi. However, if you are using a laptop to run the VoiceGPT code, there is no need for a USB microphone; you can use the laptop’s inbuilt microphone.
We now need to create an account and log into ChatGPT (see Fig. 2).
Next, we need to get the API key for doing research and experimenting with the ChatGPT code, as shown in Fig. 3.
You can create the API key using the right-corner option for API in your OpenAI account (Fig. 4).
After generating the OpenAI API key, copy it and save it. We need it later in our code for developing VoiceGPT.
Now we need to install the open AI on the system where we are going to run the VoiceGPT. Here you can use a computer with any Linux version installed. I used Raspberry Pi for it.
Next, open the terminal and install the open AI and other Python modules that help us in natural language processing. Here you can use Whisper from OpenAI or any other NLP module. I used Google NLP and combined it with ChatGPT.
You can install these modules using the following command. After that, you can either create your open custom talking content in OpenAI or use simple chatting in the playground. Here, you can also set the temperature, frequency, and other parameters for your VoiceGPT assistant.
sudo pip3 install openai sudo pip3 install SpeechRecognition sudo pip3 install gTTS Refer to Fig. 5 and Fig. 6 to see how to clone the OpenAI ChatGPT and do the setup.
Next, set the temperature, frequency, and chat model, as shown in Fig. 7.
Programming ChatGPT to be used as VoiceGPT
First, we need to import the OpenAI Python module in code to play with OpenAI and carry out an experiment with ChatGPT. Next, we import the modules for NLP. After that, we import pygame to play the file that processed the reply in a human voice using the NLP model. Next, we need to set the ChatGPT model (see Fig. 8). Here, we can choose from model names like Davinci, Ada, etc. Each model has its own expertise, and the cost of using these models varies. But no worries, because developers get a US$18 credit to develop and experiment with OpenAI.
Next, we need to set the API in the code. With that, we have created the function for connecting with ChatGPT to handle the query and get the response from it.
import speech_recognition as sr import math import time import serial from espeak import espeak import sys import openai import pygame from gtts import gTTS pygame.mixer.init() #model_to_use=”text-davinci-003” # most capable #model_to_use=”text-curie-001” #model_to_use=”text-babbage-001” model_to_use=”text-ada-001” # lowest token cost r = sr.Recognizer() openai.api_key=”******Your Key Here*******” def chatGPT(query): response = openai. Completion.create( model-model_to_use, prompt=query, temperature=0, max_tokens 1000 ) return str.strip(response[‘choices’][0] [‘text’]), response[‘usage’][‘total_ tokens’]
After that, we create the main function and then make a while loop. Here, we use NLP to capture the voice continuously and extract what we said using the NLP model and save it as a query. Then we transfer this query to ChatGPT and receive the response from it.
def main(): print(‘LED is ON while button is pressed (Ctrl-C for exit).’) while True: with sr.Microphone() as source: r.adjust_for_ambient_noise (source) print(“Say something!”) audio r.listen(source) print(“Recognizing Now….”) command=str(r.recognize_google (audio)) print(“Google Speech Recognition thinks you said + command) query=command (res, usage) = chatGPT (query) print(res) tts gTTS(text=res, lang=’en’) tts.save(“good.mp3”) pygame.mixer.music.load(“good.mp3”) pygame.mixer.music.play() #espeak.synth(res)
if __name__ == ‘__main__’: main()
After this, we again use NLP to convert the reply from ChatGPT into a human voice, and then we play that voice. This whole thing runs in a loop continuously making it look like a real conversation between two humans.
This VoiceGPT gives you the option of customising and selecting models. It allows you to choose from GPT models like Ada, Davinci, or Babbage. It uses a free speech-recognition service that can be customised to offline speech-recognition services like Sphenix.
To test the VoiceGPT, run the code in Python, and it will tell you to ask a question or start a conversation. You can ask whatever you want; it recognises your voice, transfers the query to ChatGPT, and then replies to you in a human voice.
So now you can talk to ChatGPT just like you do with Google Assistant, Alexa, or Siri. Enjoy your conversation with VoiceGPT!
Author’s note. This is the first version of VoiceGPT. I am still experimenting with it and you will get all the new updates very soon on https://www.opensourceforu.com.
Ashwini Kumar Sinha is an IoT and AI enthusiast tech journalist at EFY
Chithraa March 15, 2023 At 8:37 pm “”How To Convert ChatGPT Into An Advanced Voice Assistant”” This very informative article by Shree.Ashwini Kumar Sinha, is deeply explaing various aspects of the programming to make more use of ChatGPT. Even since its release, I have been experimenting with ChatGPT on “other languages?. aspect. Thru continuous chats in it, I am checking the response quality and depth of ChatGPT by conversing deeply in that language. Other than English ans some European Languages, the Data Base and Language Model in other languages is too shallow. Althouigh they assure that my feed back from my end is accepted and the Data Base is updated, the update is not reflected in the conversation subsequently. This idea seems very innovation and novel in that we can have a vocal conversation thru ChatGPT. Thanks a lot to the author. Log in to leave a comment
“”How To Convert ChatGPT Into An Advanced Voice Assistant”” This very informative article by Shree.Ashwini Kumar Sinha, is deeply explaing various aspects of the programming to make more use of ChatGPT. Even since its release, I have been experimenting with ChatGPT on “other languages?. aspect. Thru continuous chats in it, I am checking the response quality and depth of ChatGPT by conversing deeply in that language. Other than English ans some European Languages, the Data Base and Language Model in other languages is too shallow. Althouigh they assure that my feed back from my end is accepted and the Data Base is updated, the update is not reflected in the conversation subsequently. This idea seems very innovation and novel in that we can have a vocal conversation thru ChatGPT. Thanks a lot to the author.
SHARE YOUR THOUGHTS & COMMENTS Register or Login to leave a comment.
Smart Speed Monitoring System For Road Safety
Real-Time Face Tracking Using Raspberry Pi 4 Versus Raspberry Pi 5 With Hailo-8L
High-Voltage Capacitor Discharger
Real-time Web-based Home Automation
World’s Smallest Open-Source LoRa + GPS Module for Wearables and IoT (Only 3cm!)
Smallest Spy Video Streaming Camera
Wirelessly Control Multiple AC Appliances with Web Interface
Ultra-Low-Loss Isolated Current Sensor
STMicroelectronics has Introduced First Automotive Microcontroller With built-in AI Acceleration
Samsung Launched 200MP Image Sensor Called ISOCELL HP5
Aeva Introduced 4D LiDAR Sensor for Physical AI Systems
Battery-Free In-Tire Sensors For Autonomous Vehicles
AI Method Explains Model Predictions
Negative Light Enables Hidden Data Transfer
Blockchain Black Box For Drones
DIY: Audio Signal–Controlled LED Display Using LM3914
State Reduction In Sequential Circuits
Make Your Own Musical Temperature Alarm
Buck Converter vs Linear Voltage Regulator
Ultra-Compact RGB LED For Space-Constrained Designs
Compact Varistors For High Surge Protection
Gold Plated Reed Relays For High Voltage Systems
28nm Automotive MCU For Zonal E/E Architectures
DSP / Audio Firmware Engineer (Intern) At Chordy.ai In Bengaluru
JOB: System Engineer At General Electric In Chennai
JOB: Analog Layout Engineer At Accenture In Bengaluru
JOB: HVDC HMI Engineer At Quest Global In Bengaluru
It’s no secret that ChatGPT has revolutionised the world of AI. Unlike other AI bots, it is able to understand the context of a conversation and respond, and it makes you feel like you are chatting with a human and not a machine.
This thought gave me the idea of programming ChatGPT so that it could be used as a voice assistant called VoiceGPT. I began by using natural language processing (NLP) to recognise the voice, and then transferring the recognised voice to the ChatGPT engine as a query using the API. After getting an intelligent reply from ChatGPT, I again used NLP to convert it into a human voice.
I needed a good NLP tool for this and OpenAI itself provides one, that is, Whisper. But due to limited time and space, I ended up using Google Natural Language API.
A step-by-step guide to making VoiceGPT
We need to begin by combining the NLP for the ttX service with ChatGPT. For this we need a machine to run the open API, transfer the query gathered from NLP, and reprocess the answer given by ChatGPT into a human voice using NLP.
You can use any laptop, but I chose the Raspberry Pi to run all this. For capturing the voice for recognition, I attached the voice bonnet; a USB microphone can also be used with Raspberry Pi. However, if you are using a laptop to run the VoiceGPT code, there is no need for a USB microphone; you can use the laptop’s inbuilt microphone.
We now need to create an account and log into ChatGPT (see Fig. 2).
Next, we need to get the API key for doing research and experimenting with the ChatGPT code, as shown in Fig. 3.
You can create the API key using the right-corner option for API in your OpenAI account (Fig. 4).
After generating the OpenAI API key, copy it and save it. We need it later in our code for developing VoiceGPT.
Now we need to install the open AI on the system where we are going to run the VoiceGPT. Here you can use a computer with any Linux version installed. I used Raspberry Pi for it.
Next, open the terminal and install the open AI and other Python modules that help us in natural language processing. Here you can use Whisper from OpenAI or any other NLP module. I used Google NLP and combined it with ChatGPT.
You can install these modules using the following command. After that, you can either create your open custom talking content in OpenAI or use simple chatting in the playground. Here, you can also set the temperature, frequency, and other parameters for your VoiceGPT assistant.
sudo pip3 install openai sudo pip3 install SpeechRecognition sudo pip3 install gTTS Refer to Fig. 5 and Fig. 6 to see how to clone the OpenAI ChatGPT and do the setup.
Next, set the temperature, frequency, and chat model, as shown in Fig. 7.
Programming ChatGPT to be used as VoiceGPT
First, we need to import the OpenAI Python module in code to play with OpenAI and carry out an experiment with ChatGPT. Next, we import the modules for NLP. After that, we import pygame to play the file that processed the reply in a human voice using the NLP model. Next, we need to set the ChatGPT model (see Fig. 8). Here, we can choose from model names like Davinci, Ada, etc. Each model has its own expertise, and the cost of using these models varies. But no worries, because developers get a US$18 credit to develop and experiment with OpenAI.
Next, we need to set the API in the code. With that, we have created the function for connecting with ChatGPT to handle the query and get the response from it.
import speech_recognition as sr import math import time import serial from espeak import espeak import sys import openai import pygame from gtts import gTTS pygame.mixer.init() #model_to_use=”text-davinci-003” # most capable #model_to_use=”text-curie-001” #model_to_use=”text-babbage-001” model_to_use=”text-ada-001” # lowest token cost r = sr.Recognizer() openai.api_key=”******Your Key Here*******” def chatGPT(query): response = openai. Completion.create( model-model_to_use, prompt=query, temperature=0, max_tokens 1000 ) return str.strip(response[‘choices’][0] [‘text’]), response[‘usage’][‘total_ tokens’]
After that, we create the main function and then make a while loop. Here, we use NLP to capture the voice continuously and extract what we said using the NLP model and save it as a query. Then we transfer this query to ChatGPT and receive the response from it.
def main(): print(‘LED is ON while button is pressed (Ctrl-C for exit).’) while True: with sr.Microphone() as source: r.adjust_for_ambient_noise (source) print(“Say something!”) audio r.listen(source) print(“Recognizing Now….”) command=str(r.recognize_google (audio)) print(“Google Speech Recognition thinks you said + command) query=command (res, usage) = chatGPT (query) print(res) tts gTTS(text=res, lang=’en’) tts.save(“good.mp3”) pygame.mixer.music.load(“good.mp3”) pygame.mixer.music.play() #espeak.synth(res)
if __name__ == ‘__main__’: main()
After this, we again use NLP to convert the reply from ChatGPT into a human voice, and then we play that voice. This whole thing runs in a loop continuously making it look like a real conversation between two humans.
This VoiceGPT gives you the option of customising and selecting models. It allows you to choose from GPT models like Ada, Davinci, or Babbage. It uses a free speech-recognition service that can be customised to offline speech-recognition services like Sphenix.
To test the VoiceGPT, run the code in Python, and it will tell you to ask a question or start a conversation. You can ask whatever you want; it recognises your voice, transfers the query to ChatGPT, and then replies to you in a human voice.
So now you can talk to ChatGPT just like you do with Google Assistant, Alexa, or Siri. Enjoy your conversation with VoiceGPT!
Author’s note. This is the first version of VoiceGPT. I am still experimenting with it and you will get all the new updates very soon on https://www.opensourceforu.com.
Ashwini Kumar Sinha is an IoT and AI enthusiast tech journalist at EFY
Chithraa March 15, 2023 At 8:37 pm “”How To Convert ChatGPT Into An Advanced Voice Assistant”” This very informative article by Shree.Ashwini Kumar Sinha, is deeply explaing various aspects of the programming to make more use of ChatGPT. Even since its release, I have been experimenting with ChatGPT on “other languages?. aspect. Thru continuous chats in it, I am checking the response quality and depth of ChatGPT by conversing deeply in that language. Other than English ans some European Languages, the Data Base and Language Model in other languages is too shallow. Althouigh they assure that my feed back from my end is accepted and the Data Base is updated, the update is not reflected in the conversation subsequently. This idea seems very innovation and novel in that we can have a vocal conversation thru ChatGPT. Thanks a lot to the author. Log in to leave a comment
“”How To Convert ChatGPT Into An Advanced Voice Assistant”” This very informative article by Shree.Ashwini Kumar Sinha, is deeply explaing various aspects of the programming to make more use of ChatGPT. Even since its release, I have been experimenting with ChatGPT on “other languages?. aspect. Thru continuous chats in it, I am checking the response quality and depth of ChatGPT by conversing deeply in that language. Other than English ans some European Languages, the Data Base and Language Model in other languages is too shallow. Althouigh they assure that my feed back from my end is accepted and the Data Base is updated, the update is not reflected in the conversation subsequently. This idea seems very innovation and novel in that we can have a vocal conversation thru ChatGPT. Thanks a lot to the author.
SHARE YOUR THOUGHTS & COMMENTS Register or Login to leave a comment.
Smart Speed Monitoring System For Road Safety
Real-Time Face Tracking Using Raspberry Pi 4 Versus Raspberry Pi 5 With Hailo-8L
High-Voltage Capacitor Discharger
Real-time Web-based Home Automation
World’s Smallest Open-Source LoRa + GPS Module for Wearables and IoT (Only 3cm!)
Smallest Spy Video Streaming Camera
Wirelessly Control Multiple AC Appliances with Web Interface
Ultra-Low-Loss Isolated Current Sensor
STMicroelectronics has Introduced First Automotive Microcontroller With built-in AI Acceleration
Samsung Launched 200MP Image Sensor Called ISOCELL HP5
Aeva Introduced 4D LiDAR Sensor for Physical AI Systems
Battery-Free In-Tire Sensors For Autonomous Vehicles
AI Method Explains Model Predictions
Negative Light Enables Hidden Data Transfer
Blockchain Black Box For Drones
DIY: Audio Signal–Controlled LED Display Using LM3914
State Reduction In Sequential Circuits
Make Your Own Musical Temperature Alarm
Buck Converter vs Linear Voltage Regulator
Ultra-Compact RGB LED For Space-Constrained Designs
Compact Varistors For High Surge Protection
Gold Plated Reed Relays For High Voltage Systems
28nm Automotive MCU For Zonal E/E Architectures
DSP / Audio Firmware Engineer (Intern) At Chordy.ai In Bengaluru
JOB: System Engineer At General Electric In Chennai
JOB: Analog Layout Engineer At Accenture In Bengaluru
JOB: HVDC HMI Engineer At Quest Global In Bengaluru
Technologies used
Hardware components
- Raspberry Pi
- Relay
- MPU
- LED
- Button
- Sensor
- Module
- Capacitor
- Battery
- Microphone
- Camera
- GPS
- LoRa
- RF
Software & tools
- eSpeak
Project demo video
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.