2011-12-19 201 views
6

我已经在Android中开发了我自己的TTS应用程序。有没有办法将TTS引擎部署到操作系统中,而不是运行TTS应用程序,以便其他应用程序可以调用我的TTS?像MS Window中的SAPI。 SVOX可以将引擎打包为apk,并且在安装之后,它会将新引擎添加到Andorid操作系统中,不知道我该怎么做。将我的TTS引擎添加到Android TTS Serivce like SAPI

回答

4

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

对于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" /> 

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

我不会去到每一个活动的实施细节这里,或进入ICS预API,但你可以找到在源代码示例,eSpeak文字转语音引擎的Android端口: http://code.google.com/p/eyes-free/source/browse/trunk/tts/espeak-tts/