声音测量反应原生

时间:2017-12-08 07:55:53

标签: android audio react-native

我正在建立一个反应原生的应用程序。 我试图计量当前的声级(以分贝为单位)。

正在使用的图书馆:react-native-audioreact-native-sound

有没有人熟悉这个功能?

谢谢。

2 个答案:

答案 0 :(得分:1)

您可以使用react-native-audio currentMetering 值 - 以实时获取声级。

首先,你必须初始化你的录音机(我假设你已经完成了)。我以类似于下面的方式使用prepareRecordingAtPath

AudioRecorder.prepareRecordingAtPath(audioPath, {
  SampleRate: 22050,
  Channels: 1,
  AudioQuality: "Low",
  AudioEncoding: "aac",
  MeteringEnabled: true
});

然后,当您拨打AudioRecorder.startRecording();时(请注意,您还可以访问.pause().stop()方法

现在,为了处理音频级别,您将不得不检索onProgress方法返回的数据。根据我的记忆,您应该可以访问一些currentMetering值。请注意,定义此行为将在每次检索到不同的分贝读数时触发操作。像这样

AudioRecorder.onProgress = data => {
    let decibels = Math.floor(data.currentMetering);

    //DO STUFF
  };

希望这有帮助,

答案 1 :(得分:0)

使用react-native-audio库,您可以获得唯一的iOS的计数。

对于Android中的currentMetering,您需要在本机模块中进行自定义。我已经更新了它,在您的package.json文件中而不是您的代码中添加了以下内容。您将获得Android和iOS的currentMetering计数。

"react-native-audio": "git+https://github.com/Harsh2402/react-native-audio.git",
相关问题