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. php-5.6.26源代码 - opcode处理器的注入

    .初始化 opcode处理器列表 // main实现在文件“php-5.6.26\sapi\cgi\cgi_main.c” int main(int argc, char *argv[]) { if ...

  2. PLC状态机编程第二篇-负载均衡

    控制任务 大家好,今天我们用状态机描述稍复杂的实例,同时用LAD和ST语言写状态机.我们的控制任务如下: 真空泵A和真空泵B, 按下启动按钮后, 泵A启动, 3秒后泵B也启动, 此时泵A仍运行, 当容 ...

  3. python 学习心得

    多用类或是函数 我以前写的时候,不用函数,从头写到尾,后来,要改成函数,也是要花很多测试的时间,改的话还得一个调试,如果一开始就用函数的话,就能节省很多时间. 函数的功能尽可能的小 比如说像我用try ...

  4. mysql sum 为 0 的解决方法

    使用SQL语句SUM函数的时候,默认查询没有值的情况下返回的是null,而实际可能我们要用的是返回0. 解决方法:SELECT SUM(count) FROM test_table 改成: SELEC ...

  5. 笔记-python-lib-chardet

    笔记-python-lib-chardet 1.      chardet chardet是一个非常优秀的编码识别模块, 是python的第三方库,需要下载和安装. 文档地址:https://pypi ...

  6. MySQL 5.7远程连接

    将/etc/mysql/my.cnf中的bind_address那一行注释掉或修改为"bind_address=0.0.0.0": bind_address并没有在/etc/mys ...

  7. Python 外部函数调用库ctypes简介

    Table of Contents 1. 参考资料 2. ctypes简介 2.1. 数据类型 2.2. 调用.so/.dll 2.2.1. 加载动态链接库 2.2.2. 调用加载的函数 2.2.3. ...

  8. CSS3裁剪与遮罩解析

    一.用途 CSS3裁剪与遮罩(Clipping and Masking)用来隐藏元素的一部分而显示另一部分 二.区别 CSS3裁剪与遮罩(Clipping and Masking)用来隐藏元素的一部分 ...

  9. javascript类式继承模式#2——借用构造函数

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. DOS程序员手册(五)

    第8章磁           盘       学习编程语言,常常是从基本的输入和输出入手的(正如第5.6和第7章曾介绍的一 样).到目前为止,我们不仅学习了怎样输入和输出数据,还学习了如何进行数据操作 ...