java-speech-api icon indicating copy to clipboard operation
java-speech-api copied to clipboard

calculateEnergy

Open nalbion opened this issue 8 years ago • 0 comments

This VAD algorithm suggests to calculate the energy of each frame. ...Is that the same as RMS?

This code of Sciss/SpeechRecognitionHMM seems to be using a different algorithm:

        public double[] calcEnergy(float[][] framedSignal) {
		double[] energyValue = new double[framedSignal.length];
		for (int i = 0; i < framedSignal.length; i++) {
			float sum = 0;
			for (int j = 0; j < samplePerFrame; j++) {
				// sum the square
				sum += Math.pow(framedSignal[i][j], 2);
			}
			// find log
			energyValue[i] = Math.log(sum);
		}
		return energyValue;
	}

MicrophoneAnalyser:

        public static int calculateRMSLevel(byte[] audioData){
		long lSum = 0;
		for(int i=0; i<audioData.length; i++)
			lSum = lSum + audioData[i];

		double dAvg = lSum / audioData.length;

		double sumMeanSquare = 0d;
		for(int j=0; j<audioData.length; j++)
			sumMeanSquare = sumMeanSquare + Math.pow(audioData[j] - dAvg, 2d);

		double averageMeanSquare = sumMeanSquare / audioData.length;
		return (int)(Math.pow(averageMeanSquare,0.5d) + 0.5);
	}

nalbion avatar Jul 12 '17 04:07 nalbion