Mobile apps with App Inventor

Talk Back

Make your first app: type anything, tap a button, and the phone reads it out loud.

Day 1 45 to 60 minutes 8 steps Key Stage 3
Start step 1
Type, tap Say it, and the phone reads it out.

Today you will build a real app and run it on a phone. It is simple and surprisingly fun: whatever you type, the phone says out loud. You will design the screen by dragging, then make it work by snapping blocks together, with no typing of code at all.

You will learn

  • Design a screen with a Label, a TextBox and a Button
  • Change a component's properties
  • Make a button do something with an event block
  • Test an app on a real phone

You will need

  • A computer with a web browser
  • A phone or tablet with the free MIT AI2 Companion app
  • A Google account, or an App Inventor revisit code

Words to know

component
A part of an app: a button, a label, a sensor, a voice.
property
A setting of a component, such as its Text or its FontSize.
event
Something that happens, such as a click, which runs the blocks inside it.
non visible
A component with nothing on the screen, such as TextToSpeech.

Step by step

  1. Step 1: Start the project

    Open App Inventor, click Projects, then Start new project, and call it TalkBack.

    Call the project TalkBack, then click OK.
  2. Step 2: Set up the screen

    Click Screen1 in the Components list to choose it. In Properties, change Title to Talk Back, the words in the bar at the top of the app, and set AlignHorizontal to Center, so everything lines up down the middle.

    Screen1's AlignHorizontal and Title, changed.
  3. Step 3: Add a label

    A Label shows words. Drag a Label from the User Interface drawer of the Palette onto the phone in the Viewer. Then, in its Properties, change Text to Type something and I will say it and FontSize to 20.

    Drag a Label onto the phone, then set its Text and FontSize.
  4. Step 4: Add a text box

    A TextBox is a box to type in. Drag one under the label. Set its Hint, the grey words that show before you type, to Type here, and its Width to Fill parent, so it stretches across the screen.

    A TextBox under the label, as wide as the screen.
  5. Step 5: Add a button

    Drag a Button under the text box, and change its Text to Say it and its FontSize to 18.

    A Say it button.
  6. Step 6: Give the app a voice

    Open the Media drawer of the Palette and drag a TextToSpeech onto the phone. It is a non visible component: it has no button or box on the screen, so it shows up under the phone instead.

    TextToSpeech1 appears under the phone, with the non visible components.
  7. Step 7: Make the button talk

    Click Blocks at the top right. Then build this with three blocks:

    1. Click Button1 in the Blocks panel and drag when Button1.Click into the workspace.
    2. Click TextToSpeech1 and drag call TextToSpeech1.Speak inside it, so it clicks into place next to do.
    3. Click TextBox1 and drag the TextBox1.Text block (light green) into the message socket.

    In words: when the button is clicked, speak whatever is in the text box.

    Click Button1 (1), then drag when Button1.Click into the workspace (2).
    The finished blocks: click, then speak the text box's text.
    Tip Getters, which read a property, are light green. Setters, which change one, are dark green.
  8. Step 8: Try it on your phone

    Connect your phone with Connect then AI Companion, as in the setup steps. Type something in the box and tap Say it. Turn the volume up!

    Type, tap Say it, and the phone reads it out.

Test it

Tick each one when it works. If one does not, look back at the step it comes from.

Stretch challenges

Finished early? Try these. Each one has a hint if you get stuck.

  1. A different voice

    Make the voice higher and faster.

    Show a hint

    Choose TextToSpeech1 in the Designer. Pitch and SpeechRate go from 0 to 2: try 1.5 for each.

  2. A hello button

    Add a second button that always says hello to you by name.

    Show a hint

    A new Button, and a new when Button2.Click block. Put a pink text block with your greeting in the message socket.

  3. Clear the box

    Empty the text box after the phone has spoken.

    Show a hint

    Under the Speak block, add set TextBox1.Text to with an empty text block.

Notes for the teacher

Timing

  1. 15 minutes: everyone signed in and the project started. This always takes longer than you expect the first time.
  2. 20 minutes: steps 2 to 6, the Designer.
  3. 15 minutes: steps 7 and 8, the blocks and the phone.

Mistakes to look out for

  1. A block dropped near, but not inside, the event block: it stays apart and does nothing, and a warning triangle appears on it. Drag it until it clicks.
  2. The wrong TextBox1 block: the light green getter TextBox1.Text, not the dark green setter.
  3. The Companion will not connect: check the phone and the computer are on the same WiFi, and that the school network allows it. The emulator (Connect, then Emulator) is a fallback on Windows, after installing the aiStarter software.
  4. No sound: the phone's media volume is down, or a silent switch is on.

Accounts

App Inventor needs a Google account, such as a school Google Workspace account. Without one, students can use Continue Without An Account at code.appinventor.mit.edu, which gives a revisit code. Keep a list of the codes yourself: a lost code means lost projects.