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. 中缀表达式转后缀表达式(Python实现)

    中缀表达式转后缀表达式 中缀表达式转后缀表达式的规则: 1.遇到操作数,直接输出: 2.栈为空时,遇到运算符,入栈: 3.遇到左括号,将其入栈: 4.遇到右括号,执行出栈操作,并将出栈的元素输出,直到 ...

  2. python flask学习第2天 URL中两种方式传参

    新创建项目   自己写个url映射到自定义的视图函数 在url中传递参数 app.py from flask import Flask app = Flask(__name__) @app.route ...

  3. 我理解中的Hadoop HDFS分布式文件系统

    一,什么是分布式文件系统,分布式文件系统能干什么 在学习一个文件系统时,首先我先想到的是,学习它能为我们提供什么样的服务,它的价值在哪里,为什么要去学它.以这样的方式去理解它之后在日后的深入学习中才能 ...

  4. STM8 输出比较极性

    PWM输出的信号极性有两个选项决定,一个选项是PWM模式,另一个选项是输出极性控制位. 请看定时器的框图,PWM模式的选择决定OC1REF的极性, 例如当选择PWM1模式时,OC1REF信号是&quo ...

  5. Django的Field(字段)

    字段 1.models.AutoField 自增列 = int(11) 如果没有的话,默认会生成一个名称为 id 的列,如果要显示的自定义一个自增列,必须将给列设置为主键 primary_key=Tr ...

  6. 使用Matrix-tree与它的行列式来解决生成树计数问题

    我又把Matrix写错啦 这东西讲课的时候竟然一笔带过了,淦 好吧这东西我不会证 那我们来愉快的看结论吧 啦啦啦 预备工作 你有一个 $ n $ 个点的图 比如说 5 /|\ / | \ 2--1-- ...

  7. LC.exe已退出,代码为-1

    解决方法就是把Properties文件下的license.licx给删除,重新编译,这样就可以了.

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

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

  9. 《Cracking the Coding Interview》——第2章:链表——题目4

    2014-03-18 02:27 题目:将一个单链表按照一个值X分为两部分,小于X的部分放在大于等于X的部分之前. 解法:按照值和X的大小,分链表为两条链表,然后连起来成一条. 代码: // 2.4 ...

  10. 【vim环境配置】详细实录

    [写在前面] 以下的所有内容主要参照: https://github.com/yangyangwithgnu/use_vim_as_ide . 原blog作者写的非常用心,建议大家都去看看.(个人觉得 ...