Note that there are some explanatory texts on larger screens.

plurals
  1. POstarting text to speech engine from a service?
    primarykey
    data
    text
    <p>i have a service from where i am trying to start a TextToSpeech engine ,but it seems that it's not working , so is it possible to start tts from a service?</p> <p>here's what i've tried:</p> <pre><code>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{ public static TextToSpeech mtts; @Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub return null; } @Override public void onCreate(){ Log.d("SpeakerService","Service created successfully!"); mtts = new TextToSpeech(this,this); mtts.setLanguage(Locale.ENGLISH); } @Override public void onStart(Intent intent,int startid) { Log.d("SpeakerService","Service started successfully!"); Log.d("SpeakerService","Service started successfully!"); Log.d("SpeakerService","tspker.mtts = " + TextSpeaker.mtts.toString()); mtts = new TextToSpeech(this,this); mtts.setLanguage(Locale.ENGLISH); 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!", T oast.LENGTH_SHORT).show(); } } @Override public void onInit(int arg0) { // TODO Auto-generated method stub } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload