语音识别:单词之间的差距

时间:2016-02-01 20:54:36

标签: android voice-recognition

我有一个简单的语音识别应用程序,可以打印所有可能的字符串ArrayList解码。问题是它只有在我不停止/暂停单词之间才有效。如果我有一点暂停(非常短暂,好像我正常拼写)应用程序停止。我查看了参数SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,但它没有改变任何内容。

语音识别专家的任何线索?

这是我的代码:

package com.bernard.vtt;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.ArrayList;

public class MainActivity extends Activity implements RecognitionListener {
    private TextView mText;
    SpeechRecognizer speech = null;
    private Intent recognizerIntent;

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button speakButton = (Button) findViewById(R.id.btn);
    mText = (TextView) findViewById(R.id.textView1);

    speech = SpeechRecognizer.createSpeechRecognizer(this);
    speech.setRecognitionListener(this);
    recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE,
            "en");
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
            this.getPackageName());
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);

    speakButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            speech.startListening(recognizerIntent);
        }
    });

}

@Override
public void onResults(Bundle results) {
    ArrayList<String> matches = results
            .getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
    String text = "";
    assert matches != null;
    for (String result : matches)
        text += result + "\n";

    mText.setText(text);

    speech.stopListening();
}

@Override
public void onReadyForSpeech(Bundle params) {

}

@Override
public void onBeginningOfSpeech() {

}

@Override
public void onRmsChanged(float rmsdB) {

}

@Override
public void onBufferReceived(byte[] buffer) {

}

@Override
public void onEndOfSpeech() {

}

@Override
public void onError(int error) {

}

@Override
public void onPartialResults(Bundle partialResults) {

}

@Override
public void onEvent(int eventType, Bundle params) {

}

1 个答案:

答案 0 :(得分:4)

我相信内置的语音识别不会持续运行。它旨在听到一个语音输入并给出结果。如果要继续侦听,则需要在每个onResults回调上重新启动识别。我也相信SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS有一个最大值,这就是改变它的原因很少。