Thursday, December 8, 2011

Read out SMS using Text to speech API

One day my colleague wanted me to write a small SMS app for her. The app would read out loudly the name of the sender and also the contents of the SMS. Well, she later changed her mind and said, "No, please don't read out the contents. Just the name of the sender would do". It was fun coding the app. There are so many Android apps available in the market which does the same thing. To tell you the truth, I was first happy to see my Google Nexus reading out the contents but hearing the audio every time the SMS arrives is little annoying. So I have conveniently decreased the media volume so that it doesn't bother me with all the junk SMS that I get all day. :)

Btw, I still have the content being read out. You may want to comment it out, if it infringes on your privacy. :D.

This app does not have an activity. Not required, anyway, isn't it?

There is TextToSpeechService which runs in the background and a SMSReceiver which extends Broadcast receiver. SMSReceiver, on receiving an intent of "android.provider.Telephony.SMS_RECEIVED" , triggers the TextToSpeechService which does all the talking. This is pretty much the summary.

You will see some hardcoding in the speakWords(...) method, E.g. StringBuffer buf = new StringBuffer("You have sms from....");

You may put all the hard-coding in the strings.xml. This is just a simple example. The app can be extended to look up the phone book and read out the sms only if the sender is in the contacts list.

I can mail you the source code if would like to play around. :)

3 comments:

  1. Hello,

    I want to try doing this.
    Can you please send me code for reference.
    My Email Id is : rakesh20004u@gmail.com

    Thanks a lot,
    Rakesh

    ReplyDelete
  2. Hello mam,

    I always refer your tutorial and i loved that so much...
    Plz send me the code for refernce bcoz my app is based on that...
    so plz help me..
    Email id:kadamnilesh4@gmail.com

    ReplyDelete
  3. Hi Ashimita,

    Its interesting and of course I am struggling with this now. Will you please help me by sending the codes. I am on the way of creating an app that reads the content of sms. Plz mail me at: tonythampi1@gmail.com

    ReplyDelete