-
-
Notifications
You must be signed in to change notification settings - Fork 2
4. How to Use
Seongnoh Sean Yi edited this page Jul 3, 2024
·
5 revisions
You can use MMM-Hotword as a standalone voice commander or for MagicMirror
{
module: "MMM-Hotword",
position: "bottom_left",
config: {
startOnBoot: true,
hotwords: [
{
hotword: 'DoSomething', // I assume you built this custom hotword.
file: 'dosomething.ppn',
continuousRecording: false, // You may not need continuous recording for this kind of short-word command.
onDetect: async ({ helper }) => {
console.log("'Do Something' hotword detected!")
// helper.sendNotification("DO_SOMETHING")
// helper.getModule("MMM-Something").doSomething()
// helper.shellExec("dosomething.sh -option 1")
// ... whaterver
}
},
...This module also be used as a Hotword detector & vocal interface of user-input for other modules, if they could handle it.
{
module: "MMM-Hotword",
position: "bottom_left",
config: {
startOnBoot: false,
// hotwords: [], // If 3rd party model could provide hotword definition, you may not need to define them here by yourself.
},
}/* In MMM-Something module */
this.sendNotification('HOTWORD_ACTIVATE', {
config: {
hotwords: [
{
hotword: 'TURNONTV',
file: 'trunontv.ppn',
onDetect: async () => {
console.log("User said 'TURN ON TV'")
}
}
]
},
callback: (response) => {
if (response.error) console.log(response.error)
}
})And this module could be used as a voice recorder for other modules if they might handle it.
/* MMM-Something */
this.sendNotification('HOTWORD_ACTIVATE', {
asDetected: 'COMPUTER',
config: {
continuousRecording: true,
hotwords: [
{
hotword: 'COMPUTER',
onDetect: async ({ result }) => {
console.log(result?.fileUrl, result?.filePath)
// Do your job with the recorded file here.
},
},
],
},
callback: (response) => {
const filePath = response.result.filePath
const fileUrl = response.result.fileUrl
const hotword = response.result.hotword
// ... Or here.
}
}- By
asDetected, when the module is activated, it starts recording your voice without waiting for hotwordCOMPUTER. It is regarded as already detected. After finishing recording, the recorded wav file will be delivered tocallbackoronDetectcallback functions. You can do your job with the recorded file.