2011-12-19 6 views
6

Tôi đã phát triển các ứng dụng TTS của riêng mình trong Android. Có cách nào để triển khai công cụ TTS của tôi vào hệ điều hành thay vì chạy các ứng dụng TTS, để các ứng dụng khác có thể gọi TTS của tôi không? Một cái gì đó giống như SAPI trong MS Window. SVOX có thể đóng gói động cơ như là apk và sau khi cài đặt, nó thêm động cơ mới vào hệ điều hành Andorid, không chắc làm thế nào tôi có thể làm điều đó.thêm TTS Engine của tôi vào Android TTS Serivce như SAPI

Trả lời

4

Để công cụ chuyển văn bản thành giọng nói của bạn hiển thị trong danh sách các dịch vụ có sẵn, bạn sẽ cần phải thêm các hoạt động và mục kê khai thích hợp.

Đối với API 14 trở lên, bạn cần phải mở rộng TextToSpeechService và bạn cần phải thêm dòng sau vào biểu hiện của bạn:

<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> 

này tham khảo res/xml/tts_engine.xml, mà nên xem xét như thế này:

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

Bạn cũng sẽ cần thêm nhiều hoạt động hỗ trợ khác. Đây là những gì bạn sẽ được thêm vào biểu hiện của bạn:

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

Nếu bạn đang lập kế hoạch hỗ trợ các phiên bản trước ICS Android, bạn cũng sẽ cần một thư viện chia sẻ mà phù hợp với một API cụ thể.

tôi sẽ không đi vào chi tiết của việc thực hiện từng hoạt động ở đây, hoặc vào API trước ICS, nhưng bạn có thể tìm thấy ví dụ trong mã nguồn cho các cổng Android của động cơ eSpeak TTS: http://code.google.com/p/eyes-free/source/browse/trunk/tts/espeak-tts/