Lesson 31: How to Get Your Smartphone to Talk

 

Written by Jonathan Sim

Works on Android
You can find this lesson and more in the Arduino IDE (File -> Examples -> Andee). If you are unable to find them, you will need to install the Andee Library for Arduino IDE.

Did you know that you can make use of Android's Text-to-Speech (TTS) functionality to get the Annikken Andee to read to you?

Well, you can get it to do more than just read. It can make announcements or even report sensor readings so that you don't have to look at your phone!

Here's how!

Contents

Important Notice

If you do not hear anything from your phone, you will need to disable silent mode or check your phone's system volume settings.

If that does not work, you may need to manually configure Text to Speech.

To do this, go to the Andee app, and open "Settings." Scroll down and you should find a "Setup" button under the TTS section.

Top of the Code

#include <SPI.h>
#include <Andee.h>

AndeeHelper displaybox;
AndeeHelper button;
AndeeHelper speechObject; // You need to create a speech object for the phone to talk

setup()

void setup()
{
  Andee.begin();  // Setup communication between Annikken Andee and Arduino
  Andee.clear();  // Clear the screen of any previous displays
  setInitialData(); // Define object types and their appearance
}

setInitialData()

void setInitialData()
{
  displaybox.setId(0);
  displaybox.setType(DATA_OUT);
  displaybox.setTitle("Text to Speech");
  displaybox.setData("Be sure to unmute your phone to hear your phone talk!");  
  
  button.setId(1); // Don't forget to assign a unique ID number
  button.setType(BUTTON_IN); // Defines object as a button
  button.setLocation(1,0,FULL);
  button.setTitle("Say something!");
  button.setColor(THEME_RED_DARK);
  
  speechObject.setId(2);
  speechObject.setType(TTS); // Defines object as a Text-to-Speech object
}

loop()

void loop()
{
  if( button.isPressed() )
  {
    button.ack();
    // Use updateData() to get the phone to talk!
    speechObject.updateData("Confucius say: Man run in front of car get tired,"); 
    speechObject.updateData("man run behind car get exhausted."); 
    // You will need to break your sentence into multiple lines if your lines are too long.
    // Each speech object can only handle up to 40 characters of text at a time.
    // Punctuation will also affect the way your phone vocalises the text.
  }
  
  displaybox.update();
  button.update();
  // Do not update the speechObject!
  
  delay(500); // Always leave a short delay for Bluetooth communication
}
comments powered by Disqus