Introduction
The Chatbox with ChatGPT Extension is a versatile tool that enables developers to integrate AI-driven conversations into their applications. It leverages the power of the ChatGPT model to create interactive and intelligent chat experiences. With this extension, you can build chatbots, virtual assistants, or conversational agents that understand and respond to user inputs naturally.
The code creates a character named “Tobi” and uses speech recognition to understand spoken commands. It then asks a question to the AI assistant (ChatGPT) and displays the response on the screen, converts it into speech, and makes the character “Tobi” speak the response.
Code
sprite = Sprite('Tobi')
gpt = ChatGPT()
speech = TexttoSpeech()
sr = SpeechRecognition()
ts = TexttoSpeech()
sr.analysespeech(4, "en-US")
command = sr.speechresult()
answer = command.lower()
# sprite.input("Provide a valid word")
# answer= str(sprite.answer())
gpt.askOnChatGPT("AIAssistant", answer)
# Ask on chatGPT other OPTION "friendAI" "sarcasticAI"
result=gpt.chatGPTresult()
print(result)
speech.speak(result)
sprite.say(result,5)
Logic
- Open PictoBlox and create a new file.
- Choose a suitable coding environment for Block-based coding.
- We create an instance of Speech recognition. This class allows us to convert spoken audio into text.
- Next, we create an instance of the ChatGPT model called gpt. ChatGPT is a language model that can generate human-like text responses based on the input it receives.
- Recognize speech for 5 seconds using recognize speech for ()s in the () block.
- The sprite object has already been initialized.
- We analyze the spoken speech for 4 seconds and assume it is in the English language using analysespeech().
- We store the recognized speech as text in the variable command using speechresult().
- We convert the recognized speech to lowercase and store it in the variable answer.
- We ask the AI model ChatGPT (acting as an AI assistant) a question based on the user’s input stored in the answer.
- We retrieve the response from the AI model and store it in the variable result using chatGPTresult().
- We display the response on the screen using print(result).
- We convert the response into speech and play it aloud using the speech object using speak().
- The character “Tobi” speaks the response for 5 seconds using say().
- Press the Run button to run the code.
Output
I asked ChatGPT for a joke, and it responded with an interesting response.