Android文字轉語音引擎(TTS)使用

百度網盤下載地址 密碼:3si0
資源來源:https://blog.csdn.net/Sqq_yj/article/details/82460580?utm_source=blogxgwz4android

簡單比較

(應用包名)
* com.svox.pico 系統自帶不支持中文語音
* com.svox.classic 搜svox搜到的,和上面相似不支持中文
* com.google.android.tts 谷歌文字轉語音引擎,不支持5.0如下系統,大小17.98M
* com.iflytek.speechcloud 科大訊飛語音引擎3.0,支持4.0以上系統,大小27.27M
* com.baidu.duersdk.opensdk 度祕語音引擎3.0 不支持5.0如下系統,大小11.95M
* com.iflytek.tts 科大訊飛語音合成,較老,不支持7.0以上系統,大小9Mide

一、聲明變量測試

    private TextToSpeech textToSpeech;
    private Button speech;

二、編寫測試代碼this

 //語音
        textToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                if (status == textToSpeech.SUCCESS) {
                    int result = textToSpeech.setLanguage(Locale.CHINA);
                    if (result != TextToSpeech.LANG_COUNTRY_AVAILABLE
                            && result != TextToSpeech.LANG_AVAILABLE){
                        Toast.makeText(BaoCanSignActivity.this, "TTS暫時不支持這種語音的朗讀!",
                                Toast.LENGTH_SHORT).show();
                    }
                }
            }
        });
        speech = (Button) findViewById(R.id.buttonSpeech);
        speech.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                textToSpeech.speak("測試語音播報",
                        TextToSpeech.QUEUE_ADD, null);
            }
        });
相關文章
相關標籤/搜索