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

通常、オーディオ パワー (強度) を測定するには、AudioRecordSpeech Recognizerを使用して PCM データを取得しますが、 「わからない」 を使用しているときにそれができるとは思えません。しかし、この方法が機能すれば、質の高い結果が得られるはずです。

うまくいかなかった場合:

SpeechRecognizer Listener APIには、 onRMSChangedonBufferReceivedがあります。

どこ:

  • onRMSChangedは、オーディオ信号の現在の RMS 値 (信号の強さ) を示します。
  • onBufferReceivedAudioRecorder同じ手法を使用して、PCM サンプルから RMS 値を見つける必要があります。ここを見てください

注:SpeechRecognizerListenerすべてのデバイスですべての API が呼び出されるわけではないため、この問題には注意してテスト主導のアプローチを使用する必要があります。

于 2013-04-13T18:31:54.897 に答える