android语音识别与SpeechRecognizer

时间:2013-10-05 15:00:16

标签: android android-intent speech-recognition

我正在处理语音功能,之前我使用语音识别功能,系统识别语音时会弹出Google对话框。

随后,由于我不想要对话框,我已经按照了答案 How can I use speech recognition without the annoying dialog in android phones

实施SpeechRecognizer,以便在按下发言按钮时不会弹出标准的谷歌对话框。

代码:

public void onClick(View v) 
{
    if (v.getId() == R.id.button_record) 
    {
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);        
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test");
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "zh_HK");
        intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,1); 
        sr.startListening(intent);
        Log.i("111111","11111111");
    }

class listener implements RecognitionListener

    public void onResults(Bundle results)                   
    {
         String str = new String();
         Log.d(TAG, "onResults " + results);
         ArrayList<String> data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
         string_after_speech = data.get(0).toString();
         TextView1.setText(""+string_after_speech);    

问题:

  1. 我希望语音识别(带有Google对话框弹出窗口的那个)和SpeechRecognizer生成的结果应该相同吗?然而,运行几次,似乎语音识别与对话框的质量高于SpeechRecognizer ...

  2. 如何将结果限制为SOLELY zh_HK(广东话或繁体中文)?我试着用广东话说一下,但结果是中文的一半,英文的一半...如果我说英语,它会直接输出英文。以这种方式设置的intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "zh_HK"不正确吗?

  3. 谢谢!

0 个答案:

没有答案