语音提示辅助类MySoundAlertUtil
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的更多相关文章
- FreeSWITCH在呼叫失败的情况下播放语音提示
看到好多网友问到这个问题.一般我们在打电话时会听到“您拨的电话正在通话中,请稍后再拨....”,或“电话无应答...”之类的提示,我们在 freeswitch 里也可以这样做. 其实很简单,默认的配置 ...
- 微信小程序语音提示
一. 老规矩, 先上demo图: 然后通过 wx.createInnerAudioContext 创建内部 audio 上下文 InnerAudioContext 对象 就能播放 filename ...
- asp.net引用System.Speech实现语音提示
using System; using System.Speech.Synthesis; namespace testvoice { class Program { static void Main( ...
- 主攻ASP.NET.4.5.1 MVC5.0之重生:Web项目语音朗读网页文本,简单语音提示浏览状态
第一步 添加SpeechLib.dll 下载SpeechLib.dll: 在项目中并且引用DLL using SpeechLib; using System.Threading; 第二步 调用并使用 ...
- C# winform语音提示
1.SpeechSynthesizer文字转音频 项目添加引用:System.Speech using(SpeechSynthesizer speech = new SpeechSynthesizer ...
- python语音提示
#coding:utf8 import win32com.client speaker = win32com.client.Dispatch("SAPI.SpVoice") whi ...
- iOS开发笔记10:圆点缩放动画、强制更新、远程推送加语音提醒及UIView截屏
1.使用CAReplicatorLayer制作等待动画 CALayer+CABasicAnimation可以制作很多简单的动画效果,之前的博客中介绍的“两个动画”,一个是利用一张渐变色图片+CABas ...
- 烽火2640路由器命令行手册-11-IP语音配置命令
IP语音配置命令 目 录 第1章 配置拨号对命令... 1 1.1 配置拨号对命令... 1 1.1.1 dial-peer voice. 1 1.1.2 application. 2 1.1.3 ...
- Xamarin Essentials教程语音播报TextToSpeech
Xamarin Essentials教程语音播报TextToSpeech 语音播报是一种将文本信息转化为音频信息的技术.使用该技术,开发者可以让用户不用盯着屏幕,就可以获取到信息.例如,支付宝为商 ...
随机推荐
- laravel查看执行的sql语句
方法一: 我们有时候想测试一段代码生产的 SQL 语句,比如: 我们想看 App\User::all(); 产生的 SQL 语句,我们简单在 routes.php 做个实验即可: //app/Http ...
- 2.1 <script>元素【JavaScript高级程序设计第三版】
向 HTML 页面中插入 JavaScript 的主要方法,就是使用<script>元素.这个元素由 Netscape 创造并在 Netscape Navigator 2 中首先实现.后来 ...
- POJ:3421-X-factor Chains(因式分解)(全排列)
X-factor Chains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7986 Accepted: 2546 Descr ...
- issubclasss/type/isinstance/callable/super
issubclass() : 方法用于判断第一个参数是否是第二个参数的子子孙孙类. 语法:issubclass(sub, super) 检查sub类是否是 super 类的派生类 class A: p ...
- html---Web Storage存储
在HTML5中,除了Canvas元素之外,另一个新增的非常重要的功能是可以在客户端本地保存数据的Web Storage功能,之前可以使用Cookies在客户端保存如用户名等简单用户信息,但通过长期使用 ...
- 分布式缓存技术memcached学习系列(一)——linux环境下编译memcahed
安装依赖工具 [root@localhost upload]# yum install gcc make cmake autoconf libtool 下载并上传文件 memcached 依 ...
- Hyper-V中的Linux无法配置网络地址的解决办法
一周碰到2次在Hyper-V 2012中安装了Linux,也安装了IC 3.4.但是却无法配置IP地址的问题.因此造成很多不便,因此找机会把这个原因和解决办法进行了尝试. 这过程中感谢同事的提示,让我 ...
- Java 注解(Annoation)学习笔记
1 Junit中的@Test为例: 1.1 用注解(@Test)前 private boolean isTestMethod(Method m) { return m.getParameterType ...
- shell脚本从文件夹中递归提取文件
需求 前两天碰到需要在十层左右的文件夹中提取文件的需求,于是写了此脚本. 如下面这样的文件结构: dir1 ├── a │ ├── b │ │ └── file1 │ └── file2 ├── c ...
- windows 下开发的 .netCore MVC 部署到 Linux(Mint)
这两天在公司跟同事偶然聊到 .netCore,说到一些趋势什么的.但是说来说去自己也没试过在Linux 机子上部署过,所以就试一下. 尝试之前也在网上看了一些文章,包括 Linux 上.netCore ...