【问题标题】:How to calibrate an android device's microphone如何校准安卓设备的麦克风
【发布时间】:2016-07-12 22:10:53
【问题描述】:

我正在开展一个研究项目,该项目涉及使用 Android 设备记录社区噪音滋扰,以执行一些复杂的数字信号处理分析并计算一些指标。

我的主管指示我在将 Android 设备的麦克风分发到社区之前对其进行校准。我想知道是否有一种编程方式。

为什么要校准?

Android 设备的麦克风灵敏度可能与其他设备不同。即使是同一家公司的制造商也无法评论他们的敏感性。

因此,在相同的环境和条件下,一个 android 设备可能会录制 60 dB 的声音,而另一台设备可能会同时录制 70 dB 的声音。

我正在考虑以下几行 -> 在安静的环境中录制,然后在嘈杂的环境中录制。增益可以根据需要进行调整。这一点我还不是很清楚。

有没有任何程序化的方式来做到这一点?

非常感谢您对此的任何帮助。

【问题讨论】:

  • How to calibrate an external microphone device? 的可能重复项您刚刚问了一个几乎相同的问题。或许可以在之前的那个中添加一些细节。
  • 是的。我发布这个问题的原因是因为它是关于校准安卓智能手机的麦克风。由于在录音之前必须编写一个脚本来自动校准环境中的麦克风,所以我觉得这个问题与我问的另一个问题不同。

标签: android audio signal-processing recording calibration


【解决方案1】:

经过一番研究,我终于找到了一种校准安卓手机麦克风灵敏度的方法。

下面给出的代码是使用 android 中的 MediaRecorder 类将幅度生成为 dB 值。

import android.media.MediaRecorder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;

public class RecordingAudioThreshold extends AppCompatActivity {

    // This class generates the spectrogram of a wav file
    private MediaRecorder mediaRecorder = null;
    private Timer timerThread;
    private Button startRecording, stopRecording;
    private TextView recordingThreshold, recordingThresholdDB;
    int amplitude = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_generate_spectrogram);

        // Initialize the timer (used to cancel the thread if it's not running).
        timerThread = new Timer();

        // Method to calibrate the microphone
        startRecording = (Button) findViewById(R.id.button_startRecording);
        stopRecording = (Button) findViewById(R.id.button_stopRecording);
        recordingThreshold = (TextView) findViewById(R.id.textView_threshold);
        recordingThresholdDB = (TextView) findViewById(R.id.textView_thresholdDB);

        startRecording.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mediaRecorder = new MediaRecorder();
                mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
                mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
                mediaRecorder.setOutputFile("/dev/null");

                try {
                    mediaRecorder.prepare();
                    mediaRecorder.start();
                    System.out.println("Started Recording using Media Recorder");
                } catch (IOException e) {
                    System.out.println("Exception while recording of type : " + e.toString());
                }

                // start the timer to print the recorded values
                timerThread.schedule(new TimerTask() {
                    @Override
                    public void run() {
                        amplitude = mediaRecorder.getMaxAmplitude();
                        recordingThreshold.post(new Runnable() {
                            @Override
                            public void run() {
                                recordingThreshold.setText("The recorded value is : " + amplitude);
                            }
                        });
                        recordingThresholdDB.post(new Runnable() {
                            @Override
                            public void run() {
                                recordingThresholdDB.setText("The decibel value is : " + 20 * Math.log10(amplitude));
                            }
                        });
                    }
                }, 0, 500);
            }
        });

        stopRecording.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                timerThread.cancel();
                if (mediaRecorder != null) {
                    mediaRecorder.release();
                    mediaRecorder = null;
                }
                recordingThreshold.setText("Calibration complete.");
                recordingThresholdDB.setText("Calibration complete.");
            }
        });
    }
}

现在有两种方法可以调整麦克风的灵敏度。一种方法是使用校准的录音设备,第二种方法是生成已知值的声音。

测量手机麦克风和校准的录音设备测量的音量(以 dB 为单位)并调整增益。

产生已知值的声音并调整增益。

两者都很好用,但我更喜欢使用录音设备。

【讨论】:

  • 不错!请注意,麦克风可能不会对所有频率都同样敏感。
  • 这是一个很好的观点。 Android 设备麦克风专为人类敏感的频率量身定制。
  • 嗯,麦克风仍然可能会漏掉一些人类可以完全听到的高音或低音,并且在其他频率周围会有很大的不同。来源blog.faberacoustical.com/2009/ios/iphone/…
猜你喜欢
  • 1970-01-01
  • 2015-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-02
相关资源
最近更新 更多