Я пытаюсь создать такое приложение, которое автоматически говорит, когда изображение загружается само.
Я пробовал одно приложение (пример) TTS, которое работает правильно, но этот код дает мне
Служба «Мой код - текст в речь» не запущена.
public class show_image extends Activity implements TextToSpeech.OnInitListener {
Intent mIntent;
String value;
ImageView mImageView;
private TextToSpeech tts;
int j;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mIntent = getIntent();
Bundle b = getIntent().getExtras();
final String name = b.getString("name");
j = name.toCharArray()[0];
tts = new TextToSpeech(this, this);
tts.speak("Welcome", TextToSpeech.QUEUE_ADD, null);
mImageView = (ImageView) findViewById(R.id.imageView1);
switch (j) {
case 65:
mImageView.setBackgroundResource(R.drawable.a);
tts.speak(name + " for Apple", TextToSpeech.QUEUE_ADD, null);
// Toast.makeText(getApplicationContext(),
// "Saying:" + name + " for Apple", Toast.LENGTH_SHORT)
// .show();
tts.isLanguageAvailable(Locale.ENGLISH);
break;
case 66:
mImageView.setBackgroundResource(R.drawable.b);
tts.speak(name + "for Bluetooth", TextToSpeech.QUEUE_ADD, null);
break;
case 67:
mImageView.setBackgroundResource(R.drawable.c);
tts.speak(name + "for Chat", TextToSpeech.QUEUE_ADD, null);
break;
case 68:
mImageView.setBackgroundResource(R.drawable.d);
tts.speak(name + "for Download", TextToSpeech.QUEUE_ADD, null);
break;
case 69:
mImageView.setBackgroundResource(R.drawable.e);
tts.speak(name + "for E Mail", TextToSpeech.QUEUE_ADD, null);
break;
case 70:
mImageView.setBackgroundResource(R.drawable.f);
tts.speak(name + "for Facebook", TextToSpeech.QUEUE_ADD, null);
break;
case 71:
mImageView.setBackgroundResource(R.drawable.g);
tts.speak(name + "for Google", TextToSpeech.QUEUE_ADD, null);
break;
case 72:
mImageView.setBackgroundResource(R.drawable.h);
tts.speak(name + "for Hewlwtt Packard", TextToSpeech.QUEUE_ADD,
null);
break;
case 73:
mImageView.setBackgroundResource(R.drawable.i);
tts.speak(name + "for Iphone", TextToSpeech.QUEUE_ADD, null);
break;
case 74:
mImageView.setBackgroundResource(R.drawable.j);
tts.speak(name + "for Java", TextToSpeech.QUEUE_ADD, null);
break;
case 75:
mImageView.setBackgroundResource(R.drawable.k);
tts.speak(name + "for kingston", TextToSpeech.QUEUE_ADD, null);
break;
case 76:
mImageView.setBackgroundResource(R.drawable.l);
tts.speak(name + "for Laptop", TextToSpeech.QUEUE_ADD, null);
break;
case 77:
mImageView.setBackgroundResource(R.drawable.m);
tts.speak(name + "for Messenger", TextToSpeech.QUEUE_ADD, null);
break;
case 78:
mImageView.setBackgroundResource(R.drawable.n);
tts.speak(name + "for Nero", TextToSpeech.QUEUE_ADD, null);
break;
case 79:
mImageView.setBackgroundResource(R.drawable.o);
tts.speak(name + "for Orkut", TextToSpeech.QUEUE_ADD, null);
break;
case 80:
mImageView.setBackgroundResource(R.drawable.p);
tts.speak(name + "for Picassa", TextToSpeech.QUEUE_ADD, null);
break;
case 81:
mImageView.setBackgroundResource(R.drawable.q);
tts.speak(name + "for Quick Heal", TextToSpeech.QUEUE_ADD, null);
break;
case 82:
mImageView.setBackgroundResource(R.drawable.r);
tts.speak(name + "for Ram", TextToSpeech.QUEUE_ADD, null);
break;
case 83:
mImageView.setBackgroundResource(R.drawable.s);
tts.speak(name + "for Server", TextToSpeech.QUEUE_ADD, null);
break;
case 84:
mImageView.setBackgroundResource(R.drawable.t);
tts.speak(name + "for Twitter", TextToSpeech.QUEUE_ADD, null);
break;
case 85:
mImageView.setBackgroundResource(R.drawable.u);
tts.speak(name + "for Usb", TextToSpeech.QUEUE_ADD, null);
break;
case 86:
mImageView.setBackgroundResource(R.drawable.v);
tts.speak(name + "for Vista", TextToSpeech.QUEUE_ADD, null);
break;
case 87:
mImageView.setBackgroundResource(R.drawable.w);
tts.speak(name + "for WiFi", TextToSpeech.QUEUE_ADD, null);
break;
case 88:
mImageView.setBackgroundResource(R.drawable.x);
tts.speak(name + "for XP", TextToSpeech.QUEUE_ADD, null);
break;
case 89:
mImageView.setBackgroundResource(R.drawable.y);
tts.speak(name + "for Youtube", TextToSpeech.QUEUE_ADD, null);
break;
case 90:
mImageView.setBackgroundResource(R.drawable.z);
tts.speak(name + "for Zorpia", TextToSpeech.QUEUE_ADD, null);
break;
default:
break;
}
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, RESULT_OK);
final Thread t1 = new Thread() {
public void run() {
try {
Thread.sleep(10000);
finish();
// this.destroy();
} catch (Exception e) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
};
t1.start();
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RESULT_OK) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
// success, create the TTS instance
tts = new TextToSpeech(this, this);
} else {
// missing data, install it
Intent installIntent = new Intent();
installIntent
.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
}
}
}
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
Toast.makeText(this,
"Write and Listen engine is initialized & Ready",
Toast.LENGTH_LONG).show();
} else if (status == TextToSpeech.ERROR) {
Toast.makeText(this,
"Error occurred while initializing Text-To-Speech engine",
Toast.LENGTH_LONG).show();
}
}
protected void onDestroy() {
super.onDestroy();
if (tts != null) {
tts.shutdown();
}
}
}