So far:
byte data[] = new byte[recBufSize];
read = audioRecord.read(data, 0, recBufSize);
long v = 0;
for (int i = 0; i < data.length; i++) {
v += Math.abs(data[i]);
}
double mean = v / (double) read;
final double volume = 20 * Math.log10(mean);
Some devices work as expected, but when running on other devices, the values of v
, mean
and volume
don't change.
I want to get a value to determine whether the user is speaking or not.
这个demo一台设备上面可以如期运行,volume在不说话和说话时候波动比较大,但是再另外一些设备上基本上就没有什么波动。
Translation:
In this demo, the volume is either muted or really loud when it runs on one device, but on a different device, there are basically no other fluctuations.