【发布时间】:2011-12-19 11:19:27
【问题描述】:
我在 Android 中开发了自己的 TTS 应用程序。有没有办法将我的 TTS 引擎部署到操作系统中,而不是运行 TTS 应用程序,以便其他应用程序可以调用我的 TTS?类似于 MS Window 中的 SAPI。 SVOX 可以将引擎打包为 apk,安装后,它会将新引擎添加到 Andorid 操作系统中,不知道我该怎么做。
【问题讨论】:
我在 Android 中开发了自己的 TTS 应用程序。有没有办法将我的 TTS 引擎部署到操作系统中,而不是运行 TTS 应用程序,以便其他应用程序可以调用我的 TTS?类似于 MS Window 中的 SAPI。 SVOX 可以将引擎打包为 apk,安装后,它会将新引擎添加到 Andorid 操作系统中,不知道我该怎么做。
【问题讨论】:
为了让您的文本转语音引擎显示在可用服务列表中,您需要添加适当的活动和清单条目。
对于 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>
这引用了 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" />
您还需要添加各种支持活动。以下是您将添加到清单中的内容:
<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" />
如果您计划支持 ICS 之前的 Android 版本,您还需要一个符合特定 API 的共享库。
我不会在这里详细介绍每个活动的实现,也不会介绍 pre-ICS API,但是您可以在 eSpeak TTS 引擎的 Android 端口的源代码中找到示例: http://code.google.com/p/eyes-free/source/browse/trunk/tts/espeak-tts/
【讨论】: