我这是为了检查人们说的是否包含“recherche”,但它没有显示吐司:
public void bn6(View view ){
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech to text");
startActivityForResult(intent, 1);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1 && resultCode == RESULT_OK) {
ArrayList<String> matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
TextView speechText = (TextView)findViewById(R.id.speechText);
speechText.setText(matches.get(0).toString());
String spec = speechText.getText().toString();
if (spec.toLowerCase().contains("Recherche")) {
Toast.makeText(getApplicationContext(), "bravo", Toast.LENGTH_LONG).show();
}
}
super.onActivityResult(requestCode, resultCode, data);
}
因此它会更改textview,但它不会覆盖任何内容
答案 0 :(得分:0)
。spec.toLowerCase()包含(&#34; RECHERCHE&#34)
如果您比较较低的&#39; r&#39;您的文字将始终为false。到资本&#39; R&#39;
使用&#34; recherche&#34;小写
答案 1 :(得分:0)
在这部分:
spec.toLowerCase().contains("Recherche")
您将规范转换为小写,但 Recherche 以 R 开头,这是一个大写!请改用:
spec.toLowerCase().contains("recherche")