获取麦克风音量 [英] Get Microphone volume

查看:149
本文介绍了获取麦克风音量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能得到的音频流通过Android麦克风的卷中的?

How can I get the volume of the audio stream coming in through the android microphone?

推荐答案

有可能是一个更简单的方法,但是,我知道将工作的方法是使用 AudioRecord 配置为观看 MediaRecorder.AudioSource.MIC 音频源,并记录在8位(对象AudioFormat.ENCODING_PCM_8BIT <$ C C $> )。您将需要一个线程在后台运行,并不断查询对象音频与阅读()调用,它填补了一个给定的字节数组,从麦克风音频数据。

There may be a simpler way, but a method that I know would work is to use an AudioRecord object that is configured to watch the MediaRecorder.AudioSource.MIC audio source and record in 8-bit (AudioFormat.ENCODING_PCM_8BIT). You would need a thread to run in the background and constantly poll the object for audio with the read() call, which fills a given byte array with audio data from the mic.

由于您正在录制8位,最大范围内的每个音频采样是-128到127(虽然我可能都有这个毛病 - 它可能是从0到256)。你将不得不尝试走无论是从返回的字节数组的最大震级字节,或者也许是RMS平均根据您的应用程序的需要。字节数组的大小也将决定如何经常你的应用程序能够采样输入音频音量扮演一个角色。

Because you are recording in 8-bit, the max range of each audio sample would be -128 to 127 (although I may have this wrong - it could be from 0 to 256). You would have to experiment with taking either the maximum magnitude byte from the returned byte array, or perhaps the RMS average depending on your application's needs. The size of the byte array would also play a part in determining how frequently your application is able to sample the input audio volume.

这篇关于获取麦克风音量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆