This tutorial shows you how to extend the basic TalkToMe app so that it responds to shaking, and so that the user can make the phone say any phrase s/he types in.
Go to App Inventor on the web and log in.
Go to App Inventor on the web and log in.
Open the “TalkToMe” project that you worked on in the last tutorial.
App Inventor will always open the last project you worked on, so you may automatically be taken into your TalkToMe app.
Go to the Designer Tab
Your project may open in the Designer. If it does not, click “Designer” in the upper right
Add an Accelerometer Sensor
In the Sensors drawer, drag out an AccelerometerSensor component and drop it onto the Viewer. (It’s a non-visible component, so it drops to the bottom of the screen.) NOTE: emulator users should skip this part and proceed to the next section of this tutorial called “Say Anything”. (The emulator can not respond to shaking!)
Go to the Blocks Editor
Click “Blocks” to program the new Accelerometer Sensor that you just added.
Program the Accelerometer Shaking event
Click the AccelerometerSensor1 drawer to see its blocks. Drag out the when
AccelerometerSensor1.Shaking do block and drop it on the workspace.
What do we want the app to do when the accelerometer detects shaking?
Copy and paste the blocks that are currently inside the when Button1.Click event handler. You can select the purple block, then hit the key combination on your computer to copy and then to paste. You’ll have a second set of blocks to put inside the when Accelerometer.Shaking block.
(Alternatively, you can drag out a new call TextToSpeech1.Speak block from the TextToSpeech
drawer, and a new pink text block from the Text drawer.)
Change the phrase that is spoken when the phone is shaking.
Type in something funny for when the phone responds to shaking.
Test it out!
You can now shake your phone and it should respond by saying “Stop shaking me!” (or whatever
phrase you put in.)