xdx1399513637
ni看我屌不
2015-11-16 08:00
采纳率: 92.9%
浏览 2.3k

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

    }

};

}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • xdx1399513637
    ni看我屌不 2015-11-17 01:19
    已采纳

    一种语言读完才会读另外一种语言,我想的是读完一句汉语,在读一句维语

    点赞 评论
  • an050602
    an050602 2015-11-16 12:12

    你的问题在哪里?什么问题?你说卡住哪里卡住才行啊

    点赞 评论
  • an050602
    an050602 2015-11-16 12:13

    你的问题在哪里?什么问题?你说卡住哪里卡住才行啊

    点赞 评论
  • u011325156
    aloneGirle 2015-11-19 09:14

    我觉得你在播放两种语言的时候,要有所标记啊,什么时候播汉语什么时候播维语你没有分清楚

    点赞 评论

相关推荐