小编Ran*_*vis的帖子

在服务中运行Android TTS

我试图让Android的TTS在服务中运行,但我不知道它为什么不工作,它编译,不会崩溃,但它只是不起作用.

吐司通知确实有效.

package alarm.test;

import android.app.Service;
import com.google.tts.TextToSpeechBeta;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;

public class MyAlarmService extends Service {

    private TextToSpeechBeta myTts;
    private TextToSpeechBeta.OnInitListener ttsInitListener = new TextToSpeechBeta.OnInitListener() {
        public void onInit( int arg0, int arg1 ) {
            myTts.speak("", 0, null);
        }
    };

@Override
public void onCreate() {
 // TODO Auto-generated method stub
    myTts = new TextToSpeechBeta( this,
            ttsInitListener );

 Toast.makeText(this, "MyAlarmService.onCreate()", Toast.LENGTH_LONG).show();
}

@Override
public IBinder onBind(Intent intent) {
 // TODO Auto-generated method stub
    myTts.speak("something is working", TextToSpeechBeta.QUEUE_FLUSH, …
Run Code Online (Sandbox Code Playgroud)

android text-to-speech android-service

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

android ×1

android-service ×1

text-to-speech ×1