AI Companion (Speech Recognizer & Text)



"I want to add a feature where users can type their questions into a textbox before submitting them to the AI. I also want to optimize the code so it doesn’t require multiple attempts to load the correct response, and remove the timeout that currently acts as a cooldown for the app

See the article on Why you can't wait in AI2

You need to add a Text Box and a Clock Timer and an Enter Button after the Text Box.

When speech recognition finishes, send the text to the textbox.

Use the Enter button to send the textbox.Text to the chatbot.

Use the clock timer instead of the delay procedure.

1 Like

One last thing, would you please provide me a sample coding for the text feature please. It would help me alot since i still haven't mastered coding with mit app and i just tend to rely on youtube tutorials

I don't have your aia export, so I worked up just a simple textbox input sample wrapped with speech recognition and speech output, just to show how text can flow into and out of a textbox.

Designer:

blocks:

aia export:
textbox_input.aia (2.7 KB)

Program flow:

User clicks the Listen button to start Speech Recognition.

A Stop Listening button is provided for safety, to prevent getting stuck in speech recognition mode. In case the Speak button was disabled after receiving partial text, the speak button is re-enabled.

As speech input arrives, it is added onto the end of the textbox.Text, separated by a comma for a little pause. The speak button is disabled until a non-partial speech input is received, preventing premature speaking of incomplete text.

When the Speak button is clicked, we hide the keyboard and start speaking. We disable the Speak button until the app has finished speaking.

After the app has finished speaking, we re-enable the Speak button. If the speech was successful, we clear the input textbox.Text

1 Like

Thank you for helping me! I really appreciate it

Sorry to bother you again, would you mind helping me once again with the coding i can't seem to get it right the way i wanted to. Since i want the textbox feature to have the feature to ask the ai some questions in which the ai would respond to it just like the speech recognition feature. Here's my aia export for you to be able to identify the errors easier. Sorry for relying with your guidance too much
DraftEcoNova.aia (539.0 KB)

Here's my revised version.

I did not need the Clock Timer.

I just enforced not allowing buttons to enabled until their inputs were complete.

Designer:


(I had to add and rename buttons)

Because Ai2 trims text blocks, I added a general purpose spaces function to get you that single space you wanted for the text JOIN building up the question in the textbox.

I recommend stretching out that textbox and making it a html textbox to allow the whole question to be visible.

Further thoughts ....

To save screen space for the question, I recommend making the WebViewer invisible until and answer arrives from the AI. Do the speech animation while the speech is being announced, then make it invisible again to make room for the question textbox.

I didn't realize how much garbage was coming out of the Speech Recognizer.

This cleared it up:

The new Project:


DraftEcoNova.aia (539.3 KB)

(API key removed to protect the OP - ABG)

1 Like

Once again, thank you sincerely for your help! It truly means a lot to me, especially as I’m working on improving my coding skills with your guidance and through MIT App.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.