程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> 對象-android 醫院語音叫號 求大神指點

對象-android 醫院語音叫號 求大神指點

編輯:編程綜合問答
android 醫院語音叫號 求大神指點

想實現一句維語,一句漢語,一直循環,但是邏輯這裡卡住了。求大神指點迷津
下面有源碼
package com.zkr.voice;

import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechError;
import com.iflytek.cloud.SpeechSynthesizer;
import com.iflytek.cloud.SpeechUtility;
import com.iflytek.cloud.SynthesizerListener;

public class MainActivity extends Activity {

private Context context;
private List<String> list_han = new ArrayList<String>();
private List<String> list_wei = new ArrayList<String>();
private long timeInterval = 5000;
private Boolean flage;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    context = this;
    list_han.add("PD0小明0到窗口繳費");
    list_han.add("qw1小明到窗口繳費");
    list_han.add("qw2小明到窗口繳費");
    list_wei.add("ئۇيغۇر تىلى");
    list_wei.add("كۆيدى بىزنى دە");
    list_wei.add("كۆيدى بىزنى دە1");
    flage=true;
    // 初始化即創建語音配置對象
    SpeechUtility.createUtility(this, SpeechConstant.APPID + "=563b0226");
    final SpeechSynthesizer mTts = SpeechSynthesizer.createSynthesizer(
            this, null);
    // 多語種引擎
    mTts.setParameter(SpeechConstant.ENGINE_TYPE, "mtts");
    mTts.setParameter(SpeechConstant.VOICE_NAME, "Guli");// 設置發音人
    mTts.setParameter(SpeechConstant.SPEED, "50");// 設置語速
    mTts.setParameter(SpeechConstant.VOLUME, "80");// 設置音量,范圍0~100
    mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD); // 設置雲端   
    Runnable runnable = new Runnable() {
        @Override
        public void run() {         
            while (flage) {
                flage=false;
                for (int i = 0; i < list_wei.size(); i++) {
                    String str1 = list_wei.get(0);
                    Log.e("TAG", str1);
                    Log.e("aaaa", " 我要讀維語了");
                    // 維語發音
                    mTts.startSpeaking(str1, mSynListener);
                    list_wei.remove(0);

                    try {
                        Thread.sleep(timeInterval);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }

        }
    };
    Thread thread = new Thread(runnable);
    thread.start();
}

// 合成監聽器
private SynthesizerListener mSynListener = new SynthesizerListener() {

    @Override
    public void onBufferProgress(int arg0, int arg1, int arg2, String arg3) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onCompleted(SpeechError arg0) {
        if (arg0 == null) {
            flage=true;
            Log.i("TAG", "維語播放完成");
            final SpeechSynthesizer mTts1 = SpeechSynthesizer
                    .createSynthesizer(context, null);
            // mTts1.setParameter(SpeechConstant.ENGINE_TYPE, "mtts");
            mTts1.setParameter(SpeechConstant.VOICE_NAME, "xiaoyu");// 設置發音人
            mTts1.setParameter(SpeechConstant.SPEED, "50");// 設置語速
            mTts1.setParameter(SpeechConstant.VOLUME, "80");// 設置音量,范圍0~100
            mTts1.setParameter(SpeechConstant.ENGINE_TYPE,
                    SpeechConstant.TYPE_CLOUD); // 設置雲端

            Runnable runable1 = new Runnable() {
                @Override
                public void run() {
                    while (flage) {
                        flage=false;
                        for (int i = 0; i < list_han.size(); i++) {
                            String str2 = list_han.get(0);
                            // 漢語發音
                            Log.e("aaaa", " 我要讀漢語了");
                            mTts1.startSpeaking(str2, mSynListener1);
                            Log.e("TAG", str2);
                            list_han.remove(0);
                            flage=true;
                            try {
                                Thread.sleep(timeInterval);
                            } catch (InterruptedException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    }
                }
            };
            Thread thread1 = new Thread(runable1);
            thread1.start();
        }
    }

    @Override
    public void onEvent(int arg0, int arg1, int arg2, Bundle arg3) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onSpeakBegin() {
        // TODO Auto-generated method stub

    }

    @Override
    public void onSpeakPaused() {
        // TODO Auto-generated method stub

    }

    @Override
    public void onSpeakProgress(int arg0, int arg1, int arg2) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onSpeakResumed() {
        // TODO Auto-generated method stub

    }
};

private SynthesizerListener mSynListener1 = new SynthesizerListener() {

    @Override
    public void onBufferProgress(int arg0, int arg1, int arg2, String arg3) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onCompleted(SpeechError arg0) {
        // TODO Auto-generated method stub
        if (arg0 == null) {
            Log.i("TAG", "漢語播放完成");

        }
    }

    @Override
    public void onEvent(int arg0, int arg1, int arg2, Bundle arg3) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onSpeakBegin() {
        // TODO Auto-generated method stub

    }

    @Override
    public void onSpeakPaused() {
        // TODO Auto-generated method stub

    }

    @Override
    public void onSpeakProgress(int arg0, int arg1, int arg2) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onSpeakResumed() {
        // TODO Auto-generated method stub

    }

};

}

最佳回答:


一種語言讀完才會讀另外一種語言,我想的是讀完一句漢語,在讀一句維語

wanghang1208
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved