繁体   English   中英

如何在Google Recognizer Intent(语音识别)Android中增加语音收听时间

[英]How to increase the voice listen time in Google Recognizer Intent(Speech Recognition) Android

我确实尝试给毫秒以下这些额外的时间

Recognizer Intent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS
Recognizer Intent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS
Recognizer Intent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS

但不会影响语音收听时间! 我现在获得的语音收听时间仅为3秒! 我如何获得10秒的聆听时间

似乎它仅适用于以下ICS: https : //stackoverflow.com/a/17675098/9427932

但是您总是可以通过创建自己的类并继承SpeechRecognizer来自定义Google语音,我在Xamarin Android上编写了这些代码,因此它与android非常相似:

public class CustomRecognizer : Java.Lang.Object, IRecognitionListener, TextToSpeech.IOnInitListener
{
private SpeechRecognizer _speech;
private Intent _speechIntent;


public string Words;


public CustomRecognizer(Context _context)
{
    this._context = _context;
    Words = "";
    _speech = SpeechRecognizer.CreateSpeechRecognizer(this._context);
    _speech.SetRecognitionListener(this);
    _speechIntent = new Intent(RecognizerIntent.ActionRecognizeSpeech);
    _speechIntent.PutExtra(RecognizerIntent.ExtraLanguageModel, RecognizerIntent.LanguageModelFreeForm);
    _speechIntent.PutExtra(RecognizerIntent.ActionRecognizeSpeech, RecognizerIntent.ExtraPreferOffline);
    _speechIntent.PutExtra(RecognizerIntent.ExtraSpeechInputCompleteSilenceLengthMillis, 1000); 
    _speechIntent.PutExtra(RecognizerIntent.ExtraSpeechInputPossiblyCompleteSilenceLengthMillis, 1000);
    _speechIntent.PutExtra(RecognizerIntent.ExtraSpeechInputMinimumLengthMillis, 1500);
}

void startover()
{
    _speech.Destroy();
    _speech = SpeechRecognizer.CreateSpeechRecognizer(this._context);
    _speech.SetRecognitionListener(this);
    _speechIntent = new Intent(RecognizerIntent.ActionRecognizeSpeech);
    _speechIntent.PutExtra(RecognizerIntent.ExtraSpeechInputCompleteSilenceLengthMillis, 1000);
    _speechIntent.PutExtra(RecognizerIntent.ExtraSpeechInputPossiblyCompleteSilenceLengthMillis, 1000);
    _speechIntent.PutExtra(RecognizerIntent.ExtraSpeechInputMinimumLengthMillis, 1500);
StartListening();
}
public void StartListening()
{
    _speech.StartListening(_speechIntent);
}

public void StopListening()
{
    _speech.StopListening();
}

public void OnBeginningOfSpeech()
{

}

public void OnBufferReceived(byte[] buffer)
{
}

public void OnEndOfSpeech()
{

}

public void OnError([GeneratedEnum] SpeechRecognizerError error)
{
    Words = error.ToString();
    startover();
}

public void OnEvent(int eventType, Bundle @params)
{
}

public void OnPartialResults(Bundle partialResults)
{
}

public void OnReadyForSpeech(Bundle @params)
{
}

public void OnResults(Bundle results)
{

    var matches = results.GetStringArrayList(SpeechRecognizer.ResultsRecognition);
    if (matches == null)
        Words = "Null";
    else
        if (matches.Count != 0)
        Words = matches[0];
    else
        Words = "";

    //do anything you want for the result
    }
    startover();
}

public void OnRmsChanged(float rmsdB)
{

}

public void OnInit([GeneratedEnum] OperationResult status)
{
    if (status == OperationResult.Error)
        txtspeech.SetLanguage(Java.Util.Locale.Default);
}}

您可以调用startover()在结束后立即开始录制,因此看起来像是“连续语音”(在您的情况下为10秒)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM