-1

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.

callyalater
  • 3,102
  • 8
  • 20
  • 27
  • If there is no sound, your variables ("v", "mean", "volumn") is equal to zero. – anhtuannd Oct 25 '16 at 08:49
  • i solution my problem with http://stackoverflow.com/questions/28013253/android-make-a-recorded-pcm-raw-data-playable?nsukey=E%2FFfeAOIKqB0Nzt29eUIERVepOmA%2FzjyWASFhyoL0ZH%2B2280wYaLSiiMszZfjGt9JdMHMh4PwGAVYjHWtrJFmLCtogY3HBjNRKoQO8ceWSpVIkldYa2PcLzclLsT5LE1yMcONwZ1SSmRHnM0lRG0ccEd4kpTnC%2FB48LG4%2FDKYj7zvRKhvOA7lqF8mMfIVnk4 – jianxiong.sun Nov 03 '16 at 08:27

1 Answers1

0

If there is no sound, your variables ("v", "mean", "volumn") is equal to zero. I guess you don't have permission for audio recording.

First, please check if you have audio record permission in Manifest file.

<uses-permission android:name="android.permission.RECORD_AUDIO"/>

If tested device running Marshmallow, you need to request permission at runtime: https://developer.android.com/training/permissions/requesting.html

anhtuannd
  • 918
  • 9
  • 16
  • I am sure that get this perminssion.v,mean,volumn is not equal to zero,it is a fixed value like 31.5;31.3;31.4;31.7;30.5.when i speak or does not speak。the right device can get the value list like this 15.1;16.2;13.3;30.1;33.5;34.2;35.4;12.0;14.5,13.2; – jianxiong.sun Oct 25 '16 at 09:58