当预先录制的 wav 文件丢失时,TextToSpeech 回退到后端服务

发布于 2025-01-02 16:03:38 字数 1198 浏览 0 评论 0原文

我有一个使用 TextToSpeech 来宣布参考号的应用程序。由于公告仅包含 10 个数字和 26 个字母,我想我应该利用我在另一个应用程序中使用 Synthesizetofile 方法制作的预先录制的 wav 文件。

文档指出,如果指定的文件丢失,那么TTS引擎将使用网络进行在线合成。我已经像这样设置了 TTS:

String filePrefix = Environment.getExternalStorageDirectory()
                .getAbsolutePath()
                + "/Android/data/"
                + this.getString(R.string.package_name) + "/files/";

        int rv = 0;
        for (char c = 'A'; c<= 'Z'; c++){
            mWavFileName = filePrefix + Character.toString(c) + ".wav";
             rv  = mTts.addSpeech(Character.toString(c), mWavFileName);
        }

在我定义的位置

TextToSpeech mTts;
String mWavFileName;

如果文件存在,那么我的说出该字母的代码

mTts.speak("A", TextToSpeech.QUEUE_ADD, null);

就可以正常工作。如果文件丢失,则行为如 Android 中的文本转语音简介 尚未实现。

这样,对与wakeUpText相同的字符串内容的speak()的任何调用都将导致destFileName的播放。如果文件丢失,那么speak的行为就像音频文件不存在一样,并且会合成并播放给定的字符串。

我根本没有看到这一点。如果文件丢失,则不会发出任何声音。如果文件丢失,返回值“rv”永远不会显示错误。除了在执行“addSpeech”行之前检查文件是否存在之外,还有什么方法可以纠正此行为?

I have an application which uses the TextToSpeech to announce reference numbers. As the announcements will consist only of 10 digits and the 26 letters of the alphabet, I thought I'd take advantage of prerecorded wav files which I made using the synthesizetofile method in another app.

The documentation states that if the specified file is missing, then the TTS engine will use the network to synthesize on line. I've set up the TTS like so:

String filePrefix = Environment.getExternalStorageDirectory()
                .getAbsolutePath()
                + "/Android/data/"
                + this.getString(R.string.package_name) + "/files/";

        int rv = 0;
        for (char c = 'A'; c<= 'Z'; c++){
            mWavFileName = filePrefix + Character.toString(c) + ".wav";
             rv  = mTts.addSpeech(Character.toString(c), mWavFileName);
        }

Where I've defined

TextToSpeech mTts;
String mWavFileName;

If the files are present then my code which speaks the letter

mTts.speak("A", TextToSpeech.QUEUE_ADD, null);

works fine. If the file is missing then the behaviour as described in An introduction to Text-To-Speech in Android isn't implemented.

This way any call to speak() for the same string content as wakeUpText will result in the playback of destFileName. If the file is missing, then speak will behave as if the audio file wasn't there, and will synthesize and play the given string.

I don't see this at all. If the file is missing nothing gets spoken. The return value 'rv' never shows an error if the file is missing. Is there any way to correct this behaviour, other than checking that the file exists before executing the 'addSpeech' line?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文