Silence Removal and End Point Detection JAVA Code(音频删除静音与结束判断)
转载自:http://ganeshtiwaridotcomdotnp.blogspot.com/2011/08/silence-removal-and-end-point-detection_29.html
For the purpose of silence removal of captured sound, we used the algorithm in our final year project.
In this post, I am publishing the endpoint detection and silence removal code ( implementation of this algorithm in JAVA).
These links might be useful to you as well.
- For Capturing audio from microphone
- For Converting captured data into PCM integer or float array
- For Playing any PCM array of amplitudes
The constructor of following java class EndPointDetection takes two parameters
- array of original signal's amplitude data : float[] originalSignal
- sampling rate of original signal in Hz : int samplingRate
package org.ioe.tprsa.audio.preProcessings;
/**
* @author Ganesh Tiwari
* @reference 'A New Silence Removal and Endpoint Detection Algorithm
* for Speech and Speaker Recognition Applications' by IIT, Khragpur
*/
public class EndPointDetection {
private float[] originalSignal; //input
private float[] silenceRemovedSignal;//output
private int samplingRate;
private int firstSamples;
private int samplePerFrame;
public EndPointDetection(float[] originalSignal, int samplingRate) {
this.originalSignal = originalSignal;
this.samplingRate = samplingRate;
samplePerFrame = this.samplingRate / 1000;
firstSamples = samplePerFrame * 200;// according to formula
}
public float[] doEndPointDetection() {
// for identifying each sample whether it is voiced or unvoiced
float[] voiced = new float[originalSignal.length];
float sum = 0;
double sd = 0.0;
double m = 0.0;
// 1. calculation of mean
for (int i = 0; i < firstSamples; i++) {
sum += originalSignal[i];
}
m = sum / firstSamples;// mean
sum = 0;// reuse var for S.D. // 2. calculation of Standard Deviation
for (int i = 0; i < firstSamples; i++) {
sum += Math.pow((originalSignal[i] - m), 2);
}
sd = Math.sqrt(sum / firstSamples);
// 3. identifying one-dimensional Mahalanobis distance function
// i.e. |x-u|/s greater than ####3 or not,
for (int i = 0; i < originalSignal.length; i++) {
if ((Math.abs(originalSignal[i] - m) / sd) > 0.3) { //0.3 =THRESHOLD.. adjust value yourself
voiced[i] = 1;
} else {
voiced[i] = 0;
}
}
// 4. calculation of voiced and unvoiced signals
// mark each frame to be voiced or unvoiced frame
int frameCount = 0;
int usefulFramesCount = 1;
int count_voiced = 0;
int count_unvoiced = 0;
int voicedFrame[] = new int[originalSignal.length / samplePerFrame];
// the following calculation truncates the remainder
int loopCount = originalSignal.length - (originalSignal.length % samplePerFrame);
for (int i = 0; i < loopCount; i += samplePerFrame) {
count_voiced = 0;
count_unvoiced = 0;
for (int j = i; j < i + samplePerFrame; j++) {
if (voiced[j] == 1) {
count_voiced++;
} else {
count_unvoiced++;
}
}
if (count_voiced > count_unvoiced) {
usefulFramesCount++;
voicedFrame[frameCount++] = 1;
} else {
voicedFrame[frameCount++] = 0;
}
}
// 5. silence removal
silenceRemovedSignal = new float[usefulFramesCount * samplePerFrame];
int k = 0;
for (int i = 0; i < frameCount; i++) {
if (voicedFrame[i] == 1) {
for (int j = i * samplePerFrame; j < i * samplePerFrame + samplePerFrame; j++) {
silenceRemovedSignal[k++] = originalSignal[j];
}
}
}
// end
return silenceRemovedSignal;
}
}
The MATLAB implementation of this algorithm is also available.
问:Hi ganesh, So Is impossible listen the voice after normalizePCM and endpointdetection?
答:you can play the recorded audio after doing those time domain operations.
you need to play the pcm array using the code : http://ganeshtiwaridotcomdotnp.blogspot.com/2011/12/java-audio-playing-pcm-amplitude-array.html
you can find other codes related to sound processing in java here :
http://ganeshtiwaridotcomdotnp.blogspot.com/search/label/Audio%20Processing
Silence Removal and End Point Detection JAVA Code(音频删除静音与结束判断)的更多相关文章
- Silence Removal and End Point Detection MATLAB Code
转载自:http://ganeshtiwaridotcomdotnp.blogspot.com/2011/08/silence-removal-and-end-point-detection.html ...
- Java语言编码规范(Java Code Conventions)
Java语言编码规范(Java Code Conventions) 名称 Java语言编码规范(Java Code Conventions) 译者 晨光(Morning) 简介 本文档讲述了Java语 ...
- java code to byte code--partone--reference
Understanding how Java code is compiled into byte code and executed on a Java Virtual Machine (JVM) ...
- [转]Java Code Examples for android.util.JsonReader
[转]Java Code Examples for android.util.JsonReader The following are top voted examples for showing h ...
- SQL to Java code for Elasticsearch
Elasticsearch虽然定位为Search Engine,但是因其可以持久化数据,很多时候,我们把Elasticsearch当成Database用,但是Elasticsearch不支持SQL,就 ...
- JUnit单元测试教程(翻译自Java Code Geeks)
JUnit单元测试教程--终极指南 JUnit单元测试教程终极指南 说明 单元测试简介 1 什么是单元测试 2 测试覆盖 3 Java中的单元测试 JUnit简介 1 使用Eclipse实现简单JUn ...
- Java Code Style
近期困惑于团队成员代码风格迥异,代码质量不可控,作为一名老司机,忧患于后期服务的可维护性,多次一对一的代码Review,耗时耗力不说,效果也不明显.痛定思痛,多次反思之后得出结论:无规矩不成方圆,可靠 ...
- 玩转Eclipse — 自动代码生成的Java Code Template
文章转载地址:点击打开链接 当代码写到一定程度之后,就会发现很多代码都被重复地敲了N多遍,甚至毫不夸张地说:闭着眼睛都能敲出来.大量地敲这些重复地代码,除了锻炼敲键盘的速度,基本上没有其他益处,但是长 ...
- Use formatter to format your JAVA code
In order to make the codes looks unified and make it easy to understand, it's better to use the same ...
随机推荐
- 如何从notepad++的偏移量查找
有的时候报错的会把偏移量直接报错给我们,我就需要根据偏移量定位我们的错误. 比如他报错偏移量1009. 做搜索(按Ctrl + F) 选择Regular expressions并确保有. matche ...
- 堆优化/zkw线段树优化 dijkstra
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; const int MAXM = 200005 ...
- Bootstrap是什么意思?
Bootstrap是一组用于网站和网络应用程序开发的开源前端(所谓“前端”,指的是展现给最终用户的界面.与之对应的“后端”是在服务器上面运行的代码)框架,包括HTML.CSS及JavaScript的框 ...
- web文件上传下载组件
最近遇见一个需要上传百兆大文件的需求,调研了七牛和腾讯云的切片分段上传功能,因此在此整理前端大文件上传相关功能的实现. 在某些业务中,大文件上传是一个比较重要的交互场景,如上传入库比较大的Excel表 ...
- AGC 030 B - Tree Burning 结论+枚举
考试 T2,是一个脑筋急转弯. 最暴力的贪心是每次先选左,再选右,再选左..... 然而这么做在一些情况下是错的. 但是,我们发现我们的选法一定是 $LLLLRLRLRLRLR$ 或 $RRRRLRL ...
- QtWebEngineWidgets
我用的qt5.10+VS2017,2013应该一样项目属性里手动添加包含目录:(QTDIR)\include\QtWebEngineWidgets,(QTDIR)\include\QtWebChann ...
- cube.js 学习(一)简单项目创建
cube.js 是一个很不错的模块化分析框架,基于schema生成sql 同时内置可代码生成,可以快速的搞定 web 分析应用的开发 安装cli 工具 npm install -g cubejs-cl ...
- bg/fg/jobs
用于将某个任务放置后台运行,一般会与 ctrl+ z , fg, & 符号联用. 典型的场景就是将耗时的任务放于后台运行,例如打包某个占用空间大的目录,
- 【Python】安装MySQLdb模块centos 6.1 宝塔Linux面板 MySQL5.6
[Python]安装MySQLdb模块centos 6.1 宝塔Linux面板 MySQL5.6 总之是各种坑 先说一下,宝塔安装在centos 6.1 i368 也就是32位系统上的方法 https ...
- 信竞四定律orz
正常代码不写#define @zdx 平时刷题不写freopen @liuziwen 循环内部不写return 0 @asdfo123 主程序内不写char array @asdfo123 输出时间: ...