Simple wearable projects with your Android phone

Tech on Tap

© Lead Image © Andrey Simonenko, 123RF.com

© Lead Image © Andrey Simonenko, 123RF.com

Article from Issue 218/2019
Author(s):

Create some interesting wearable projects with an Android device, an armband case, headphones, and MIT's free App Inventor package.

A wearable solution with voice recognition and speech-to-text capabilities can be used by anyone who needs information while their hands are busy or when they can't take their eyes away from their current task. Some examples include recipes for chefs, instruction manuals for mechanics, or directions for a cyclist.

In this article, I create an Android application that recognizes a spoken keyword that is searched in a text file; text-to-speech software echoes the result of the search. To create the Android app, I use MIT's App Inventor package, a free web-based Android app development tool you can use to create applications in a graphical environment.

For this project, you need a smartphone armband case and a set of headphones with a built-in microphone (Figure 1), as well as a Google user account [1] and a desktop or laptop computer to use App Inventor.

Figure 1: Hardware needed for this project: an Android smartphone mounted in an armband and headphones with a mic.

App Inventor

App Inventor [2] is a web-based app creation tool for Android devices with a graphical programming environment. App Inventor has two main screen modes: In Designer mode, you lay out the Android app in the Viewer screen, and in Blocks mode, you build the logic. On the right side of the top menubar, the Designer and Blocks buttons allow you to toggle between these two modes.

In Designer mode, you create an app layout by dragging a component from the Palette window onto the Viewer window. For the visuals on this application, you will use the following components from the User Interface section of the Palette: Button, which initiates speech recognition, Label, which first shows the Hit the Talk Button message and then shows the result of the speech recognition, and ListView, which shows the lines of the data file.

Also, you need some non-visual components. In the Media section of the Palette, drag the SpeechRecognizer and TextToSpeech components into the Viewer window and add the File component from the Storage group (Figure 2).

Figure 2: App layout.

The Components window lets you rename or delete components. When you select a component, the Properties window shows the component's editable features. In this example, I renamed the button BT_Speak and changed the BackgroundColor, FontSize, Width, and Text fields from their defaults (Figure 3).

Figure 3: App components and properties.

Logic

Once the layout design is complete, you can add logic by clicking on the Blocks button in the top menubar. Logic is built by selecting an object in the Blocks window and then clicking on the specific block you want to use (Figure 4).

Figure 4: Logic blocks added to the Viewer window after clicking Screen1, the current project.

App Inventor is pretty amazing when it comes to fast prototyping. This entire app only requires one variable and four when blocks (Figure 5). The first step is to load the text file by calling the when Screen1.Initialize block. The when File1.GotText block loads the text file data into the global variable (THELIST) and populates the ListView component.

Figure 5: Logic blocks filled out for the current project.

The when BT_Speak.Click block is activated on a button push and starts the speech recognition block. The final block, when SpeechRecognizer1.AfterGettingText, shows the result of the speech recognition in a label and it checks whether it is in the global variable. If the result is found, a text-to-speech message is generated with the full line of text.

Data File

The data file I used, places.txt, is a list of some local landmarks, but you could use a number of other data choices, such as friends' addresses, recipe ingredients, or favorite restaurants. For readability, I recommend you put the keywords at the beginning of each line; for example:

"Hope Bay has a sandy beach with..."
"The Glen is a horseshoe-shaped valley..."
"Isaac Lake is a bird sanctuary with..."
"Oliphant is great for kite surfing..."
...

For this example, the file was saved in the Android's Download directory; this location needs to match the fileName entered in the File1.ReadFrom block definition (i.e., /Download/places.txt) in the first when block.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News