在Android的语音识别结果分析命令 [英] Analyzing commands in android speech recognition results

查看:180
本文介绍了在Android的语音识别结果分析命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android的语音识别应用程序,我想比较,我用我自己的字符串得到的结果
这是我的code

i have a speech recognition app in android and i want to compare the results that i get with my own strings this is my code

if (requestCode == REQUEST_CODE && resultCode == RESULT_OK)
        {

            ArrayList<String> matches = data.getStringArrayListExtra(
                    RecognizerIntent.EXTRA_RESULTS);
            for(String resultString: matches)
            {

            if(resultString.equalsIgnoreCase("go"))
                Toast.makeText(getBaseContext(), "go", Toast.LENGTH_SHORT);
            else if(resultString.equalsIgnoreCase("stop"))
                Toast.makeText(getBaseContext(), "stop", Toast.LENGTH_SHORT);
            else if(resultString.equalsIgnoreCase("back"))
                Toast.makeText(getBaseContext(), "back", Toast.LENGTH_SHORT);
            else if(resultString.equalsIgnoreCase("right"))
                Toast.makeText(getBaseContext(), "right", Toast.LENGTH_SHORT);
            else if(resultString.equalsIgnoreCase("left"))
                Toast.makeText(getBaseContext(), "left", Toast.LENGTH_SHORT);
            else
                Toast.makeText(getBaseContext(), "wrong command use go , stop , back , right or left", Toast.LENGTH_SHORT);


            }
        }

我已经使用 matches.contains(走)也尝试过;
甚至似乎没有工作。请大家帮我

i have also tried using matches.contains("go"); even that doesnt seem to work. please help me

推荐答案

结果空格隔开字符串 S,所以你要拆你的 resultString

The results are space separated Strings, so you have to split your resultString

使用一个循环是这样的:

Use a loop like this:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode == VOICE_RECOGNITION_REQUEST_CODE)
    {
        if (resultCode == RESULT_OK)
        {
            List<String> heard = data
                            .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            Set<String> matchThese = new HashSet<String>();
            matchThese.add("tree");
            matchThese.add("car");

            for (String said : heard)
            {
                String[] saidWords = said.split("\\s");
                for (String wordSaid : saidWords)
                {
                    if (matchThese.contains(wordSaid))
                    {
                        tts.speak("You said the correct word",
                            TextToSpeech.QUEUE_FLUSH, null);
                    }
                }
            }
        }
    }
}

更重要的是使用内 GAST 的工具,其中有一些演讲的一个开源项目识别工具。

Better yet use the tools within GAST, an open source project which has some speech recognition tools.

特别是,你至少需要<一个href=\"https://github.com/gast-lib/gast-lib/blob/master/library/src/root/gast/speech/text/match/WordMatcher.java\"相对=nofollow> WordMatcher 和<一个href=\"https://github.com/gast-lib/gast-lib/blob/master/library/src/root/gast/speech/text/WordList.java\"相对=nofollow>单词表

Specifically, you at least need WordMatcher and WordList

这篇关于在Android的语音识别结果分析命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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