Is the Google TTS Engine on all Android Phones, and where can I get it?

你离开我真会死。 提交于 2019-12-05 07:11:22

I don't think the accepted answer is really correct. This code doesn't check if the google TTS engine is installed. It just launch an intent that TTS engines in general respond to ask if the TTS data for them is installed.

If there is no TTS engine installed, you may get an FC caused by an exception of the type ActivityNotFoundException. If you have other TTS engine (like pico) it will respond and check it's data. If you have more than one TTS engine, it will ask you which TTS engine you want the intent to work.

You should check for the package name in the package manager instead. This code checks for SVOX Pico TTS:

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    if(isPackageInstalled(getPackageManager(), "com.svox.pico")){
        ttsInstalled = true; // This would be good to have it as a static member
    }
}


public static boolean isPackageInstalled(PackageManager pm, String packageName) {
        try {
            pm.getPackageInfo(packageName, 0);
        } catch (NameNotFoundException e) {
            return false;
        }
        return true;
}

This code will check if TextToSpeech is installed and if not go to google store to download

Intent intent = new Intent();
intent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
ArrayList<String> languages = new ArrayList<String>();
languages.add("eng-USA"); //$NON-NLS-1$
intent.putStringArrayListExtra(TextToSpeech.Engine.EXTRA_CHECK_VOICE_DATA_FOR, 
                                                    languages);
startActivityForResult(intent, REQUEST_TTS_DATA_CHECK_CODE);  

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{
    super.onActivityResult(requestCode, resultCode, intent);

    switch (requestCode)
    {
        case REQUEST_TTS_DATA_CHECK_CODE:
            if (resultCode != TextToSpeech.Engine.CHECK_VOICE_DATA_PASS)
            {
                // show Alert Dialog to ask user go to play store to install
                // When user click OK this is the code to set
                intent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                startActivity(intent);
            }
            break;

}

Google TTS is a proprietary package developed by the Google and is available in most devices (particularly on Nexus devices) since ICS[citation needed]. It is part of Google developed apps that include Google Play Store, Google Maps, Google+, Gmail, YouTube, Google Search, Google Play Music, Google Play Books and many others. Not all of them are available for download from Play Store.

As far as I can tell, you can not have it unless somehow Google decides to make it open source and publicly available. As you have already mentioned, Google TTS uses HTS patch (is not an engine by itself) for HTK (I also know this from license page) which is released under the Modified BSD license. That's, you may never be able to obtain a copy of the engine.

If you want to develop a TTS engine, I would recommend taking a look on PICO TTS engine, source code of which is available in AOSP repository.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!