3

サンプル アプリケーション (手順):

  1. EditText コントロールのない Android アプリケーション。
  2. アプリケーションには、テキスト ビューを含むアクティビティがあります。
  3. アクティビティの onCreate() メソッドで、アプリケーションの起動時に仮想キーボード (SoftKeyBoard) を持ち込みます。
  4. 仮想キーボードのマイク (音声入力) ボタンを押します。
  5. 「お元気ですか」と話す。

音声入力の結果: Android アプリケーションは、 「お元気ですか」「お元気ですか 」 「お元気ですか」
のように、上記の音声を 3 回繰り返して受け取ります。


これは正しくありません。ご覧のとおり、 「How」「are」という言葉が 3 回目の反復で繰り返されます。

期待される結果:アプリケーションは、 「How」 「are」 「you」
のような 3 回の反復で話し言葉を受け取る必要があります。


サンプル アプリケーション コードは次のとおりです。

public class TestSpeechToText extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_url);
    /* Default display keyboard */
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_test_url, menu);
    return true;
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    return true;
}

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    return true;
}

@Override
public boolean onKeyMultiple(int keyCode, int count, KeyEvent event) {
    String text = event.getCharacters();
    Log.d("Testing", "Text is " + event.toString());
    return true;
}

}

この場合、オーバーライドされたメソッド onKeyMultiple() が 3 回呼び出され、テキストは「How」、「are」、「How are you」です。

注:
1. EditText コントロールはありません
2. xml レイアウトにはテキスト ビューのみが含まれます

誰もこの問題を認識していますか? はいの場合、どのように解決できますか?

4

2 に答える 2

0

EditText がない場合は、SoftKeyboard 経由ではなく、自分で Intent 呼び出しを行います。次に、認識されたすべての単語を含む配列を取得します。純粋でシンプル。

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);
}

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK)
    {
        // Populate the wordsList with the String values the recognition engine thought it heard
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        // Manipulate your data or do whatever you like with the result
    }
}
于 2012-10-29T09:13:36.040 に答える