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 ...
随机推荐
- python列表命令
创建普通列表:member;: 创建混合列表:mix: 创建空列表:empty >>> member = ['lala','oo'] >>> member ['la ...
- SIGAI机器学习第二十集 AdaBoost算法1
讲授Boosting算法的原理,AdaBoost算法的基本概念,训练算法,与随机森林的比较,训练误差分析,广义加法模型,指数损失函数,训练算法的推导,弱分类器的选择,样本权重削减,实际应用 AdaBo ...
- PHP流程控制之for循环控制语句
王同学反复往返与北京和大连,并且在本上记录往返次数.在PHP中还有另外一种实现方式能够实现同样的计数.无锡大理石测量平台 for 循环是 PHP 中的一种计数型循环,它的语法比较数活多变.这是一个必须 ...
- MongoDB 常用操作命令大全
一.数据库常用命令1.Help查看命令提示 复制代码 代码如下: helpdb.help();db.yourColl.help();db.youColl.find().help();rs.help() ...
- declare/typeset
用来生命变量的,作用完全一样. 不像C语言那样严谨的语法,变量在使用前必须声明. 但是在shell中对变量的声明要求并不高,因为shell弱化了变量的类概念,所以shell被称为弱类型语言, 声明变量 ...
- Centos 7 安装 dotnet 环境
Centos 7 安装 dotnet 环境 下载官方 rpm yum 源 直接 yum install 安装rpm -Uvh https://packages.microsoft.com/confi ...
- 二维$MLE$线段树
关于二维线段树,ta死了 先来看看两种二维线段树的打法 1.四叉树 然而ta死了,ta是$\Theta (n)$的,加上线段树的常数,$T$飞稳 2.线段树套线段树 我尽量画出来... 图中每个方块是 ...
- C++标准库分析总结(九)——<HashFunction、Tuple>
一.HashFunction 当我们在使用hash table以及由它做底层的数据结构时,我们必不可少要讨论hash function,所谓的哈希函数就是产生一个数,这个数越乱越好,以至于达到避免碰撞 ...
- 登录科普(一)CAS与Oauth
https://www.jianshu.com/p/18aedcaf47f2 CAS的单点登录,资源都在客户端这边,不在CAS的服务器那一方. 用户在给CAS服务端提供了用户名密码后,作为CAS客户端 ...
- Python中单引号和双引号的作用
一.单引号和双引号 在Python中我们都知道单引号和双引号都可以用来表示一个字符串,比如 str1 = 'python' str2 = "python" str1和str2是没有 ...