在 Android 上使用 TTS:大声朗读标点符号 [英] Using TTS on Android: Punctuation is read aloud

查看:39
本文介绍了在 Android 上使用 TTS:大声朗读标点符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CONTEXT: 我的应用程序正在向用户拥有的任何 TTS 引擎发送句子.句子是用户生成的,可能包含标点符号.

CONTEXT: My application is sending sentences to whatever TTS engine the user has. Sentences are user-generated and may contain punctuation.

问题:一些用户报告说 在 SVOX、Loquendo 和其他可能的平台上大声朗读标点符号(TTS 表示逗号"等).

PROBLEM: Some users report that the punctuation is read aloud (TTS says "comma" etc) on SVOX, Loquendo and possibly others.

问题:

  1. 我应该去掉所有标点符号吗?
  2. 我是否应该使用这种API来转换标点符号?
  3. 我应该让 TTS 引擎处理标点符号吗?

看到 Loquendo 问题的同一用户,在另一个名为 FBReader 的 Android 应用程序上没有这个问题.所以我想第三个选项不是正确的做法.

The same user that sees the problem with Loquendo, does not have this problem with another Android application called FBReader. So I guess the 3rd option is not the right thing to do.

推荐答案

因此,您担心用户可能碰巧选择了哪种后巷获得的文本转语音引擎作为他们的默认引擎......大概因为您不希望您的应用因该引擎的未知/不良行为而看起来很糟糕.可以理解.

So, you're worried about what back-alley-acquired text-to-speech engine the user might happen to have selected as their default... presumably because you don't want your app to look bad due to this engine's unknown/bad behavior. Understandable.

但(好的)事实是,TTS 的行为实际上不是您的责任,除非您决定在应用本身中嵌入引擎(难度:难,推荐?否).

The (good) fact is, though, that the TTS's behavior is not actually your responsibility unless you decide to embed an engine in the app itself (Difficulty: Hard, Recommended? No).

引擎可以而且应该被推定遵守 此处规定的 Android 规则和行为... 并假定在 Android 系统设置 (home\settings\language&locale\TTS) 中提供他们自己足够的配置选项集,其中可能包括也可能不包括发音选项.还应该假定用户足够聪明,可以安装他们满意的引擎.

Engines can and should be presumed to adhere to Android rules and behaviors dictated here... and presumed to supply their own sufficient set of configuration options in the Android system settings (home\settings\language&locale\TTS) which may or may not include pronunciation options. The user should also be presumed intelligent enough to install an engine that they are satisfied with.

预测和纠正"未知和不需要的引擎行为(至少在你自己没有测试过的引擎中)的工作是一个滑坡.

It is a slippery slope to take on the job of anticipating and "correcting" for unknown and unwanted engine behaviors (at least in engines that you haven't tested yourself).

一个简单而好的选择(难度:简单):

A SIMPLE AND GOOD OPTION (Difficulty: Easy):

  • 在您的应用中进行设置:忽略标点符号".

更好的选择(难度:中等):

A BETTER OPTION (Difficulty: Medium):

  • 执行上述操作,但仅当您在用户设备上检测到的引擎容易出现此问题时才显示忽略标点符号"设置选项.

另外,需要注意的一件事是引擎之间存在很多很多差异(它们是使用嵌入式语音还是在线语音、响应时间、初始化时间、可靠性/对 Android 规范的遵守、跨 Android API 级别的行为、跨它们的行为)自己的版本历史、语音质量,更不用说语言能力)......对用户来说,这些差异可能比标点是否发音更重要.

Also, one thing to note is that there are many, many differences between engines (whether they use embedded voices vs online, response time, initialization time, reliability/adherence to Android specs, behavior across Android API levels, behavior across their own version history, the quality of voices, not to mention language capability)... differences that may be even more important to users than whether or not punctuation is pronounced.

您说我的应用程序正在向用户拥有的任何 TTS 引擎发送句子."嗯……那是你的问题."为什么不让用户选择使用什么引擎?

You say "My application is sending sentences to whatever TTS engine the user has." Well... "That's yer problem right there." Why not give the user a choice on what engine to use?

并引导我们...

一个更好的选择(难度:困难而好![以我的拙见]):

AN EVEN BETTER OPTION (Difficulty: Hard and Good! [in my humble opinion]):

  • 确定您的应用将支持"一些已知良好"的引擎,首先是 Google 和三星.我猜现在只有不到 5% 的设备上没有这两种引擎.
  • 在您计划支持的所有 Android API 级别上尽可能多地研究和测试这些引擎......至少在它们是否发音标点符号方面如此.
  • 随着时间的推移,如果您愿意,可以测试更多引擎,并在后续应用更新中将它们添加到您支持的引擎中.
  • 在您的应用启动时运行算法来检测安装了哪些引擎,然后针对您自己的受支持引擎列表使用该信息:
private ArrayList<String> whatEnginesAreInstalled(Context context) {
    final Intent ttsIntent = new Intent();
    ttsIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    final PackageManager pm = context.getPackageManager();
    final List<ResolveInfo> list = pm.queryIntentActivities(ttsIntent, PackageManager.GET_META_DATA);
    ArrayList<String> installedEngineNames = new ArrayList<>();
    for (ResolveInfo r : list) {
        String engineName = r.activityInfo.applicationInfo.packageName;
        installedEngineNames.add(engineName);

        // just logging the version number out of interest
        String version = "null";
        try {
            version = pm.getPackageInfo(engineName,
            PackageManager.GET_META_DATA).versionName;
            } catch (Exception e) {
                Log.i("XXX", "try catch error");
            }
        Log.i("XXX", "we found an engine: " + engineName);
        Log.i("XXX", "version: " + version);
    }
    return installedEngineNames;
}

<小时>

  • 在您的应用设置中,将您决定支持的所有引擎显示为选项(即使当前未安装).这可能是一组简单的 RadioButton,其标题对应于不同的引擎名称.如果用户选择了未安装的软件,请通知他们并让他们选择是否有意安装.
  • 将用户选择的引擎名称(字符串)保存在 SharedPreferences 中,并在您的应用中需要 TTS 时使用他们的选择作为 TextToSpeech 构造函数的最后一个参数.
  • 如果用户安装了一些奇怪的引擎,即使无法识别/不受支持,也将其作为选项显示,但请告知他们他们选择了未知/未经测试的引擎.
  • 如果用户选择了受支持但已知会发出标点符号(坏)的引擎,则在选择该引擎后,会弹出一个警告对话框,警告用户有关该问题,并解释说他们可以关闭这种不良行为使用已经提到的忽略标点符号"设置.
  • 附注:

    • 不要让 SVOX/PICO(模拟器)引擎让你太担心——它有很多缺陷,甚至没有设计或保证在 API ~20 以上的 Android 上运行,但仍然包含在模拟器中图像高达 API ~24,导致不可预测的结果",实际上并不反映现实.在过去七年左右的时间里,我还没有在任何真正的硬件设备上看到这个引擎.

    • Don't let the SVOX/PICO (emulator) engine get you too worried -- it has many flaws and is not even designed or guaranteed to run on Android above API ~20, but is still included on emulators images up to API ~24, resulting in "unpredictable results" that don't actually reflect reality. I have yet to see this engine on any real hardware device made within the last seven years or so.

    既然你说句子是用户生成的",我会更担心解决他们将输入什么语言的问题!我会注意一个问题!:)

    Since you say that "sentences are user generated," I would be more worried about solving the problem of what language they are going to be typing in! I'll look out for a question on that! :)

    这篇关于在 Android 上使用 TTS:大声朗读标点符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆