我正在尝试开发一个使用TTS
引擎和语音识别的酷应用程序。到目前为止它还可以,但我想要更多。我想创建一个服务(我认为服务是正确的方式),总是“倾听”,当有人说"ok google"
或其他东西时,语音识别就像Google现在一样开始。例如,如果您说"ok google"
谷歌现在开始。我不知道从哪里开始所以我在这里直接询问是否有可能。我试着查看这个帖子[这里](Listening for keywords at all times, like "Ok google" on 4.4),最后的答案谈到了服务,正如我想的那样。有人可以帮我解决我的代码吗?
例如,这是通过点击按钮开始语音识别的代码:
/**
* Instruct the app to listen for user speech input
*/
private void listenToSpeech() {
//start the speech recognition intent passing required data
Intent listenIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
//indicate package
listenIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
//message to display while listening
listenIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say a word!");
//set speech model
listenIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
//specify number of results to retrieve
listenIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 10);
//start listening
startActivityForResult(listenIntent, VR_REQUEST);
}
您是否认为仅使用语音启动listenIntent
并且无需按任何按钮?这就是我的意思。
答案 0 :(得分:1)
(2002年1月6日更新:在上一个答案中添加了一些内容)
此应用使用热词检测作为" Google Now"。
并且Android没有提供这样的API来执行此类操作。
Saiy应用程序现在是repository here的开源。从我在代码中看到的很少,它似乎已经使用CMU Pocketshinx实现了功能。
不要忘记发表你的发现。
注意 - 它非常耗费CPU和电池消耗,可以在后台随时收听。
答案 1 :(得分:0)
它不是java,但你见过Jasper吗?看起来很有希望:http://jasperproject.github.io
答案 2 :(得分:0)
使用Jform,而不是android,并且您创建了一个按钮,您可以调用button.doClick()。所以我使用的是Timer,Timer.scheduleAtFixedRate(new task(),int delay,int iterval);这样它就可以独立完成并重复。所以我试图得到的是,我确定在android中使用do.action / button / key,等等,你可以使用计时器独立激活它。看到它似乎是一个空虚,试试
listenToSpeech();
关于计时器;
Timer listenTimer = new Timer(); //listenTimer.schedualAtFixedRate(new listeningTask(),0,1);//place this where your program starts as this starts the timer class listeningTask extends TimerTask{ if(condition){ listenToSpeech(); } }
对于使用平板电脑的格式或缩进感到抱歉。