xdx1399513637 2015-11-16 08:00 采纳率: 100%
浏览 2348
已采纳

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 2015-11-17 01:19
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错
  • ¥15 java python或者任何一种编程语言复刻一个网页
  • ¥20 如何通过代码传输视频到亚马逊平台
  • ¥15 php查询mysql数据库并显示至下拉列表中
  • ¥15 freertos下使用外部中断失效
  • ¥15 输入的char字符转为int类型,不是对应的ascall码,如何才能使之转换为对应ascall码?或者使输入的char字符可以正常与其他字符比较?
  • ¥15 devserver配置完 启动服务 无法访问static上的资源
  • ¥15 解决websocket跟c#客户端通信
  • ¥30 Python调用dll文件输出Nan重置dll状态