Не удалось установить связь с двигателем TTS
Таким образом, у меня была оригинальная деятельность с в основном тем же самым точным кодом для разговора, но я должен был перенести этот код в другую деятельность. Единственное отличие, которое я могу сказать, состоит в том, что текст в речь не вызывается в асинхронном методе. Разговор происходит в методе talkFull. Я получаю эти ошибки: я
speak failed: not bound to TTS engine
isSpeaking failed: not bound to TTS engine
Я новичок в разработке Android, яя искал другие решения этой проблемы, и я могуКажется, я действительно нашел решение, чтобы заставить мою работу. Любой совет или помощь приветствуется.
Код:
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 the menu; this adds items to the action bar if it is 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)|(?