6

是否可以在您自己的应用程序中使用“google now”这个很酷的语音激活功能?

所以我想要的是用户不必通过按下按钮或某事来触发激活。像那样。

我宁愿通过关键字激活自动语音识别。例如:当“google now”打开时,您只需说:“google”。在该命令之后,系统正在侦听实际输入。

这可以通过使用android API吗?或者是否有任何提供这种行为的开源库?

我知道这可以通过“开放式耳朵”实现,但不幸的是,开放式耳朵不适用于 android。

4

3 回答 3

1

您必须将语音识别作为服务而不是作为活动来运行。

查看此 git 以获取有关如何执行此操作的示例代码: https ://github.com/gast-lib/gast-lib ‎</p>

于 2013-09-06T20:06:06.447 回答
1

我建议使用 CMU Sphinx,或者在每个“onResults”和“onError”函数调用上重新启动识别器。

于 2014-11-27T17:33:23.000 回答
0

使用CMUSphinx库,它将在离线模式下工作,不需要按钮来触发它,你可以命名它,通过使用名称你可以触发识别模块在下面的链接中你可以找到完整的源代码

1)它会在离线模式下工作 2)你可以命名它 3)当你叫他的名字时它会开始监听

    private static final String KEYPHRASE = "ok computer";
    private static final int PERMISSIONS_REQUEST_RECORD_AUDIO = 1;
    private SpeechRecognizer recognizer;
      public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    captions = new HashMap<String, Integer>();
    captions.put(KWS_SEARCH, R.string.kws_caption);
    captions.put(MENU_SEARCH, R.string.menu_caption);
    setContentView(R.layout.activity_maini);
    }
     private void runRecognizerSetup() {
    // Recognizer initialization is a time-consuming and it involves IO,
    // so we execute it in async task
    new AsyncTask<Void, Void, Exception>() {
        @Override
        protected Exception doInBackground(Void... params) {
            try {
                Assets assets = new Assets(MainActivity.this);
                File assetDir = assets.syncAssets();
                setupRecognizer(assetDir);
            } catch (IOException e) {
                return e;
            }
            return null;
        }
        @Override
        protected void onPostExecute(Exception result) {
            if (result != null) {
                ((TextView) findViewById(R.id.caption_text))
                        .setText("Failed to init recognizer " + result);
            } else {
                switchSearch(KWS_SEARCH);
            }
        }
    }.execute();
}

@Override
public void onRequestPermissionsResult(int requestCode,
                                       String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);

    if (requestCode == PERMISSIONS_REQUEST_RECORD_AUDIO) {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            runRecognizerSetup();
        } else {
            finish();
        }
    }
}
     public void onResult(Hypothesis hypothesis) {
    ((TextView) findViewById(R.id.result_text)).setText("");
    if (hypothesis != null) {
        String text = hypothesis.getHypstr();
        makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
    }}
于 2017-10-13T03:54:10.170 回答