其目的是让用户选择的视频的名字发音出来。用户可以选择一个视频或同时选择几个视频。

使用ExoPlayer播放视频,但TextToSpeech不能说出第一段视频的名字,无论它是被选中的视频还是被选中的第一段。另一方面,TextToSpeech能很好地说出第二个视频和后面的视频。

欢迎和感谢任何建议,我昨天和今天早上花了一天时间寻找,但没有找到解决方案。

private fun goToPlayer(theMvmt: String) {
    val intent = Intent(this@GokyoActivity, PlayerActivity::class.java)
    intent.putExtra("mvmt", theMvmt)
    startActivity(intent)

在PlayerActivity中,我初始化了ExoPlayer和TextToSpeech。

全球性的变量。

var tts: TextToSpeech? = null

在onCreate :

// Initialize TextToSpeech
tts = TextToSpeech(this, this)

然后从onCreate中出来

TextToSpeech:

   override fun onInit(status: Int) {
        val myLanguage = Locale.getDefault().displayLanguage
        if (androidAPILevel < 21) {
            val params: HashMap<String, String> = HashMap()
            params[TextToSpeech.Engine.KEY_PARAM_VOLUME] = musicVolume.toString() // change the 0.5 to any value from 0-1 (1 is default)
//            tts!!.speak("This is a volume test.", TextToSpeech.QUEUE_FLUSH, params)
        } else { // android API level is 21 or higher...
            val params = Bundle()
            params.putFloat(
                TextToSpeech.Engine.KEY_PARAM_VOLUME, musicVolume.toFloat()
            ) // change the 0.5f to any value from 0f-1f (1f is default)
//            tts!!.speak("This is a volume test.", TextToSpeech.QUEUE_FLUSH, params, null)
        /* test de l'existence de la langue japonaise */
        if (status == TextToSpeech.SUCCESS) {
            /* set the language for tts */
            val result = tts!!.setLanguage(Locale.FRENCH)
            if (result == TextToSpeech.LANG_MISSING_DATA
                || result == TextToSpeech.LANG_NOT_SUPPORTED) {
//                tts!!.language = Locale.FRENCH
                Log.e("TTS", "*************** This Language is not supported ***************")
                speakOut(« French not supported, install it please")
                showTheToast(getString(R.string.NoJapaneseLanguage))
            } else {
                tts!!.setSpeechRate(1.0f)
        } else {
            showTheToast("TextToSpeech initialization failed!")
private fun initializePlayer() {
    player = SimpleExoPlayer.Builder(this)
        .build()
        .also { exoPlayer ->
            viewBinding.videoView.player = exoPlayer