4

I have an application that according to some events, changes a normal notification to text-to-speech in order to since sometimes the phone isn't available to users, and it'll be safer not to handle the phone.

For example, when you're driving, this is dangerous, so i want to turn the notifications to text-to-speech. I've looked for a long time some explanation for turning text-to-speech when driving, but i can't find any reference for that no where i search.

For generating text-to-speech, i have this part, which works fine :

private TextToSpeech mTextToSpeech;

public void sayText(Context context, final String message) {

    mTextToSpeech = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            try {
                if (mTextToSpeech != null && status == TextToSpeech.SUCCESS) {
                    mTextToSpeech.setLanguage(Locale.US);
                    mTextToSpeech.speak(message, TextToSpeech.QUEUE_ADD, null);
                }
            } catch (Exception ex) {
                System.out.print("Error handling TextToSpeech GCM notification " + ex.getMessage());
            }
        }
    });
}

But, i don't know how to check if i'm currently driving or not.

JenniferH
  • 95
  • 6

2 Answers2

2

In order to know whether you are driving or not you can use Activity Recognition API

Here is a great tutorial that might help you out Tutorial and Source Code

Ashwin Prasad
  • 108
  • 3
  • 11
2
  1. As Ashwin suggested, you can use Activity recognition Api, but there's a downside of that, the driving samples you'll receive, has a field of 'confidence' which isn't always accurate, so you'll have to do extra work(such as check locations to see if you actually moved) in order to fully know if the user moved.
  2. You can use google's FenceApi which allows you to define a fence of actions such as driving, walking, running, etc.
    This api launched recently. If you want a sample for using it, you can use this answer.
  3. You can pull this git project (everything free), which does exactly what you want : adds to the normal notification a text-to-speech when you're driving.
Community
  • 1
  • 1
Dus
  • 4,052
  • 5
  • 30
  • 49