On Jun 22, 9:18 pm, Mark Murphy <[email protected]> wrote:
> On Tue, Jun 22, 2010 at 12:04 PM, pranay <[email protected]> wrote:
> > hi, i have an app that responds to user the incoming sms via speech .
> > The app seems to work perfectly when it is lauched or even when i
> > press the back button on the emulator, however when i start a new
> > app , then i receive the new message only as a Toast (as shown in the
> > prgm below) but i cannnot hear any sound. I checked the logcat and
> > found that in this situation i get the error that : "null synthesis-
> > can't speak" .
>
> It is not safe to kick off anything that might take a while in a
> BroadcastReceiver, as it may cause your process to be terminated with
> the background equivalent of an application-not-responding error. At
> minimum, you need to move this to an IntentService and out of the
> BroadcastReceiver.
>
> It is also possible that speech synthesis can only be done by an
> Activity -- I have no idea if services can do it or not.
>
> Also, please bear in mind that the intent-filter you are presumably
> using for this application uses an action string that is not part of
> the Android SDK, and so your code may break in the future


i have tried the following ,

package com.example.TextSpeaker;

import java.util.Locale;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.util.Log;
import android.widget.Toast;


public class SpeakerService extends Service implements OnInitListener{

        //Receiver rv = new Receiver();
        //TextSpeaker tspker = new TextSpeaker();
        public static TextToSpeech mtts;
        @Override
        public IBinder onBind(Intent arg0) {
                // TODO Auto-generated method stub
                return null;
        }

        @Override
        public void onCreate(){
                //mtts =new TextToSpeech(getBaseContext(), null);
                Log.d("SpeakerService","Service created successfully!");
                mtts = new TextToSpeech(this,this);
                mtts.setLanguage(Locale.ENGLISH);
                //mtts.speak(rv.str, TextToSpeech.QUEUE_FLUSH,null);
                //TextSpeaker.mtts.speak(Receiver.str,
TextToSpeech.QUEUE_FLUSH,null);

        }
        @Override
        public void onStart(Intent intent,int startid)
        {
                Log.d("SpeakerService","Service started successfully!");
                Log.d("SpeakerService","Service started successfully!");
                //Log.d("SpeakerService","rv = " + rv.toString());
                //Log.d("SpeakerService","tspker = " + tspker.toString());
                Log.d("SpeakerService","tspker.mtts = " +
TextSpeaker.mtts.toString());
                mtts = new TextToSpeech(this,this);
                mtts.setLanguage(Locale.ENGLISH);
                //TextSpeaker.mtts.speak("Service started",
TextToSpeech.QUEUE_FLUSH, null);
                //TextSpeaker.mtts.speak(Receiver.str,
TextToSpeech.QUEUE_FLUSH,null);
                mtts.speak(Receiver.str, TextToSpeech.QUEUE_FLUSH,null);
        }
        @Override
        public void onDestroy(){
                if(mtts!=null)
                {
                        mtts.stop();
                        Toast.makeText(getApplicationContext(),"The service has 
been
destroyed!", Toast.LENGTH_SHORT).show();
                }

        }

        @Override
        public void onInit(int arg0) {
                // TODO Auto-generated method stub

        }

}

Now i am not able to hear any sound. but only receive the Toast
messages. the logcat says "ERROR/MediaPlayerService(30): Couldn't open
fd for content://settings/system/notification_sound  and also  unable
to create media player""

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to