2017-05-08 6 views
0

Ich erhalte einen Fehler bei der Umwandlung des Textes in Sprache in Android Studio. Ich habe den Code initialisiert, aber es gibt immer noch keine Sprachausgaben zurück. Der Code ist wie folgt.android Text to Speech einer Toast-Nachricht

else if((match.contains("yes") || match.contains("yeah")) && defsele) { 
      //Toast toast = Toast.makeText(getApplicationContext(), "Default selection is done and program is starting", Toast.LENGTH_SHORT); 
      //toast.show(); 
      defsele=false; 
      switch (progno) { 
       case 1: 
        //Toast toast1 = Toast.makeText(getApplicationContext(),"The default settings for cotton cycle is done",Toast.LENGTH_SHORT); 
        //toast1.show(); 
        String cotton = "The cotton program is starting with the default values"; 
        tts.speak(cotton, TextToSpeech.QUEUE_FLUSH, null); 
        soak=true; 
        soakdef(); 
        break; 

Der tts.speak wird entzogen und funktioniert nicht. Wie kann ich Initialisierungscode machen dieses funktionieren.Die ist wie folgt

tts = new TextToSpeech(this,this); 
    @Override 
public void onInit(int status) { 
    Log.d("Speech", "OnInit - Status ["+status+"]"); 
    if(status == TextToSpeech.SUCCESS){ 
     Log.d("Speech","Success"); 
     tts.setLanguage(Locale.ENGLISH); 

Ich bin sehr neu für Android-Programmierung und würde jede Hilfe dankbar.

Danke in fortgeschrittenem !!!

Antwort

0

versuchen diese

TextToSpeech textToSpeech = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() { 
        @Override 
        public void onInit(int status) { 
          //your text 
          String textToSpeechStr = "Hello"; 

          //status is success/0 
          if (status == TextToSpeech.SUCCESS) { 
           //speech starts 

           textToSpeech.speak(textToSpeechStr, TextToSpeech.QUEUE_FLUSH, null); 
          } 

        } 
       }); 
+0

Nö, der Code kommentiert sich automatisch. Gibt es da sowieso kann ich nur die API initialisieren und mehrere Sätze mit nur der Funktion "tts.speak()" konvertieren? –