将我的TTS引擎添加到Android TTS Serivce,如SAPI

use*_*745 6 android text-to-speech

我在Android中开发了自己的TTS应用程序.有没有办法将我的TTS引擎部署到操作系统而不是运行TTS应用程序,以便其他应用程序可以调用我的TTS?类似于MS Window中的SAPI.SVOX可以将引擎打包为apk,安装后,它会将新引擎添加到Andorid OS中,不知道我该如何做到这一点.

ala*_*anv 5

为了让您的文本转语音引擎显示在可用服务列表中,您需要添加适当的活动和清单条目。

对于 API 14 及更高版本,您需要扩展 TextToSpeechService,并且需要将以下内容添加到您的清单中:

    <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>
Run Code Online (Sandbox Code Playgroud)

这引用了 res/xml/tts_engine.xml,它应该是这样的:

<?xml version="1.0" encoding="utf-8"?>
<tts-engine xmlns:android="http://schemas.android.com/apk/res/android"
    android:settingsActivity="com.example.MyTtsSettingsActivity" />
Run Code Online (Sandbox Code Playgroud)

您还需要添加各种支持活动。以下是您将添加到清单中的内容:

    <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" />
Run Code Online (Sandbox Code Playgroud)

如果您计划支持 ICS 之前的 Android 版本,您还需要一个符合特定 API 的共享库。

我不会在这里详细介绍每个活动的实现,也不会详细介绍 ICS API,但您可以在 eSpeak TTS 引擎的 Android 端口的源代码中找到示例:http : //code.google.com /p/eyes-free/source/browse/trunk/tts/espeak-tts/