Table of Contents

Function Definition: analysespeech(time = 2, language = "en-US")

Parameters

NameTypeDescriptionExpected ValuesDefault Value
timeintThe record time in seconds.2-102
languagestringThe language in which speech needs to be analysed."ar-AE", "ca-ES", "da-DK", "da-de", "en-GB", "en-US", "es-ES", "fi-FI", "fr-FR", "gu-IN", "hi-IN", "it-IT", "ja-JP", "ko-KR", "mr-IN", "nb-NO", "nl-NL", "pl-PL", "pt-PT", "ru-RU", "sv-SE", "ta-IN", "te-IN", "th-TH", "tr-TR", "zh-CN", "zh-HK""en-US"

Description

When the function is executed, the recognition window will open and you will get a specified time during which PictoBlox will record whatever you say. Once recorded, the speech will be converted to the text of the language you spoke in and saved locally.

Example

Engage in interactive conversations with the AI assistant powered by ChatGPT and Sprite Tobi.

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

  1. Open PictoBlox and create a new file.
  2. Choose a suitable coding environment for Block-based coding.
  3. We create an instance of  Speech recognition. This class allows us to convert spoken audio into text.
  4. 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. 
  5. Recognize speech for 5 seconds using recognize speech for ()s in the () block.
  6. The sprite object has already been initialized.
  7. We analyze the spoken speech for 4 seconds and assume it is in the English language using analysespeech().
  8.  We store the recognized speech as text in the variable command using speechresult().
  9. We convert the recognized speech to lowercase and store it in the variable answer.
  10. We ask the AI model ChatGPT (acting as an AI assistant) a question based on the user’s input stored in the answer.
  11. We retrieve the response from the AI model and store it in the variable result using chatGPTresult().
  12. We display the response on the screen using print(result).
  13.  We convert the response into speech and play it aloud using the speech object using speak().
  14.  The character “Tobi” speaks the response for 5 seconds using say().
  15. Press the Run button to run the code.

Output

I asked ChatGPT for a joke, and it responded with an interesting response.

Read More
All articles loaded
No more articles to load