Friday, February 18, 2011

App Inventor sample project: Voice to Text and vice-versa

I'm back with another App Inventor tutorial for you. This time around, I have a simple tutorial that demonstrates an app that is able to convert your voice to text and, in turn, that text back to voice. Google does all of the heavy lifting in regards to converting voice and text, and thankfully makes it very easy to tap into those resources.

Let's get started...

1. Click on My Projects, then create a new project. I called mine VoiceApp.

2. You will now see the layout screen with Palette, Viewer, Components, Media and Properties boxes. Adding components is easy by dragging objects from the Palette box onto the Viewer.

3. Now drag a Button from the left column under Basic onto the palette. Select the button in the Components column and click Rename to change the name to VoiceToTextButton. Then, in the Properties column, set the Text to "Voice to Text."

4. Next, drag in a Label and place below the VoiceToTextButton. Rename the label to ResultLabel and set the Text field to "".

5. Drag in another Button and place below ResultLabel. Rename to TextToVoiceButton and set Text field to "Text to voice."

6. Now, expand the Other Stuff tab in the left column and drag two final components onto the palette: SpeechRecognizer and TextToSpeech. NOTE: These are non-visible components and so will appear below the palette.

Your screen should now look like this:

7. Now connect your Android phone via usb. On your phone, go to Settings-->Applications-->Development. Enable USB debugging and Stay awake.

8. On the layout screen click the button to Open the Blocks Editor. This will open a Java applet that contains all of the logic blocks/action handlers and interfaces with your phone.

9. In the Blocks Editor, create the following code:

We need to handle the Voice to text button click event first. In this, we simply tell the SpeechRecognizer1 to start listening. The BeforeGettingText function clears our label so the words spoken can be displayed there. The AfterGettingText function sets our label to the words spoken.

10. To go the other way--text to voice--we handle the click event of the other button. TextToSpeech1.Speak has an output parameter that we set to our label.text field.

In order for this component to work, the device must have the TTS Extended Service app by Eyes-Free Project installed. You can download this from

So there's the code (layout and blocks) required for building a simple voice-to-text and text-to-voice application.

Download this application onto your phone by scanning this code:


  1. Hi my friend, great tutorials I must say!
    I'm working on a "co workers phonebook". I'm sick of filling my personal phonebook with 100 of CO's and I've been trying to make my "CO phonebook" using the list pickers but the only thing I can do is text, I want to have the list + the phonecall function. Cant sort it out, I'd be greatful if you had any tip for me or even better, show me some blocks in the block editor 8)

    Best regards Nicklas

  2. Hi Nicklas,

    You may find this tutorial helpful for making phone calls.

    - tk

  3. i want to convert speech to text... so i done but dont work... pls help me...and list the code....

  4. how can i do a project like put the word hello in press a translate button and changes to another word.

  5. Sorry for the silly question but how do you get the Text block with just Text and no drop down? Thanks tons

  6. This comment has been removed by the author.

  7. In many ways Voice Actions for Android is very similar to the Vlingo for Android product—just by pushing a widget button on the home screen you can speak to your Android phone and have Voice Actions turn your words into actions. Just like Vlingo you can speak to send a text message or an email, navigate to a business location, search the web, and much more. The Voice Actions business dialing feature is very similar to Vlingo’s SuperDialer—you just say “call ” such as “call Blue Ribbon Barbecue” and Voice Actions dials the business for you. It even goes farther in some areas—my favorite is setting the alarm clock on the phone just by speaking “Set alarm for 8 am.”

  8. hi guys!my name is mahmoud and am from africa, i need help on my project and its important. can somebody please contact me via my mail for mentorship. thanks in advance.

  9. Hi,
    Is it possible to create Text/String to Sound?
    The text is base64 format of an encrypted text or string.

    and vice versa from sound to encrypted string which then will be passed to a function to decrypt the text/string?


  10. Congratulations guys, quality information you have given!!!..Its really useful blog. Thanks for sharing this useful information
    |Best Android Training in Velachery | android development course fees in chennai

  11. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.Android Training in chennai | Best Android Training in chennai