Automatically download android TTS engine

前端 未结 1 1848
广开言路
广开言路 2021-02-10 08:27

I have developed an app based on TTS for Android 2.3. I am noticing that in recent version of Android (4.2.2) for example, no default TTS language where installed by default, y

相关标签:
1条回答
  • 2021-02-10 08:38

    Is there a way to install a language automatically?

    Yes, but that will not happen automatically (without user consent) as mentioned in the docs:

    Since the installation of the data can be interrupted or declined by the user, the application shouldn't expect successful installation upon return from that intent...

    Anyhow, you can trigger the installation with something like this:

    /**
     * Ask the current default engine to launch the matching INSTALL_TTS_DATA activity
     * so the required TTS files are properly installed.
     */
    private void installVoiceData() {
        Intent intent = new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setPackage("com.google.android.tts"/*replace with the package name of the target TTS engine*/);
        try {
            Log.v(TAG, "Installing voice data: " + intent.toUri(0));
            startActivity(intent);
        } catch (ActivityNotFoundException ex) {
            Log.e(TAG, "Failed to install TTS data, no acitivty found for " + intent + ")");
        }
    }
    
    0 讨论(0)
提交回复
热议问题