Fonctionne sur l’émulateur mais pas sur tablette
Bonjour,
J'ai récupéré un petit bout de code pour comprendre le fonctionnement de "TextToSpeech" et je me retrouve face à un petit soucis. Tout fonctionne correctement sur mon GS2, sur l’émulateur, mais il ne se passe rien sur ma tablette (iconia tab 500).
Si vous avez une idée pour résoudre ce problème je suis preneur, merci d'avance!
le code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
| package FormationTextToSpeech.com;
import java.util.Locale;
import java.util.Random;
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class FormationTextToSpeechActivity extends Activity implements TextToSpeech.OnInitListener {
private static final String TAG = "TextToSpeechDemo";
//creation de objet TextToSpeech
private TextToSpeech mTts;
private Button mAgainButton;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//instanciation de l'objet mTts
mTts = new TextToSpeech(this,this );
// The button is disabled in the layout.
// It will be enabled upon initialization of the TTS engine.
mAgainButton = (Button) findViewById(R.id.again_button);
mAgainButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ParleandroidPhone ();
}
});
}
//
private static final Random RANDOM = new Random();
private static final String[] HELLOS = {
"Note dinformation 1",
"Note dinformation 2",
"Note dinformation 3",
"Note dinformation 4"
};
//
//
//Implements TextToSpeech.OnInitListener.
public void onInit(int status) {
//vérification de la disponibilité de la synthèse vocale.
if (status == TextToSpeech.SUCCESS) {
//le choix de la langue ici français
int result = mTts.setLanguage(Locale.FRANCE);
//vérification ici si cette langue est supporté par le terminal et si elle existe
if (result == TextToSpeech.LANG_MISSING_DATA ||
result == TextToSpeech.LANG_NOT_SUPPORTED) {
//renvoi une erreur sur la console logcat.
Log.e(TAG, "Language is not available.");
} else {
mAgainButton.setEnabled(true);
ParleandroidPhone ();
}
} else {
//si la synthèse vocal n'est pas disponible
Log.e(TAG, "Could not initialize TextToSpeech.");
}
}
//
private void ParleandroidPhone () {
// choix aléatoire de la phrase.
int helloLength = HELLOS.length;
String hello = HELLOS[RANDOM.nextInt(helloLength)];
mTts.speak(hello, TextToSpeech.QUEUE_FLUSH, null);
}
} |
xml:
Code:
1 2 3 4 5 6 7 8
| <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="@+id/again_button" android:layout_height="wrap_content" android:text="test" android:layout_width="147dp"></Button>
</LinearLayout> |