Android AudioRecord录音音量大小

时间:2025-01-30 11:00:05
private doublecalculateVolume(byte[] buffer){ double sumVolume = 0.0; double avgVolume = 0.0; double volume = 0.0; for(int i = 0; i < ; i+=2){ int v1 = buffer[i] & 0xFF; int v2 = buffer[i + 1] & 0xFF; int temp = v1 + (v2 << 8);// 小端 if (temp >= 0x8000) { temp = 0xffff - temp; } sumVolume += (temp); } avgVolume = sumVolume / / 2; volume = Math.log10(1 + avgVolume) * 10; return volume; }