gotev / android-speech

Android speech recognition and text to speech made easy
http://gotev.github.io/android-speech/
Apache License 2.0
473 stars 156 forks source link

there is a way to know when TextToSpeech engine successfully started without logger delegate #40

Closed josco007 closed 3 years ago

josco007 commented 4 years ago

Hi, I have a doubt about if the loggerDelegate will works in production mode, i am using this delegate to know if the engine has been started to set the locale in there , example:

    Speech.init(this, packageName)
    Logger.setLogLevel(Logger.LogLevel.DEBUG);
    Logger.setLoggerDelegate(object : LoggerDelegate {
        override fun error(tag: String?, message: String?) {
        }

        override fun error(tag: String?, message: String?, exception: Throwable?) {
        }

        override fun debug(tag: String?, message: String?) {
        }
        override fun info(tag: String?, message: String?) {
            if (message == "TextToSpeech engine successfully started"){
                Speech.getInstance().setLocale(Locale("es", "MX"))
            }
        }
    })
gotev commented 4 years ago

By default Speech uses your default locale set on Android. Do you need setting a different one instead? If so, isn't this sufficient?

Speech.init(this, packageName)
Speech.getInstance().setLocale(Locale("es", "MX"))
josco007 commented 3 years ago

Hi, thanks for your answer, I have tried that but seems that is necessary that the speech.init method be completed because if I call Speech.getInstance().setLocale(Locale("es", "MX")) immediately after init, the method setLocale does not take effect

gotev commented 3 years ago

@josco007 yes, that's a race condition, which is not easy to overcome and would require cumbersome code to handle. To avoid race conditions, one possible way is to extend the init method:

Speech.init(this, packageName, locale)

and provide the desired initial locale