Hey @Baltibu, @carteblanche I’ll help all I can.
So to make sure I got rid of any problems, I started with a clean MagicMirror install
Then I install Alexyak’s voicecontrol module
to get my USB microphone working, I need to overwrite the ~/.asoundrc file with these contents;
#asym fun start here. we define one pcm device called "pluged"
pcm.pluged {
type plug
#this is your output device
slave.pcm "hw:0,1"
}
#one called "dsnooped" for capturing
pcm.dsnooped {
ipc_key 1027
type dsnoop
#this is your input device
slave.pcm "hw:1,0"
}
#and this is the real magic
pcm.asymed {
type asym
playback.pcm "pluged"
capture.pcm "dsnooped"
}
#a quick plug plugin for above device to do the converting magic
pcm.pasymed {
type plug
slave.pcm "asymed"
}
#a ctl device to keep xmms happy
ctl.pasymed {
type hw
card 0
}
#for aoss:
pcm.dsp0 {
type plug
slave.pcm "asymed"
}
ctl.mixer0 {
type hw
card 0
}
pcm.!default {
type plug
slave.pcm “asymed”
}
Then I start the Audio Preferences control panel in the Raspain GUI and select controls (tick PCM) for the sound card and select controls (tick microphone) for the USB microphone.
I then created a PMDL keyword test file on the snowboy website and downloaded it.
The PMDL I created I called smartmirror.pmdl - it recognised the phrase ‘smart mirror’
Put this file in the ~/MagicMirror directory.
Now it’s time to test!
Add the following to your /config/config.js:
{
module: 'voicecontrol',
position: 'bottom_left',
config: {
models: [
{
keyword: "show alert", // keyword
description: "Say 'Show Alert' to show an alert",
file: "smartmirror.pmdl", // trained model file name
message: "SHOW_ALERT" // notification message that's broadcast in the MagicM
},
]
}
},
start your magic mirror in dev mode:
npm start dev
wait for everything to start (you may get some ALSA stuff in the terminal window but that isn’t necessarily a problem). Ensure the dev window is in Console mode, so you can see any console messages as Magic Mirror runs. Once everything has started okay, try saying ‘smart mirror’ (or whatever your keyword is) If it’s all working, you should see two things happening:
- An empty, white alert box should pop up and then disappear on the Magic Mirror
- In the Dev console, you should see the alert notification being broadcast to all the modules.
If you get both of these happening, you’re 90% of the way there :)
If you only see the broadcast in the Dev console but not the alert, there’s a problem with the config.js or the alert.js
If you don’t see the broadcast, you need to double-check everything, or the microphone isn’t working… You’ll need to solve this first.
What we’ve just done, is made use of the MagicMirror notification broadcast and one of the default modules ‘Alert’
The next step is to create a load of PMDL files for all of the words you want the mirror to respond to. Copy all the downloaded PMDLs into the MagicMirror root folder.
You can now add to that section of the config.js for each PMDL file. The only thing to change is the file: entry (to be the PMDL file, and the description: entry (this will just add to what voicecontrol displays on the MagicMirror screen and will help in remembering what keywords you’ve got active).
So… You should now have a bunch of trigger words that you can test. Each one will send a notification (which you will see in the dev console) and will briefly trigger the alert popup at the top of the magic mirror screen.
All you need to do now, is change the SEND_ALERT that is broadcast, to something more useful.
I wanted to hide and show modules so I ended up with something like this in my config.js:
{
module: 'voicecontrol',
position: 'bottom_left',
config: {
models: [
{
keyword: "Hide Calendar", // keyword
description: "Hide Calendar",
file: "hidecalendar.pmdl", // trained model file name
message: "HIDE_CALENDAR" // notification message that's broadcast in the MagicM
},
{
keyword: "Show Calendar", // keyword
description: "Show Calendar",
file: "showcalendar.pmdl", // trained model file name
message: "SHOW_CALENDAR" // notification message that's broadcast in the MagicM
},
]
}
},
Now, when I say “Show Calendar”, a SHOW_CALENDAR notification will be broadcast to all the modules and when I say “Hide Calendar”, a HIDE_CALENDAR notification will be broadcast to all the modules.
None of the modules are going to understand what SHOW_CALENDAR and HIDE_CALENDAR mean, so we need to tell in this case, the calendar module, what to do.
Make a backup copy of the /modules/default/calendar/calendar.js and then edit it so that it can act on NotificationReceived events.
This is the bit that tripped me up initially. Modules will have a SocketNotificationReceived - this is where they interact with their node-helper.js file. It looks similar to what we’re after but not quite! There probably isn’t a plain ‘NotificationReceived’ section, so we’ll add one - we can always delete the .js and restore our backup if things go horribly wrong.
I went ahead and added this to my calendar.js
// voice control notification handling
NotificationReceived: function (notification, payload) {
if (notification === "HIDE_CALENDAR") {
this.hide();
} else if (notification === "SHOW_CALENDAR") {
this.show();
}
},
(I added this just after the SocketNotificationReceived section)
Start your magic mirror in dev mode again and this time you should see a SHOW_CALENDAR or HIDE_CALENDAR notification broadcast when you say the appropriate keyword. If the NotificationReceived code is working, you will also see the Calendar appear or disappear!
If you’ve made it this far, congratulations. You’re home and dry. You can now extend it by adding the same code, with different notifications in the other modules you want to control. I added a ‘HIDE_ALL’ and ‘SHOW_ALL’ to all of my modules so that I can switch them all on or off , as well as independantly.
Give it a go and see how you get on. In each case, just take little steps and back any files up before you change them and you should be fine. I know next to nothing and I’ve managed, so it’s definitely doable…and you’ll have a big grin when it works.
If you have any more trouble just give a shout and I’ll help all I can.