package com.jlb.scan.util;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.util.SparseIntArray; import com.jlb.scan.R; /**
* @version V1.0
* @Description: 语音提示的 辅助类
*/
public class MySoundAlertUtil {
public static final int GET_ORDER_INFO_REQUEST_CODE = 0x001;
public static final int STATUS_NORMAL = 10101; // 正常
public static final int STATUS_PICKUP = 10102;// 取走
public static final int STATUS_RETRIEVE = 10104;// 取回
public static final int STATUS_WITHDRAW = 10122;// 已退
public static final int STATUS_FLAG_WITHDRAW = 10124;// 待退
public static final int STATUS_NOEXIT = -10999;// 不存在
public static final int STATUS_OTHER = -10998;// 异常 /**
* 运单错误
*/
public static final int ERROR_yundan_cuowu = 11;
/**
* 运单重复
*/
public static final int ERROR_yundan_chongfu = 12;
/**
* 运单已接驳
*/
public static final int ERROR_yundan_yijiebo = 13;
/**
* 接驳成功
*/
public static final int JIEBO_SUCCESS = 14;// 异常 public static final int ERROR_JIEBO_PICI_INFO_ERROR = 15;// 批次信息错误,请重新选择
//运单不存在
public static final int ERROR_WAYBILL_NOT_EXIST = 16; //未知
public static final int ERROR_UNKNOW = 17; public static final int ERROR_NO_PHONE_NUM = 18; public static final int ERROR_NO_JIE_BO = 15351; private SoundPool mSoundPool;
private SparseIntArray mSoundMap;
private Context context; public MySoundAlertUtil(Context context) {
super();
this.context = context;
initSound(context);// ;
} private void initSound(Context context) {
mSoundPool = new SoundPool(10, AudioManager.STREAM_ALARM, 5);
mSoundMap = new SparseIntArray(20);
mSoundMap.put(STATUS_NORMAL, mSoundPool.load(context, R.raw.normal, 1));
mSoundMap.put(STATUS_PICKUP, mSoundPool.load(context, R.raw.finished, 1));
mSoundMap.put(STATUS_NOEXIT, mSoundPool.load(context, R.raw.noexist, 1));
mSoundMap.put(STATUS_OTHER, mSoundPool.load(context, R.raw.error, 1));
mSoundMap.put(STATUS_RETRIEVE, mSoundPool.load(context, R.raw.quhui, 1));
mSoundMap.put(STATUS_WITHDRAW, mSoundPool.load(context, R.raw.tuihui, 1));
mSoundMap.put(STATUS_FLAG_WITHDRAW, mSoundPool.load(context, R.raw.daitui, 1)); mSoundMap.put(ERROR_yundan_cuowu, mSoundPool.load(context, R.raw.yundan_cuowu, 1));
mSoundMap.put(ERROR_yundan_chongfu, mSoundPool.load(context, R.raw.yundan_chongfu, 1));
mSoundMap.put(ERROR_yundan_yijiebo, mSoundPool.load(context, R.raw.yundan_yijiebo, 1));
mSoundMap.put(JIEBO_SUCCESS, mSoundPool.load(context, R.raw.success, 1));
mSoundMap.put(ERROR_JIEBO_PICI_INFO_ERROR, mSoundPool.load(context, R.raw.pici_info_error, 1));
mSoundMap.put(ERROR_WAYBILL_NOT_EXIST, mSoundPool.load(context, R.raw.waybill_not_exist, 1));
mSoundMap.put(ERROR_NO_PHONE_NUM, mSoundPool.load(context, R.raw.no_phone_num, 1));
mSoundMap.put(ERROR_NO_JIE_BO, mSoundPool.load(context, R.raw.no_jie_bo, 1));
} public void play(int statusid) {
if (mSoundMap.indexOfKey(statusid) != -1) {
mSoundPool.play(mSoundMap.get(statusid), 1f, 1f, 0, 0, 1);
}
} public void release() {
if (mSoundPool != null) {
mSoundPool.release();
}
} /**
* 读取文件到 sound pool
*
* @param resourceKey
* @param filePath
*/
public void loadSoundFile(int resourceKey, String filePath) {
int id = mSoundPool.load(filePath, 1);
mSoundMap.put(resourceKey, id);
} /**
* 从资源文件加载音频
*
* @param key
* @param resouceID
*/
public void loadFromResource(int key, int resouceID) {
mSoundMap.put(key, mSoundPool.load(context, resouceID, 1));
} public boolean exist(int soundKey) {
return mSoundMap.indexOfKey(soundKey) > 0;
} public void delete(int soundKey) {
int soundID = mSoundMap.get(soundKey);
if (soundID > 0) {
mSoundPool.unload(soundID);
mSoundMap.delete(soundKey);
}
}
}

语音提示辅助类MySoundAlertUtil的更多相关文章

  1. FreeSWITCH在呼叫失败的情况下播放语音提示

    看到好多网友问到这个问题.一般我们在打电话时会听到“您拨的电话正在通话中,请稍后再拨....”,或“电话无应答...”之类的提示,我们在 freeswitch 里也可以这样做. 其实很简单,默认的配置 ...

  2. 微信小程序语音提示

    一. 老规矩, 先上demo图:  然后通过 wx.createInnerAudioContext  创建内部 audio 上下文 InnerAudioContext 对象 就能播放 filename ...

  3. asp.net引用System.Speech实现语音提示

    using System; using System.Speech.Synthesis; namespace testvoice { class Program { static void Main( ...

  4. 主攻ASP.NET.4.5.1 MVC5.0之重生:Web项目语音朗读网页文本,简单语音提示浏览状态

    第一步 添加SpeechLib.dll 下载SpeechLib.dll: 在项目中并且引用DLL using SpeechLib; using System.Threading; 第二步 调用并使用 ...

  5. C# winform语音提示

    1.SpeechSynthesizer文字转音频 项目添加引用:System.Speech using(SpeechSynthesizer speech = new SpeechSynthesizer ...

  6. python语音提示

    #coding:utf8 import win32com.client speaker = win32com.client.Dispatch("SAPI.SpVoice") whi ...

  7. iOS开发笔记10:圆点缩放动画、强制更新、远程推送加语音提醒及UIView截屏

    1.使用CAReplicatorLayer制作等待动画 CALayer+CABasicAnimation可以制作很多简单的动画效果,之前的博客中介绍的“两个动画”,一个是利用一张渐变色图片+CABas ...

  8. 烽火2640路由器命令行手册-11-IP语音配置命令

    IP语音配置命令 目  录 第1章 配置拨号对命令... 1 1.1 配置拨号对命令... 1 1.1.1 dial-peer voice. 1 1.1.2 application. 2 1.1.3 ...

  9. Xamarin Essentials教程语音播报TextToSpeech

    Xamarin Essentials教程语音播报TextToSpeech   语音播报是一种将文本信息转化为音频信息的技术.使用该技术,开发者可以让用户不用盯着屏幕,就可以获取到信息.例如,支付宝为商 ...

随机推荐

  1. 在Ubuntu下安装gcc编译器+测试

    1.输入命令: sudo apt-get install gcc libc6-dev 2.创建文件hello.c使用命令: touch hello.c 3.在hello.c中写入:  #include ...

  2. 正则表达式(re)

    1.re.match(pattern, str, flag) 从str的第一个字母开始匹配,若不是开头的,尽管属于str内,则无法匹配. 2.贪婪匹配与非贪婪匹配(?) 贪婪匹配:尝试匹配尽可能多的字 ...

  3. Atlantis HDU - 1542

    Problem Description There are several ancient Greek texts that contain descriptions of the fabled is ...

  4. 使用Yeoman自动构建Ember项目

    Yeoman是什么? Yeoman按照官方说法,它不只是一个工具,还是一个工作流.它其实包括了三个部分yo.grunt.bower,分别用于项目的启动.文件操作.包管理. Yo: Yo是一个项目初始化 ...

  5. android 多行文本显示的textView

    package com.zhangyue.iReader.common.view; import android.content.Context; import android.graphics.Ca ...

  6. JavaScript - 问题集 - 含function的json对象与json字符串之间相互转换

    基本的转换为:JSON.parse与JSON.stringify. 但是json数据中含function,则转换后,function会丢失,如: var json={ test:'test', log ...

  7. Jenkins拾遗--第一篇(安装Jenkins)

    起因 近期由于工作需要做起了起了jenkins的维护.不做不知道,一搞发现里边全是小坑.两个月弄了一身泥.曾经小瞧了它,但是发现其实要弄好它不是那么容易的.有句知名的话"没有总结就没有提高. ...

  8. 【Balanced Binary Tree】cpp

    题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bin ...

  9. Python利器一之requests

    Python利器一之requests 一.教程涉及开发语言.脚本.框架.数据库等内容 Python + requests 通过 pip 安装: pip install requests 通过 easy ...

  10. 查看Linux系统用户登录日志

    日志: /var/log/wtmp说明: 此文件是二进制文件,查看方法如下:该日志文件永久记录每个用户登录.注销及系统的启动.停机的事件.因此随着系统正常运行时间的增加,该文件的大小也会越来越大,增加 ...