ChatGPT-3 wants no introduction. You ask it any query and it replies in a flash. However the reply comes within the type of textual content. What for those who may discuss with it, identical to you do with any voice assistant like Siri?
It’s no secret that ChatGPT has revolutionised the world of AI. In contrast to different AI bots, it is ready to perceive the context of a dialog and reply, and it makes you are feeling like you’re chatting with a human and never a machine.
However as it’s nonetheless a type of chatbot, you should sort a query and also you get the reply within the type of textual content. That’s not as thrilling as speaking to a bot.
This thought gave me the concept of programming ChatGPT in order that it might be used as a voice assistant referred to as VoiceGPT. I started through the use of pure language processing (NLP) to recognise the voice, after which transferring the recognised voice to the ChatGPT engine as a question utilizing the API. After getting an clever reply from ChatGPT, I once more used NLP to transform it right into a human voice.
I wanted a superb NLP software for this and OpenAI itself offers one, that’s, Whisper. However because of restricted time and house, I ended up utilizing Google Pure Language API.
A step-by-step information to creating VoiceGPT
We have to start by combining the NLP for the ttX service with ChatGPT. For this we’d like a machine to run the open API, switch the question gathered from NLP, and reprocess the reply given by ChatGPT right into a human voice utilizing NLP.
You need to use any laptop computer, however I selected the Raspberry Pi to run all this. For capturing the voice for recognition, I connected the voice bonnet; a USB microphone may also be used with Raspberry Pi. Nevertheless, in case you are utilizing a laptop computer to run the VoiceGPT code, there isn’t a want for a USB microphone; you need to use the laptop computer’s inbuilt microphone.
We now must create an account and log into ChatGPT (see Fig. 2).
Subsequent, we have to get the API key for doing analysis and experimenting with the ChatGPT code, as proven in Fig. 3.
You may create the API key utilizing the right-corner choice for API in your OpenAI account (Fig. 4).
After producing the OpenAI API key, copy it and reserve it. We’d like it later in our code for growing VoiceGPT.
Now we have to set up the open AI on the system the place we’re going to run the VoiceGPT. Right here you need to use a pc with any Linux model put in. I used Raspberry Pi for it.
Subsequent, open the terminal and set up the open AI and different Python modules that assist us in pure language processing. Right here you need to use Whisper from OpenAI or another NLP module. I used Google NLP and mixed it with ChatGPT.
You may set up these modules utilizing the next command. After that, you may both create your open customized speaking content material in OpenAI or use easy chatting within the playground. Right here, you can too set the temperature, frequency, and different parameters on your VoiceGPT assistant.
sudo pip3 set up openai sudo pip3 set up SpeechRecognition sudo pip3 set up gTTS
Discuss with Fig. 5 and Fig. 6 to see tips on how to clone the OpenAI ChatGPT and do the setup.
Subsequent, set the temperature, frequency, and chat mannequin, as proven in Fig. 7.
Programming ChatGPT for use as VoiceGPT
First, we have to import the OpenAI Python module in code to play with OpenAI and perform an experiment with ChatGPT. Subsequent, we import the modules for NLP. After that, we import pygame to play the file that processed the reply in a human voice utilizing the NLP mannequin. Subsequent, we have to set the ChatGPT mannequin (see Fig. 8). Right here, we are able to select from mannequin names like Davinci, Ada, and so forth. Every mannequin has its personal experience, and the price of utilizing these fashions varies. However no worries, as a result of builders get a US$18 credit score to develop and experiment with OpenAI.
Subsequent, we have to set the API within the code. With that, we have now created the operate for connecting with ChatGPT to deal with the question 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 succesful #model_to_use=”text-curie-001” #model_to_use=”text-babbage-001” model_to_use=”text-ada-001” # lowest token price r = sr.Recognizer() openai.api_key=”******Your Key Right here*******” def chatGPT(question): response = openai. Completion.create( model-model_to_use, immediate=question, temperature=0, max_tokens 1000 ) return str.strip(response[‘choices’][0] [‘text’]), response[‘usage’][‘total_ tokens’]
After that, we create the principle operate after which make some time loop. Right here, we use NLP to seize the voice constantly and extract what we stated utilizing the NLP mannequin and reserve it as a question. Then we switch this question to ChatGPT and obtain the response from it.
def primary(): print(‘LED is ON while button is pressed (Ctrl-C for exit).’) whereas True: with sr.Microphone() as supply: r.adjust_for_ambient_noise (supply) print(“Say something!”) audio r.hear(supply) 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__’: primary()
After this, we once more use NLP to transform the reply from ChatGPT right into a human voice, after which we play that voice. This complete factor runs in a loop constantly making it appear to be an actual dialog between two people.
This VoiceGPT offers you the choice of customising and deciding on fashions. It permits you to select from GPT fashions like Ada, Davinci, or Babbage. It makes use of a free speech-recognition service that may be customised to offline speech-recognition providers like Sphenix.
Testing VoiceGPT
To check the VoiceGPT, run the code in Python, and it’ll let you know to ask a query or begin a dialog. You may ask no matter you need; it recognises your voice, transfers the question to ChatGPT, after which replies to you in a human voice.
So now you may discuss to ChatGPT identical to you do with Google Assistant, Alexa, or Siri. Get pleasure from your dialog with VoiceGPT!
Creator’s notice. That is the primary model of VoiceGPT. I’m nonetheless experimenting with it and you’re going to get all the brand new updates very quickly on
Ashwini KumarSinha is an IoT and AI fanatic tech journalist at EFY