MMM-Spotify



  • @Sean yes, the other commands work. I can skip the song, increase/decrease the volume and etc. Also Raspotify is running, because I can start the playback on the mirror from my Desktop/Smartphone app.0_1563467613897_Untitled20190718193321.png



  • @Sean, I did some more testing and I can confirm that this is the only command that doesn’t work. Maybe I am not understanding it correctly.

    My expected results would be:

    1. Raspotify is running in the background (but no music is playing)
    2. When I say “music please” spotify will start a random song and play it on the MagicMirror

    The result however is:

    1. Raspotify is running in the background and no music is playing
    2. When I say “music please” I see no errors in the logs, however, no music is starting as well
    3. To workaround this I start the music from my smartphone or desktop app and switch the player to MagicMirror, after that I can control the player via AssistankMK2

  • Module Developer

    @Ivanov_d
    There could be 2(or 3)kinds of possibility about your issue;

    1. AssistantMk2 cannot catch your word “music please”
    2. AssistantMk2 could catch “music please” but cannot emit “SPOTIFY_PLAY” notification
    3. Spotify cannot receive (or understand) SPOTIFY_PLAY notification. (hmmm… I can’t agree about this)

    Well, I’ll test from last third issue. Wait for a while.


  • Module Developer

    @Ivanov_d
    I just tested 3rd case, and there is no problem to work. I think your music please phrase is not hooked, because music is reserved word for default Music feature of Assistant itself(for Youtube Music or Spotify on Google Home itself, but not yet supported by SDK for devices - only allowed for Google Home or some genuine devices). Some keywords or phrases are reserved for Google itself. Unless you override the keywords by Custom Action for Assistant (And even though, cannot guarantee it will work), your music keyword couldn’t work.
    Can you try other phrase? like “stay tune.” or any phrase you like.



  • @Sean I will try that and report back. Thanks for the suggestion.



  • Hi Guys need some help with this module - newbie 😏
    I have the following loaded succesfully:
    AssistantMk2
    Hotword
    Raspotify
    Change device name in Raspotify :to Mirror
    Created a spotify.json - recipe(code from here) in recipes file this is it:
    Added the recipe to the Mk2.js
    recipes:[“hide_and_show_all_modules.js”, “reboot.js”, “screen_onoff.js”, “shutdown.js”, “spotify.js”],
    Dont know what i missed - any assistance please …

    var recipe = {
    transcriptionHook: {
              STOP_PLAY: {
                pattern: "stop the video", // this is for youtube but it is preferable to have youtubeAutoplay: false, when running spotify so you don't get interaction with youtube player. 
                command: "STOP_VID"
              },
             // STOP_PLAY2: {
             //   pattern: "arrête la musique",
             //   command: "STOP_VID"
             // },
    
    	 SPOTIFY_PREVIOUS: {
            pattern: "previous song",
            command: "SPOTIFY_PREVIOUS"
            },
            SPOTIFY_PAUSE: {
            pattern : "stop the musique",
            command: "SPOTIFY_PAUSE"
            },
            SPOTIFY_PLAY: {
            pattern : "music please",
            command: "SPOTIFY_PLAY"
            },
            SPOTIFY_NEXT: {
            pattern: "next song",
            command: "SPOTIFY_NEXT"
            },
            SPOTIFY_VOLUME: {
            pattern: "set music volume to ([0-9]{1,2}[0]?|100)",
            command: "SPOTIFY_VOLUME"
            },
            SPOTIFY_SEARCH: {
            pattern: "play (.*) on Spotify",
            command: "SPOTIFY_SEARCH"
            },
    	SPOTIFY_SEARCH_PLAYLIST: {
            pattern: "playlist (.*) on Spotify",
            command: "SPOTIFY_SEARCH_PLAYLIST"
            },
    	SPOTIFY_MA_PLAYLIST: {
    	pattern: "(.*) my playlist",   // (.*)  is an action  eg: play my playlist / run my playlist etc... 
    	command: "SPOTIFY_MA_PLAYLIST"
    	},
    	SPOTIFY_TRANSFER: {
    	pattern: "play the music on (.*)", // (.*)  is the name of your device
    	command: "SPOTIFY_TRANSFER"
    	},
              VOLUME_UP: {
                pattern: "volume up",
                command: "CMD_VOLUME_UP"
              },
              VOLUME_DOWN: {
                pattern: "volume down",
                command: "CMD_VOLUME_DOWN"
              },
              SET_VOLUME: {
                pattern: "set master volume to ([0-9]{1,2}[0]?|100)",
                command: "CMD_VOLUME_SET"
              }
    
            },
            command: {
    
              STOP_VID: {
                moduleExec: {
                  module: ["MMM-AssistantMk2"],
                  exec: (module, params, key) => {
                    module.assistant.subdom.youtube.innerHTML = ""; 
                    module.assistant.subdom.youtube.style.display = "none";
                    module.youtubePlaying = false;
                  }
                }
              },
    	   SPOTIFY_TRANSFER: {
    	    notificationExec: {
                  notification: "SPOTIFY_TRANSFER",
    	         payload: (params) => {
                     console.log("SPOTIFY_TRANSFER @",params)
                    return params[1];
                            }
        
    	}
              },
               SPOTIFY_PAUSE: {
                notificationExec: {
                  notification: "SPOTIFY_PAUSE"
                }
              },
    
            SPOTIFY_PLAY: {
                notificationExec: {
                    notification: "SPOTIFY_PLAY"
                    }
            },
    	
    	SPOTIFY_MA_PLAYLIST: {
    	    notificationExec:  {
    		notification: "SPOTIFY_PLAY",
    		payload: (params) => {
    		console.log("SPOTIFY_MA_PLAYLIST")
    		return {
    			context_uri:"spotify:playlist:0bdByehKVfdsfdsfdsOhF5t",   // Uri of a personnal playlist or album
    				}
    			},
    		notification: "SPOTIFY_SHUFFLE",  // added this to toogle shuffle
    		notification: "SPOTIFY_NEXT" // added this to not always have the same song starting first 
    		}
    	},		
            
    	SPOTIFY_NEXT: {
             notificationExec: {
                notification: "SPOTIFY_NEXT"
                    }
            },
    
            SPOTIFY_PREVIOUS: {
             notificationExec: {
                notification: "SPOTIFY_PREVIOUS"
                    }
            },
            SPOTIFY_VOLUME: {
             notificationExec: {
               notification: "SPOTIFY_VOLUME",
               payload: (params) => {
                     console.log("SPOTIFY_VOLUME @",params)
                    return params[1];
                            }
                    }
            },
    	SPOTIFY_SEARCH: {
             notificationExec: {
               notification: "SPOTIFY_SEARCH",
    
            payload: (params) => {
                    console.log("SPOTIFY_SEARCH @",params)
                    return {
                            type: "artist,track,album,playlist",
                            query: params[1],
                            random:false,
                            }
                         }
                    }
            },
    	 SPOTIFY_SEARCH_PLAYLIST: {
             notificationExec: {
               notification: "SPOTIFY_SEARCH",
    
            payload: (params) => {
                    console.log("SPOTIFY_SEARCH_PLAYLIST @",params)
                    return {
                            type: "playlist",
                            query: params[1],
                            random:true,
                            }
                         }
                    }
            },
    
    
              CMD_VOLUME_UP: {
                notificationExec: {
                  notification: "VOLUME_UP"
                }
              },
              CMD_VOLUME_DOWN: {
                notificationExec: {
                  notification: "VOLUME_DOWN"
                }
              },
              CMD_VOLUME_SET: {
                notificationExec: {
                  notification: "VOLUME_SET",
                  payload: (params, key) => {
                    console.log("@", params);
                    return params[1];
                  }
                }
              }
            },
    
    
    
    exports.recipe = recipe // Don't remove this line.
    
    

    This is the error

    AMK2] Recipe is loaded: shutdown.js
    Whoops! There was an uncaught exception...
    /home/pi/MagicMirror/modules/MMM-AssistantMk2/recipes/spotify.js:183
    exports.recipe = recipe // Don't remove this line.
           ^
    
    SyntaxError: Unexpected token .
        at new Script (vm.js:74:7)
        at createScript (vm.js:246:10)
        at Object.runInThisContext (vm.js:298:10)
        at Module._compile (internal/modules/cjs/loader.js:678:28)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:722:10)
        at Module.load (internal/modules/cjs/loader.js:620:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:559:12)
        at Function.Module._load (internal/modules/cjs/loader.js:551:3)
        at Module.require (internal/modules/cjs/loader.js:658:17)
        at require (internal/modules/cjs/helpers.js:20:18)
    MagicMirror will not quit, but it might be a good idea to check why this happened.

  • Module Developer

    @Faiek
    you might have missed closing brace somewhere. check to count opening and closung pairs.



  • @Sean Thanks for the response - i m lost - no programming knowledge whats so ever
    trail and error got me thus far- and everything’s working great except spotify, still learning.
    Can’t i get a completed (recipe.json) with any other require details, for voice activation on this module that could assist me, once i have one, ill probably be able to see my error.
    Stomped for days now … online json checkers… really need to learn the basics …Thanks


  • Module Developer

    @Faiek
    Just add } over exports....

    }
    
    exports.recipe = recipe // Don't remove this line.
    


  • @Sean Thanks A Million - - working 😀