Android Text-To-Speech API听起来很机器人 [英] Android Text-To-Speech API Sounds Robotic

查看:389
本文介绍了Android Text-To-Speech API听起来很机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次学习android开发,我的目标是创建一个简单的Hello World应用程序,该应用程序可以吸收一些文本,然后大声读出来.

I'm learning android development for the first time and my goal is to create a simple Hello World application that takes in some text, and reads them out loud.

我的代码基于我发现的示例,这是我的代码:

I've based my code off an example I found and here's my code:

class MainFeeds : AppCompatActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main_feeds)



        card.setOnClickListener{
            Toast.makeText(this, "Hello", Toast.LENGTH_LONG).show()
            TTS(this, "Hello this is leo")
        }
    }

}


class TTS(private val activity: Activity,
          private val message: String) : TextToSpeech.OnInitListener {

          private val tts: TextToSpeech = TextToSpeech(activity, this, "com.google.android.tts")

    override fun onInit(i: Int) {
        if (i == TextToSpeech.SUCCESS) {

            val localeUS = Locale.US

            val result: Int
            result = tts.setLanguage(localeUS)

            if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                Toast.makeText(activity, "This Language is not supported", Toast.LENGTH_SHORT).show()
            } else {
                speakOut(message)
            }

        } else {
            Toast.makeText(activity, "Initilization Failed!", Toast.LENGTH_SHORT).show()
        }
    }

    private fun speakOut(message: String) {
        tts.speak(message, TextToSpeech.QUEUE_FLUSH, null, null)
    }
}

它工作得非常好,我遇到的问题是,从合成器发出的音频听起来非常机器人化,就像我在使用Google Maps并断开互联网连接时一样.使用Google Assistant语音是不是要利用我必须启用的其他API?

And it works perfectly fine, the issue that I'm running into is that the audio that's coming out of the synthesizer sounds extremely robotic, almost like when I'm using Google Maps and I get disconnected from the internet. Is using the voice Google Assistant leverages some other API that I have to enable?

我已经尝试在像素2xl上运行该应用程序,但它听起来还是很机器人,因为它没有使用Google Assistant语音.

I've tried running the app on my pixel 2xl and it still sounds robotic, as in it's not using the Google Assistant voice.

推荐答案

首先,语音质量取决于您创建的TextToSpeech对象使用的语音引擎":

The quality of speech first and foremost comes down to what "speech engine" is being used by the TextToSpeech object that you created:

private val tts: TextToSpeech = TextToSpeech(activity, this)

如果您改为输入:

private val tts: TextToSpeech = TextToSpeech(activity, this, "com.google.android.tts")

...然后,您在其上运行该代码的任何设备都会尝试以使用Google语音引擎...,但只有在该设备上存在该设备时,它才会被实际使用.

...then any device you run that code on will attempt to use the google speech engine... but it will only actually be used if it exists on the device.

类似地,使用"com.samsung.SMT"将尝试使用三星语音引擎(这也是高质量的,但通常仅安装在三星[real]设备上).

Similarly, using "com.samsung.SMT" would attempt to use the Samsung speech engine (which is also high-quality, but usually only installed on Samsung [real] devices).

是否可以使用Google语音引擎并不太取决于设备的Android API级别(只要它足够新,足以运行Google引擎),而是实际的Google text-to -语音引擎完全安装在设备上.

Whether or not the Google speech engine will be available is not so much dependent on the Android API level of the device (as long as it's recent enough to run the Google engine), but whether or not the actual Google text-to-speech engine is installed on the device at all.

要确保已安装Google引擎,请执行以下操作:

To make sure that the Google engine is installed:

在Android Studio模拟器上:

创建一个新的模拟器,然后在目标"列中选择一个具有"Google API"或"Google Play"的系统映像.

Create a new emulator and select a system image that has "Google APIs" or "Google Play" in the "target" column.

在真实设备上:

转到Play商店并安装

Go to the Play Store and install the Google speech engine.

Android上的TTS(或至少试图预测其行为)可能是真正的野兽.

TTS on Android (or at least trying to predict its behavior) can be a real beast.

文档: Java | 科林.

这篇关于Android Text-To-Speech API听起来很机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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