Android上的语音输入一个字比较 [英] Comparing speech input on Android with a word

查看:146
本文介绍了Android上的语音输入一个字比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了这个检查,如果有什么人说含有RECHERCHE,但它合乎理显示敬酒:

I made this to check if what people say contain "recherche" but it doest display the toast :

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但它不举杯任何

so it changes the textview but it doesn't toast anything

推荐答案

在此部分:

spec.toLowerCase().contains("Recherche")

您转换的规范小写,但 RECHERCHE 开始是研究这是一个大写!用这个来代替:

you convert spec to lower case but Recherche start with R that is an upper case! use this instead :

spec.toLowerCase().contains("recherche")  

这篇关于Android上的语音输入一个字比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆