HOW TO: Program the native SpeechRecognizer for Continuous Dictation and to do things

parrot
HOW TO: Program the native SpeechRecognizer for continuous dictation and to do things is an example app that shows how to make the native SpeechRecognizer work. It is not a step by step tutorial.

The SpeechRecognizer tutorial example is Speech Recognizer Parrot. Use voice commands to do different things; command something to happen, use it as a typewriter. amaze your children etc. Parrot can provide continuous recognition (more or less) or not depending on how you use it and how you talk to it. It is just like (almost) talking to a Parrot. Say something and Parrot repeats it. Make Alexa? No,it is not that amazing. The Parrot can do some things that Alexa can do despite utilizing much simpler technology. The code uses no extensions, just the native SpeechRecognizer and a TextToSpeech component.

How to Use it

Three ways:

  • The app prompts the user to speak with a beep, once every 10 seconds by using a Clock to schedule user responses. The user can say a single word or a longer phrase.
  • Parrot can run automatically (turn automatic on) without prompts (sorry, that feature has issues). The recognizer stops listening if you wait too long to respond after hearing a prompt. The fix, touch the Speak another word Button when it goes stupid or do not pause too often will coddle it to understand what you say to it.
  • Run it one command at a time. Set Automatic off and Use Timer to off. Touch the Speak another word when you want to talk and say a word or phrase.

What it can do

  • Parrot can be ‘programmed’ to do things. As shown, Parrot can, change the color of a button. It knows two commands: turn button red or turn button blue; say turn the button red and Parrot will ignore you (unless you provide code to ignore the word “the”). You must say exactly what you code to make it respond or to provide code that allows departure from the script.
  • Talking to it currently fills a list; re-purpose Parrot to type a letter or note by writing to a Label instead of a List. You might disable the Parrot response by changing the source code.
  • The example works using English. To get Parrot to perform for you on your French or Spanish enabled device, you may have to set the language and country settings. See the component documentation: * SpeechRecognizer

How to avoid mistakes

  • Experiment with the various Parrot option choices until you find something the fits your speeking/dictation style. - A secret to making a Speech Recognizer work is to speak in a strong, steady, clear voice. Even then, the Parrot recognizer WILL make mistakes.
  • I show one way to delete words Parrot misspeaks…type the word that must be eliminated, press Delete or use the Delete Last of to delete the last spoken text.
  • There are a few grayed out Blocks of code at the top of the AfterGettingText event handler. Restore the Blocks and these or similar blocks can be used when the SpeechRecognizer is stubborn. Yes, sometimes it refuses to provide the word you speak. For example, if you do not want to record 2 when you say 2 but to print out two or to respond with for when it thinks you say four, you make it obey when it mis-understands your pronunciation.

Improve this simple app
Parrot is not a complete app; it shows some techniques. Its certainly is not Alexa (which is incredibly complicated software and only available by subscription). Parrot records what is said to it in a List (which is copied to a ListView).

  • Use event handlers to ask the app to do things by using appropriate coded phrases with additional coding (conditional statements).
  • I coded Parrot to place spoken text in a List, feel free to post it to a Label or where ever.
  • I did not code a Stay Awake routine (use the forum Search and google StayAwake for ideas). Why? App Inventor apps do not run in the background (as a Service). To keep them in the foreground, the developer has to program something to prevent the screen from closing (go to sleep). A solution is StayAwake****strong text.
  • If the example does not do what you want it to do either change how you talk to Parrot and/or make appropriate coding changes to the existing code.

The Parrot example is not perfect. This small app demonstrates what can be accomplished with the native SpeechRecognizer control. The app screen is configured to run on a tablet. If you run Parrot on a phone, you may have to change the placement of controls. Its ability to recognize what you say depends on the hardware and operating system it is run on. This app tested well on a Samsung A10 Android 8.1 tablet, performance was less enlightening on an Android 4.2.2. Your performance in your usage most certainly will be different and hopefully similar.

This is an advanced tutorial. That means everything (well, most things) is not explained. It takes three to for times the development time to document everything.

Can something similar be coded with other tools?

  • Certainly. There are several extensions that might provide additional control of the recognizer tool. None of them to allow you the flexibility you could achieve using the professional Android Studio.
  • Android Studio has the full libraries for maximum utilization of this Google Tool. App Inventor 2 provides only a subset of the controls that can be used to program the Google Speech Recognizer.

Parrot.aia (16.4 KB)

I hope this helps you to code the native SpeechRecognizer tool to do what you want it to do.

Regards,
Steve

3 Likes