安卓,文本转语音

发布于 2024-10-05 21:30:30 字数 969 浏览 2 评论 0原文

我正在尝试文本转语音,以使我的测试应用程序更有趣。它可以在模拟器中运行,但不能在我的手机上运行,​​因为我的默认区域设置不是英语。

然而,文本是英文的,所以 tts 当然应该使用英文。据我所知,我可以实现自动安装,例如

    public void onInit(int status) {

    if (status == TextToSpeech.SUCCESS) {
        // Set preferred language to US english.

        int result = mtts.setLanguage(Locale.US);

        if (result == TextToSpeech.LANG_MISSING_DATA ||
            result == TextToSpeech.LANG_NOT_SUPPORTED) {
           // Lanuage data is missing or the language is not supported.
            Log.e(TAG, "Language is not available.");
        } else {

            // The TTS engine has been successfully initialized.
            speak();
        }
    } else {
        // missing data, install it
        Intent installIntent = new Intent();
        installIntent.setAction(
            TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
        startActivity(installIntent);
    }
}

但是,我想要吗?安装语言环境是否会占用大量空间?它会弄乱其他东西吗?

问候

I'm playing with text to speech to make my testapp a little more fun. It works in the emulator but not on my phone since my default locale isn't english.

However, the texts are english so the tts should of course use english. As far as I know I can implement an autoninstall, something like

    public void onInit(int status) {

    if (status == TextToSpeech.SUCCESS) {
        // Set preferred language to US english.

        int result = mtts.setLanguage(Locale.US);

        if (result == TextToSpeech.LANG_MISSING_DATA ||
            result == TextToSpeech.LANG_NOT_SUPPORTED) {
           // Lanuage data is missing or the language is not supported.
            Log.e(TAG, "Language is not available.");
        } else {

            // The TTS engine has been successfully initialized.
            speak();
        }
    } else {
        // missing data, install it
        Intent installIntent = new Intent();
        installIntent.setAction(
            TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
        startActivity(installIntent);
    }
}

But, do I want to? Does installing locales take a lot of space? Does it mess up something else?

regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

阪姬 2024-10-12 21:30:30

你应该执行这个:

   // missing data, install it
    Intent installIntent = new Intent();
    installIntent.setAction(
        TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
    startActivity(installIntent);

当你得到 LANG_MISSING_DATA 时

You should execute this:

   // missing data, install it
    Intent installIntent = new Intent();
    installIntent.setAction(
        TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
    startActivity(installIntent);

when you get LANG_MISSING_DATA

海拔太高太耀眼 2024-10-12 21:30:30

我只会在“LANG_MISSING_DATA”不适用于“LANG_NOT_SUPPORTED”的情况下尝试安装。由于它启动另一个活动,并且用户可以选择是否下载它,所以我不会太担心它占用空间。不,它不应该搞乱任何事情。

I would only try the install in the case where "LANG_MISSING_DATA" not for "LANG_NOT_SUPPORTED". Since it starts another activity and the user can choose whether they download it or not, I wouldn't worry too much about it taking space. No, it shouldn't mess anything up.

岁月如刀 2024-10-12 21:30:30

Android 允许您将文本转换为语音。您不仅可以转换它,还可以让您用各种不同的语言说出文本。
Android 为此提供了 TextToSpeech 类。
有关更多详细信息,请按照本教程操作:-

http://a-droidtech.blogspot.in/2015/06/android-text-to-speech-tutorial-android.html

Android allows you convert your text into voice. Not only you can convert it but it also allows you to speak text in variety of different languages.
Android provides TextToSpeech class for this purpose.
For more detail please follow this tutorial :-

http://a-droidtech.blogspot.in/2015/06/android-text-to-speech-tutorial-android.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文