java - Speak Failed Not Bound to TTS Engine -
so had original activity same exact code speaking, had move code activity. difference can tell text speech not called in asynchronous method. speaking occurs in speakfull method. these errors:
speak failed: not bound tts engine isspeaking failed: not bound tts engine i'm new android development, i've searched through other solutions problem, , can't seem find solution make mine work. advice, or appreciated.
code:
package com.example.webview; import android.os.bundle; import android.app.activity; import android.content.context; import android.content.dialoginterface; import android.content.dialoginterface.onclicklistener; import android.content.intent; import android.speech.tts.texttospeech; import android.text.method.scrollingmovementmethod; import android.view.menu; import android.view.view; import android.widget.button; import android.widget.textview; public class readout extends activity implements texttospeech.oninitlistener, onclicklistener { boolean paused = false; string lefttoread = null; string res = null; @suppresswarnings("deprecation") @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.read_out); intent intent = getintent(); res = intent.getextras().getstring("response"); textview textv = (textview) findviewbyid(r.id.textview1); textv.settext(res); textv.setmovementmethod(new scrollingmovementmethod()); android.view.display display = ((android.view.windowmanager)getsystemservice(context.window_service)).getdefaultdisplay(); textv.setheight((int)(display.getheight()*0.76)); lefttoread = speakfull(res); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. return true; } public string speakfull(string text){ system.out.println("speaking: " + text); texttospeech tts = new texttospeech(this, this); system.out.println("speaking"); string[] sentences = text.split("\n|\\.(?!\\d)|(?<!\\d)\\."); // regex splits body of text sentences of body stored in string array. for(int = 0; < sentences.length; i++){ if(!tts.isspeaking() && !paused){ system.out.println("speaking: " + i); tts.speak(sentences[i], texttospeech.queue_flush, null); }else if(paused){ system.out.println("paused"); string paused = ""; for(int j = - 1; j < sentences.length; j++){ paused += sentences[j]; } return paused; }else{ i--; } if(i == sentences.length - 1){ return "message 001: complete"; } } return null; } @override public void oninit(int arg0) { // todo auto-generated method stub } public void clickpause(view v){ if(paused){ paused = false; button b = (button) findviewbyid(r.id.button1); b.settext("play"); }else{ paused = true; button b = (button) findviewbyid(r.id.button1); b.settext("pause"); if(lefttoread == null){ lefttoread = speakfull(res); }else{ lefttoread = speakfull(lefttoread); } } } @override public void onclick(dialoginterface arg0, int arg1) { // todo auto-generated method stub } }
you can call speak() after oninit() called. move tts speak code in oncreate oninit()
@override public void oninit(int status) { if (status == texttospeech.success) { lefttoread = speakfull(res); } and initialize pause true boolean paused = true;
Comments
Post a Comment