Skip to content

3. Control

Seongnoh Sean Yi edited this page Jul 3, 2024 · 1 revision

Control by Notification (For expert)

Incoming Notification

HOTWORD_ACTIVATE

  • payload: {...configs, callback})

3rd party module can activate the detector with a notification HOTWORD_ACTIVATE.

When the MMM-Hotword2 is already activating (listening to the user's voice) at that moment, this notification would be ignored. (callback will be called with error)

/* MMM-SomeModule */
this.sendNotification('HOTWORD_ACTIVATE', {
  config: {
    hotwords: [
      {
        hotword: 'DO_SOMETHING',
        onDetect: () => { ... }
      },
      {
        hotword: 'DO_OTHERTHING',
        onDetect: () => { ... }
      }
    ],
    restart: false,
    sensitivity: 0.6, // You can redefine any configs for this activation.
  },
  callback: ({ error, result, payload }) => {
    // This callback is only once executed when any hotword is detected at first.
    // Generally, this callback could be used to check whether the module works at first time.
    if (error) ...
  },
  /* asDetected: 'COMPUTER' */ 
})

This notification can carry some data objects as parameters of payload during this active session. It would be used for a dedicated hotword detector for the specific 3rd party module. When the payload is omitted, the default configuration of MMM-Hotword2 will be applied.

config

3rd party module can reconfigure the behaviour of MMM-Hotword2 with this payload.

callback

The result of activation (error or detection) will execute this callback function.

asDetected

When this parameter is set as one of hotwords, the voice of the user would be recorded directly without hotword detection. It is used when you need only the voice recording. (When the recording ends, onDetect of that hotword and callback will be executed.)

HOTWORD_DEACTIVATE

  • payload: null

3rd party module can deactivate the detector with this notification. Usually, this will be used to release a mic.

/* MMM-SomeModule */
this.sendNotification('HOTWORD_DEACTIVATE')

Outgoing Notificaiton

HOTWORD_READY

  • payload: null

3rd party module can know that MMM-Hotword2 is ready to work.

HOTWORD_DEACTIVATED

  • payload: null

3rd party module can know that MMM-Hotword2 is now deactivated. (the mic is released.)

Usually, your device may have only one mic. So you should carefully manage the mic occupation.