add my TTS Engine to Android TTS Serivce like SAPI

删除回忆录丶 提交于 2019-12-04 05:17:59

For your text-to-speech engine to show up in the list of available services, you'll need to add the appropriate activities and manifest entries.

For API 14 and above, you need to extend TextToSpeechService and you need to add the following to your manifest:

    <service
        android:name=".MyTextToSpeechService"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.TTS_SERVICE" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <meta-data
            android:name="android.speech.tts"
            android:resource="@xml/tts_engine" />
    </service>

This references res/xml/tts_engine.xml, which should look like this:

<?xml version="1.0" encoding="utf-8"?>
<tts-engine xmlns:android="http://schemas.android.com/apk/res/android"
    android:settingsActivity="com.example.MyTtsSettingsActivity" />

You'll also need to add a variety of supporting activities. Here's what you'll be adding to your manifest:

    <activity
        android:name=".DownloadVoiceData"
        android:theme="@android:style/Theme.Dialog" >
        <intent-filter>
            <action android:name="android.speech.tts.engine.INSTALL_TTS_DATA" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".CheckVoiceData"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" >
        <intent-filter>
            <action android:name="android.speech.tts.engine.CHECK_TTS_DATA" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".GetSampleText"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" >
        <intent-filter>
            <action android:name="android.speech.tts.engine.GET_SAMPLE_TEXT" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".TtsSettingsActivity"
        android:label="@string/tts_settings_label" >
        <intent-filter>
            <action android:name="android.speech.tts.engine.CONFIGURE_ENGINE" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <!-- Legacy code for pre-ICS compatibility. -->
    <activity
        android:name=".MyTtsEngine"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" >
        <intent-filter>
            <action android:name="android.intent.action.START_TTS_ENGINE" />
        </intent-filter>
    </activity>

    <provider
        android:name="com.googlecode.eyesfree.espeak.providers.SettingsProvider"
        android:authorities="com.googlecode.eyesfree.espeak.providers.SettingsProvider" />

If you're planning on supporting pre-ICS versions of Android, you'll also need a shared library that conforms to a specific API.

I won't go into details of the implementation of each activity here, or into the pre-ICS API, but you can find examples in the source code for the Android port of eSpeak TTS engine: http://code.google.com/p/eyes-free/source/browse/trunk/tts/espeak-tts/

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