Mobile apps with App Inventor
Talk Back
Make your first app: type anything, tap a button, and the phone reads it out loud.
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
Step 1: Start the project
Open App Inventor, click Projects, then Start new project, and call it
TalkBack.App InventorCreate new App Inventor projectTalkBackCancelOKCall the project TalkBack, then click OK. 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.App InventorMy ProjectsGuidePaletteSearch Components...User InterfaceButton?CheckBox?DatePicker?Image?Label?ListPicker?ListView?Notifier?PasswordTextBox?Slider?Spinner?Switch?TextBox?TimePicker?WebViewer?LayoutMediaDrawing and AnimationMapsSensorsSocialStorageConnectivityLEGO® MINDSTORMS®ExperimentalExtensionViewerDisplay hidden components in Viewer9:41Talk BackComponentsScreen1RenameDeletePropertiesScreen1 (Screen)AboutScreenAccentColorDefaultAlignHorizontalCenter : 3AlignVerticalTop : 1AppNameTalkBackBackgroundColorDefaultIconNone...PrimaryColorDefaultScreenOrientationUnspecifiedSizingResponsiveThemeDevice DefaultTitleTalk BackTitleVisibleScreen1's AlignHorizontal and Title, changed. 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 itand FontSize to20.App InventorMy ProjectsGuidePaletteSearch Components...User InterfaceButton?CheckBox?DatePicker?Image?Label?ListPicker?ListView?Notifier?PasswordTextBox?Slider?Spinner?Switch?TextBox?TimePicker?WebViewer?LayoutMediaDrawing and AnimationMapsSensorsSocialStorageConnectivityLEGO® MINDSTORMS®ExperimentalExtensionViewerDisplay hidden components in Viewer9:41Talk BackType something and I will say itComponentsScreen1Label1RenameDeletePropertiesLabel1 (Label)BackgroundColorNoneFontBoldFontItalicFontSize20FontTypefacedefaultHTMLFormatHasMarginsHeightAutomaticWidthAutomaticTextType something and I will say itTextAlignmentleft : 0TextColorDefaultVisibleDrag a Label onto the phone, then set its Text and FontSize. 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.App InventorMy ProjectsGuidePaletteSearch Components...User InterfaceButton?CheckBox?DatePicker?Image?Label?ListPicker?ListView?Notifier?PasswordTextBox?Slider?Spinner?Switch?TextBox?TimePicker?WebViewer?LayoutMediaDrawing and AnimationMapsSensorsSocialStorageConnectivityLEGO® MINDSTORMS®ExperimentalExtensionViewerDisplay hidden components in Viewer9:41Talk BackType something and I will say itType hereComponentsScreen1Label1TextBox1RenameDeletePropertiesTextBox1 (TextBox)BackgroundColorDefaultEnabledFontBoldFontItalicFontSize14.0FontTypefacedefaultHeightAutomaticWidthFill parentHintType hereMultiLineNumbersOnlyReadOnlyTextTextAlignmentleft : 0TextColorDefaultVisibleA TextBox under the label, as wide as the screen. Step 5: Add a button
Drag a Button under the text box, and change its Text to
Say itand its FontSize to18.App InventorMy ProjectsGuidePaletteSearch Components...User InterfaceButton?CheckBox?DatePicker?Image?Label?ListPicker?ListView?Notifier?PasswordTextBox?Slider?Spinner?Switch?TextBox?TimePicker?WebViewer?LayoutMediaDrawing and AnimationMapsSensorsSocialStorageConnectivityLEGO® MINDSTORMS®ExperimentalExtensionViewerDisplay hidden components in Viewer9:41Talk BackType something and I will say itType hereComponentsScreen1Label1TextBox1Button1RenameDeletePropertiesButton1 (Button)BackgroundColorDefaultEnabledFontBoldFontItalicFontSize18FontTypefacedefaultHeightAutomaticWidthAutomaticImageNone...ShapedefaultShowFeedbackTextSay itTextAlignmentcenter : 1TextColorDefaultVisibleA Say it button. 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.
App InventorMy ProjectsGuidePaletteSearch Components...User InterfaceLayoutMediaCamcorder?Camera?ImagePicker?Player?Sound?SoundRecorder?SpeechRecognizer?TextToSpeech?Translator?VideoPlayer?Drawing and AnimationMapsSensorsSocialStorageConnectivityLEGO® MINDSTORMS®ExperimentalExtensionViewerDisplay hidden components in Viewer9:41Talk BackType something and I will say itType hereNon-visible componentsTextToSpeech1ComponentsScreen1Label1TextBox1Button1TextToSpeech1RenameDeletePropertiesTextToSpeech1 (TextToSpeech)CountryLanguagePitch1.0SpeechRate1.0TextToSpeech1 appears under the phone, with the non visible components. Step 7: Make the button talk
Click Blocks at the top right. Then build this with three blocks:
- Click Button1 in the Blocks panel and drag when Button1.Click into the workspace.
- Click TextToSpeech1 and drag call TextToSpeech1.Speak inside it, so it clicks into place next to do.
- 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.
App InventorMy ProjectsGuideBlocksBuilt-inControlLogicMathTextListsDictionariesColorsVariablesProceduresScreen1Label1TextBox1Button1TextToSpeech1Any componentRenameDeleteShow Warningswhen Button1.Clickdowhen Button1.GotFocusdowhen Button1.LongClickdowhen Button1.LostFocusdoClick Button1 (1), then drag when Button1.Click into the workspace (2). App InventorMy ProjectsGuideBlocksBuilt-inControlLogicMathTextListsDictionariesColorsVariablesProceduresScreen1Label1TextBox1Button1TextToSpeech1Any componentRenameDeleteShow Warningswhen Button1.Clickdocall TextToSpeech1.SpeakmessageTextBox1.TextThe 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.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!
9:41Talk BackType something and I will say itHello, Coding Club!Hello, Coding Club!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.
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.
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.Clickblock. Put a pink text block with your greeting in the message socket.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
- 15 minutes: everyone signed in and the project started. This always takes longer than you expect the first time.
- 20 minutes: steps 2 to 6, the Designer.
- 15 minutes: steps 7 and 8, the blocks and the phone.
Mistakes to look out for
- 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.
- The wrong TextBox1 block: the light green getter TextBox1.Text, not the dark green setter.
- 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.
- 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.