在android中测量噪音

时间:2013-04-13 18:17:33

标签: android audio audio-recording

我能够在android中通过语音识别来检测语音,但是想要测量语音的强度,并且在测量强度之后执行相应的任务。 我这样做:

   @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.voicerecogscreen);

    speakButton = (Button) findViewById(R.id.speakButton);

    wordsList = (ListView) findViewById(R.id.list);
    PackageManager pm = getPackageManager();
    List<ResolveInfo> activities = pm.queryIntentActivities(
            new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    if (activities.size() == 0)
    {
        speakButton.setEnabled(false);
        speakButton.setText("Recognizer not present");
    }        
}

/**
 * Handle the action of the button being clicked
 */
public void speakButtonClicked(View v)
{
    startVoiceRecognitionActivity();
}

/**
 * Fire an intent to start the voice recognition activity.
 */
private void startVoiceRecognitionActivity()
{
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice recognition Demo...");
    startActivityForResult(intent, REQUEST_CODE);        
}

/**
 * Handle the results from the voice recognition activity.
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK)
    {

        ArrayList<String> matches = data.getStringArrayListExtra(
                RecognizerIntent.EXTRA_RESULTS);
        wordsList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
                matches));
}

1 个答案:

答案 0 :(得分:1)

通常使用AudioRecord测量音频功率(强度),您将获得PCM数据 但是我怀疑你在使用Speech Recognizer“不确定”时可以这样做。但这种方法如果有效,应该会给你带来高质量的结果。

如果不起作用:

SpeechRecognizer Listener API中有:onRMSChangedonBufferReceived

其中:

  • onRMSChanged 为您提供音频信号的当前RMS值(信号有多强)
  • onBufferReceived AudioRecorder应使用相同的技术从PCM示例中查找RMS值。看看here

注意:并非所有SpeechRecognizerListener API都会在所有设备上调用,因此您需要小心并使用测试驱动的方法来解决此问题。