val textToSpeech = TextToSpeech(applicationContext, TextToSpeech.OnInitListener { status -> if (status == TextToSpeech.SUCCESS) { textToSpeech.language = Locale.US } })
textToSpeech.speak("Hello World", TextToSpeech.QUEUE_FLUSH, null)
请确保你已经添加了Text-to-Speech引导程序的依赖项:
implementation 'com.android.support:support-v4:27.0.0' implementation 'com.android.support:appcompat-v7:27.0.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'com.android.volley:volley:1.1.1'
希望这个解决方案对你有所帮助!