从服务开始文本到语音引擎? [英] starting text to speech engine from a service?
本文介绍了从服务开始文本到语音引擎?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经从那里我试图启动一个TextToSpeech引擎服务,但它似乎不工作,所以是有可能从服务开始TTS?
这是我已经试过:
包com.example.TextSpeaker;
进口java.util.Locale中;
进口android.app.Service;
进口android.content.Intent;
进口android.os.IBinder;
进口android.speech.tts.TextToSpeech;
进口android.speech.tts.TextToSpeech.OnInitListener;
进口android.util.Log;
进口android.widget.Toast;
公共类SpeakerService扩展服务实现OnInitListener {
公共静态TextToSpeech MTTS;
@覆盖
公众的IBinder onBind(意向为arg0){
// TODO自动生成方法存根
返回null;
}
@覆盖
公共无效的onCreate(){
Log.d(SpeakerService,服务创建成功!);
MTTS =新TextToSpeech(这一点,这一点);
mtts.setLanguage(Locale.ENGLISH);
}
@覆盖
公共无效ONSTART(意向意图,诠释startid)
{
Log.d(SpeakerService,服务启动成功!);
Log.d(SpeakerService,服务启动成功!);
Log.d(SpeakerService,tspker.mtts =+ TextSpeaker.mtts.toString());
MTTS =新TextToSpeech(这一点,这一点);
mtts.setLanguage(Locale.ENGLISH);
mtts.speak(Receiver.str,TextToSpeech.QUEUE_FLUSH,NULL);
}
@覆盖
公共无效的onDestroy(){
如果(MTTS!= NULL)
{
mtts.stop();
Toast.makeText(getApplicationContext(),服务已被摧毁!,T oast.LENGTH_SHORT).show();
}
}
@覆盖
公共无效的OnInit(INT为arg0){
// TODO自动生成方法存根
}
}
解决方案
新TextToSpeech(getApplicationContext(),这一点);
可与我... 但可以肯定,让服务运行,直到语音完成。
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?
here's what i've tried:
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
}
}
解决方案
new TextToSpeech(getApplicationContext(),this);
works with me... But be sure to let the service run , until speech is done..
这篇关于从服务开始文本到语音引擎?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文