Infinite loop Output Problem Text to Speech

Viewed 39

Hello im using Android Studio and Java Code. i got an infinite loop Problem on text to speech. All is working but the last word of the output is infinite looping and i want just one random output of my string array (frage) everytime my tesla goes over 60. i tried with the stop funtion of tts but it does not work. thanks for help here is a part of my code:


 if (tesla > 60)

        {
            imageViewGreen2.setVisibility(View.VISIBLE);
            imageViewGreen2=(ImageView) findViewById(R.id.green2);
            Random random = new Random();
            int num = random.nextInt(frage.length);
            ausgabe.setText(frage[num]);
            mTTs.stop();

        }

        else{

            imageViewGreen2.setVisibility(View.GONE);

        }

tts code:

mTTs = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                if (status != TextToSpeech.ERROR) {
                    mTTs.setLanguage(Locale.GERMAN);
                    mTTs.setPitch((float) 0.6);
                } else {
                    Toast.makeText(MainActivity.this, "Fehler", Toast.LENGTH_SHORT).show();
                }
            }
        }); 



String toSpeak = ausgabe.getText().toString().trim();
        if (toSpeak.equals("")){
            Toast.makeText(MainActivity.this, "Warte auf Antwort", Toast.LENGTH_SHORT).show();
        }
        else {
            Toast.makeText(MainActivity.this, toSpeak, Toast.LENGTH_SHORT).show();
            mTTs.speak(toSpeak, TextToSpeech.QUEUE_FLUSH,null);
        } 
0 Answers
Related