在WebRTC for iOS中测量麦克风级别 [英] Measure microphone level in WebRTC for iOS
问题描述
我有一个WebRTC iOS应用程序。
我有 AVAudioSession
和 RTCAudioSource
。
我需要检测麦克风何时开始接收响亮的声音(比如一个人开始说话时),类似于 hark 使用 AudioContext 在浏览器中执行操作。
如何检测它或获得类似于可以测量的流的内容,如 AVCaptureAudioChannel
或 AVCaptureAudioDataOutput
?
I have a WebRTC iOS application.
There I have AVAudioSession
and RTCAudioSource
.
I need to detect when a microphone starts receiving loud sounds (like when a person starts speaking) similar to what hark does in the browser with AudioContext.
How can I detect it or get something that resembles stream that can be measured like AVCaptureAudioChannel
or AVCaptureAudioDataOutput
?
推荐答案
使用 AVAudioSession
请求录制音频的权限后,我会建议使用 AVAudioRecorder。这是一个相当简单的类,并且非常简单:
After using AVAudioSession
to request permission to record audio, I would recommending using AVAudioRecorder. It is a fairly straightforward class and is as simple as:
- 创建<的实例code> AVAudioRecorder
- 在实例上调用方法
prepareToRecord
- 使用方法启用声音测光功能
meteringEnabled
- Create an instance of
AVAudioRecorder
- Call the method
prepareToRecord
on the instance - Enable the sound metering function using the method
meteringEnabled
启用录制后,您可以使用 averagePowerForChannel:
方法访问录制音量 测量 。
After enabling the recording, you can access the recording volume measurement using the method averagePowerForChannel:
.
您可能想要阅读Apple的文档
~~~~~~~~~~~~~~~~~~~~~ ~~~ 注意
~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~ N O T E
~~~~~~~~~~~~~~~~~~~~~~~
我不熟悉WebRTC框架/功能,但 AVAudioRecorder 类将使您能够在录制过程中测量音频输入。
I am not familiar with the WebRTC framework/functionality, but the AVAudioRecorder class will provide you with the ability to measure the audio input during a recording.
~~~~~~~~~~~~~~~~~~~~~~ SAMPLE
~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~ S A M P L E
~~~~~~~~~~~~~~~~~~~~~~
我已经包含了一个GitHub 示例项目,我过去曾使用过。设置为使用我所描述的AVAudioRecorder类检测音频的灵敏度。
I've included a GitHub sample project that I've used in the past. It is setup to detect sensitivity of the audio using the AVAudioRecorder class that I've described.
这篇关于在WebRTC for iOS中测量麦克风级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!