0

我可以借助 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));
}
4

1 回答 1

1

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

如果它不起作用:

在SpeechRecognizer Listener API中有:onRMSChangedonBufferReceived

在哪里:

  • onRMSChanged为您提供音频信号的当前 RMS 值(信号有多强)
  • onBufferReceived并且AudioRecorder应该使用相同的技术从 PCM 样本中查找 RMS 值。看看这里

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

于 2013-04-13T18:31:54.897 回答