add my TTS Engine to Android TTS Serivce like SAPI

筅森魡賤 提交于 2019-12-21 13:02:20

问题


I have developed my own TTS apps in Android. Is there any way to deploy my TTS engine into the OS instead on running the TTS apps, so that other apps can call my TTS? Something like SAPI in MS Window. SVOX can package the engine as apk and after installed, it adds new engines into the Andorid OS, not sure how can I do that same.


回答1:


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/



来源:https://stackoverflow.com/questions/8560549/add-my-tts-engine-to-android-tts-serivce-like-sapi

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