测量android的噪音



我可以通过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));
}

通常要测量音频功率(强度),您将使用AudioRecord获得PCM数据但我怀疑你在使用Speech Recognizer时是否能做到这一点。但是这种方法如果有效的话,应该会得到高质量的结果。

如果它不工作:

在语音识别Listener API有:onRMSChanged和onBufferReceived

地点:

  • onRMSChanged给出音频信号的当前RMS值(信号的强度)
  • onBufferReceivedAudioRecorder应该使用相同的技术从PCM样本中找到RMS值。请看这里

注意:不是所有的SpeechRecognizerListener api在所有设备上被调用,所以你需要小心,并使用测试驱动的方法来解决这个问题。

最新更新