1

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

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());
    }
4

0 回答 0