音频相似度对比 Demo

#简单的音频相似度对比 Demo

##环境
AndroidStudio、MATLAB、Audacity
##基本思路和流程
1. 录音,保存音频数据
2. 从二进制文件中获取音频原始数据
3. 音频滤波
4. 计算音频信号短时能量
5. 截取音频信号有效数据
6. 对对比音频数据进行同上操作
7. 计算标准音频与对比音频数据的余弦距离

##核心代码

	import java.io.DataInputStream;
	import java.io.IOException;
	
	/**
	 * Created by lzy on 2015/11/18.
	 */
	public class AudioDataOperate {
	
	    public static final int TYPE_16BIT = 1;
	    public static final double DATA_START_VALUE = 0.025;
	    public static final double DATA_END_VALUE = 0.025;
	
	    /**
	     * 按编码类型提取音频数据
	     *
	     * @param dis
	     * @param size
	     * @param type
	     * @return
	     */
	    public static short[] getAudioData(DataInputStream dis, int size, int type) {
	        short[] audioData = new short[size];
	        try {
	            byte[] tempData = new byte[2];
	            long audioDataSize = 0;
	            while (dis.read(tempData) != -1) {
	                // 每16位读取一个音频数据
	                audioData[(int) audioDataSize] = (short) (((tempData[0] & 0xff) << 8) | (tempData[1] & 0xff));
	                audioDataSize++;
	                if (audioDataSize == size) {
	                    break;
	                }
	            }
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return audioData;
	    }
	
	    /**
	     * 归一化
	     */
	    public static double[] normalize(short[] data) {
	        short max = findMax(data);
	        double[] result = new double[data.length];
	        for (int i = 0; i < data.length; i++) {
	            result[i] = ((double) data[i] / max);
	        }
	        return result;
	    }
	
	    /**
	     * 归一化
	     */
	    public static doub
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值