Android筆記之 TTS中文發音

來源:互聯網
上載者:User

Android筆記之 TTS中文發音
1、TTS 就是 Text to Speech ,把常值內容變為語音。 Google在Android 1.6 開始就支援TTS 了,但是可惜,只是支援英文法語德語等五種語言,唯獨丫丫的木有我們中文。 所以,我們只能另外自己開發中文語音包程式。
目前主要有以下幾種中文TTS 。 (1)開源項目 eyes-free ,連結是: http://code.google.com/p/eyes-free/ 在手機上安裝了eyes-free 提供的 TTS Service Extended.apk 檔案後,就可以在手機-設定-語音輸入-中設定是eSpeak輸入為預設的語音輸入。
實際效果沒有測試,網上有其他網友測試說效果很差。具體如何開發,請參考這篇文章: http://blog.csdn.net/ichliebephone/article/details/6373184
(2)科大訊飛 這個比較出名了,因為蘋果的語音合成讓它火了一把,它也是國內語音合成方面做得比較好的一個公司。 之前提供安卓開發的中文語音引擎。但是現在找不到了。
(3)手說TTS 手說TTS,是Android平台下的中文語音引擎,提供了中文文本到語音的轉換。
使用手說TTS進行中文文本的朗讀,包括中文簡繁體、阿拉伯數字、英文字母及一些符號的混讀。並且處理了中文的多音字和音調轉換等問題。個人工作室所做的。因為他提供了比較詳細的二次開發介面,所以我下面就是針對他做了一個中文TTS開發。實際測試,效果差錢人意吧,普通話真的不是很好。此外,只有最新版的才有連貫功能,以前的沒有,糾結我半天。
下面給出調試過程和源碼。

 

第一步:安裝手說TTS安裝包

 

安裝到真實手機或者手機模擬器中。

 

第二步:下載手說TTS客戶類庫包

 

下載手說TTS客戶類庫包:shoushuotts.jar 。

將該jar檔案引入到你的應用中。

第三步,編寫代碼

 

import android.app.Activity;import android.content.ComponentName;import android.content.Context;import android.content.Intent;import android.content.ServiceConnection;import android.os.Bundle;import android.os.IBinder;import android.os.RemoteException;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import com.shoushuo.android.tts.ITts;/** * @version 1.0 */public class Speech extends Activity{   private ITts ttsService;      private boolean ttsBound;     private ServiceConnection connection = new ServiceConnection() {              @Override        public void onServiceConnected(ComponentName className, IBinder iservice) {          ttsService = ITts.Stub.asInterface(iservice);          ttsBound = true;             //在應用第一個使用TTS 的地方,調用下面的initialize方法,比如如果有      //兩個Activity都使用手說TTS,則第二個Activity在此不需要再調用。      try {            ttsService.initialize();      } catch (RemoteException e) {       e.printStackTrace();      setTitle("出錯啦");     }        }              @Override        public void onServiceDisconnected(ComponentName arg0) {          ttsService = null;          ttsBound = false;        }      };  private EditText edt; private Button press;  @Override public void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.main);     this.setContentView( R.layout.main );         this.press = ( Button ) findViewById( R.id.speech );         edt = (EditText)findViewById(R.id.txt);         //給Button 添加事件監聽器Button.OnClickListener()                         //處理事件       press.setOnClickListener(new OnClickListener()         {             @Override             public void onClick( View source)             {                            try {      ttsService.speak("歡迎小朋友",0);     } catch (RemoteException e) {      // TODO Auto-generated catch block      e.printStackTrace();     }             }         } ); }  @Override      protected void onStart() {        super.onStart();        if (!ttsBound ) {          String actionName = "com.shoushuo.android.tts.intent.action.InvokeTts";          Intent intent = new Intent(actionName);          this.bindService(intent, connection, Context.BIND_AUTO_CREATE);        }      }        @Override      protected void onDestroy () {        if (ttsBound ) {          ttsBound = false;          this.unbindService(connection);        }    super. onDestroy ();      }  }



 

記得用最新版的手說TTS apk 程式,因為舊版沒有連貫朗讀的功能,一字字地很生硬。
此外,特別注意一點,就是匯入 shoushuo開發包的時候,如果你出現了如下的錯誤,threadid=1: thread exiting with uncaught exception (group=0x4001d800)

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.