Closed cawoolf closed 1 year ago
This happens as well on the Phrases fragment. When typing in a phrase it spams you on text changed.
Fixed Phrases typing spam, but still adding TTS to a never ending queue
solved by good ol chatgpt
To prevent the TextToSpeech queue from getting filled with requests when the button is clicked multiple times, you can check if the TextToSpeech engine is speaking before calling the speak() method. You can achieve this by using the isSpeaking() method provided by the TextToSpeech class.
Here's an example of how you can modify the code to check if the TextToSpeech engine is speaking before calling the speak() method:
scss Copy code if (mAnswerSetting.toString() == getString(R.string.answer_format_value_french_audio) || mAnswerSetting.toString() == getString(R.string.answer_format_value_french_text)) { val frenchText = answerPhrase.phraseFrench if (!mTextToSpeech.isSpeaking) { mPhrasalUtil.useTextToSpeech(frenchText) } }
fun useTextToSpeech(frenchText: String) { mTextToSpeech.setSpeechRate(1.0F) mTextToSpeech.speak(frenchText, TextToSpeech.QUEUE_ADD, null) } In the modified code, we check if the TextToSpeech engine is speaking by calling the isSpeaking() method before calling the speak() method. If the TextToSpeech engine is not speaking, we call the useTextToSpeech() method to speak the French text.
By adding this check, you can prevent the TextToSpeech queue from getting filled with requests when the button is clicked multiple times in a row.
On both the questions and the answers you can spam yourself