[英]Text to Speech is not working during an incoming call in android
我想在通話過程中以語音播放文本序列,將鈴聲降低幾秒鍾。 我已經通過意圖將字符串從廣播接收器發送到另一個類文件。 如果在通話期間在吐司中使用該文本,則會顯示該文本,但語音不會播放。 在我的班級文件中用於文本語音轉換的代碼是:-
public class callName extends Activity {
String call;
TextToSpeech tts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
call = extras.getString("sms");
tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
// TODO Auto-generated method stub
if (status != TextToSpeech.ERROR) {
tts.setLanguage(Locale.US);
}
}
});
Toast.makeText(getBaseContext(), call, Toast.LENGTH_LONG).show();
tts.speak(call, TextToSpeech.QUEUE_FLUSH, null);
}
}
調用語音時tts尚未初始化,您必須將onInit()
代碼onInit()
tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
// TODO Auto-generated method stub
if (status != TextToSpeech.ERROR) {
tts.setLanguage(Locale.US);
tts.speak(call, TextToSpeech.QUEUE_FLUSH, null);
}
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.