Speech Recognizer - Talking Calculator

695 views
Skip to first unread message

SteveJG

unread,
Jul 16, 2017, 1:13:13 PM7/16/17
to mitappinv...@googlegroups.com
TalkingCalculator is the bare bones code to create a calculator you can speak to.  It will make a calculation based on what you tell it to do and provide (speak to you with) the correct answer (usually).


The code has to be run on a real device (it will not run on the emulator) because of the SpeechRecognizer object is not supported on the emulator.





'Train' the SpeechRecognizer to your voice.  Take a deep breath and say everything you want to say in a single sentence, keeping a steady cadence.  For example, say 98 point 3 times 7 point 2 equals    instead of     98.3          times         7.2         equals  .   If the app has trouble understanding, say something simple...like perhaps   10 plus 5 equals and see what happens.

TalkingCalculator understands only four Math operations at the moment.  Add as many additional operations as you want.  If you add a lot more realize soon you may be requesting more processing in the afterspeech event handler than App Inventor's asynchronous processing will allow without errors.   The Android Speech Recognizer is fairly smart but is not brilliant.  It recognizes you are working with numbers IF you start the request (ASK) with a numeral.  If you pause too long between numbers and words, it will mess up.

The app itself is presently pretty dumb, all it does is parse the spoken text into a LIST and it assume the user knows how to speak to it;  say first number, say the operator, say the second number then say equals or not (saying equals is not totally necessary but it makes it easier to say the instructions.  It has limited error control capability...If you do not provide two numbers and an operator, the app will balk.

The app  takes two values and provides a mathematical operation on them.  It places the first number mentioned in the red text box (TextBox1) and the subsequent number in the blue text box (TextBox2). It looks for a mathematical operator ( +, -, * or / ) .  These operators must be spoken as 
+ plus
-  minus or   subtract 
* times 
/ divide  or divided
. point
and equals

Other words can be used however the SR will only know the words you provide.  You cannot provide an operator like   "divided by" because this is two 'words' and the parsing separates based on spaces.  A developer can re-coded the behavior to accept a spoken "divided by" but is not done in this example.  Of course, if you are not in North America and other places where the decimal separator is a point or period ( . ) you will need to provide a comma equivalent.  You will need the equivalents of plus, minus, divide , minus in your language (or the language your Android understands).

The app runs very well on a Tablet; the SpeechRecognizer on my phone has some issues and it is necessary to occasionally repeat a request.  I expect it is because the Tablet has better hardware and cpu.   Your experience might be different.  The Google Android SR is very fussy and the coding set is limited.

Regards,
Steve
MathSpeech.aia

Tim Carter

unread,
Jul 16, 2017, 3:00:19 PM7/16/17
to MIT App Inventor Forum
Great fun - well done!  :)
Message has been deleted

Shivendra Kr. Sahu

unread,
Jul 17, 2017, 1:15:43 PM7/17/17
to MIT App Inventor Forum
When I ran this application, I received a message like this.

My phone is Samsung Galaxy J7 Prime

Abraham Getzler

unread,
Jul 17, 2017, 2:24:30 PM7/17/17
to MIT App Inventor Forum
This reminds me of the old Abbott and Costello comedic routine where 
Costello is a door to door vacuum cleaner salesman in the 
country, and he dumps dust on a housewife's carpet
over her objections, claiming it will
suck up all the dust or he will eat it.

She hands him a spoon and tells him she has no electricity.

You have to find a speech recognition app for your phone
and install it.

ABG


SteveJG

unread,
Jul 17, 2017, 4:01:40 PM7/17/17
to MIT App Inventor Forum
@Shivendra  I do not know what the issue is on your Samsung Galaxy J7 Prime.

Here are some things you might do to get it to run on your device.  The app runs fine on most devices so it would be interesting to note what is different about your Samsung.


1) It might not use the 'standard' Google Speech Recognition engine.  This Samsung device may have its own speech recognition engine .
When you press the ASK button, do you see 

a screen something like this?   If not, TalkingCalculator is not finding the Google Speech Recognizer.


2)  If you do see that screen, do you speak in English?   and is your phone set for English or Hindi?     It's gotta be set to English.  If you do not see 
the Speech icon, then it is probably that the App Inventor 2 SR component is incompatible with that device , especially if you do not see that screen  or 
the error message appears as soon as TalkingCalculator is installed.

3) It is possible your phone does not have a TextToSpeech app enabled . The app needs a text-to-speech engine (it can be download it from Google Play).  The TTS language 
and your device language have to be the same.  The lack of a TTS could be the reason  the error message does indicate 
RECOGNIZE_SPEECH, not Speech Recognizer. The presence of the TTS could be the issue.   You could delete the TTS component.  The TTS is used to have the device speak the math answer. 


and delete the two occurrences of this block , rerun the modified code and try again.



Alternatively you could  download Google's Text to Speech engine from the Playstore (because it might not be installed on your device).



4)Something else is causing issues.  In the aia, the Screen Sizing is set to Fixed ... perhaps change that to Responsive.   That should not be an issue but it might
be a contributing factor.

Is any of this helpful?    Did you get TalkingCalculator running?

Regards,
Steve

Shivendra Kr. Sahu

unread,
Jul 17, 2017, 5:53:34 PM7/17/17
to MIT App Inventor Forum
I carefully checked your phone and found that my phone is already Google's Text to Speech engine and it is working properly in Google translator.
And one thing I noticed is that no request has been received from all the applications in the application of the camera to do it, microphone use, etc.
But this application has not asked for any permissions.
Reply all
Reply to author
Forward
0 new messages