如何与 Porcupine 一起使用语音识别

时间:2021-05-05 20:10:45

标签: android-studio kotlin speech-recognition voice-recognition hotword

任何人都可以帮助我了解如何使用语音识别在豪猪醒来后立即收听。我们需要弄清楚如何阻止豪猪经理听麦克风,直到完成语音识别。

try {
        Log.i("YOU SAID IT!", "yesss");
        porcupineManager = new PorcupineManager.Builder()
                .setKeyword(Porcupine.BuiltInKeyword.JARVIS)
                .setSensitivity(0.7f).build(
                        getApplicationContext(),
                        (keywordIndex) -> {
                            
                            // This is where I need to somehow stop so that I can trigger speech recognition to listen

                            numUtterances++;

                            PendingIntent contentIntent = PendingIntent.getActivity(
                                    this,
                                    0,
                                    new Intent(this, MainActivity.class),
                                    0);

                            final String contentText = numUtterances == 1 ? " time!" : " times!";
                            Notification n = new NotificationCompat.Builder(this, CHANNEL_ID)
                                    .setContentTitle("Wake word")
                                    .setContentText("Detected " + numUtterances + contentText)
                                    .setSmallIcon(R.drawable.ic_launcher_background)
                                    .setContentIntent(contentIntent)
                                    .build();

                            NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                            assert notificationManager != null;
                            notificationManager.notify(1234, n);
                        });
        porcupineManager.start();
    } catch (PorcupineException e) {
        Log.e("PORCUPINE", e.toString());
    }

0 个答案:

没有答案