examples/conf/hook.py
def on_music_play_command(event, title=None, artist=None, **context):
    """
    This function will be executed when a SpeechRecognizedEvent with `phrase="play the music"` is triggered.
    `event` contains the event object and `context` any key-value info from the running context.
    Note that in this specific case we can leverage the token-extraction feature of SpeechRecognizedEvent through
    ${} that operates on regex-like principles to extract any text that matches the pattern into context variables.
    """
    results = run('music.mpd.search', filter={
        'artist': artist,
        'title': title,
    })

    if results:
        run('music.mpd.play', results[0]['file'])
    else:
        run('tts.say', "I can't find any music matching your query")

    This function will be executed when a SpeechRecognizedEvent with `phrase="play the music"` is triggered.
    `event` contains the event object and `context` any key-value info from the running context.
    Note that in this specific case we can leverage the token-extraction feature of SpeechRecognizedEvent through
    ${} that operates on regex-like principles to extract any text that matches the pattern into context variables.
    
This function will be executed when a SpeechRecognizedEvent with `phrase="play the music"` is triggered.
`event` contains the event object and `context` any key-value info from the running context.
Note that in this specific case we can leverage the token-extraction feature of SpeechRecognizedEvent through
${} that operates on regex-like principles to extract any text that matches the pattern into context variables.
This function will be executed when a SpeechRecognizedEvent with ` phrase = " play the music " ` is triggered . ` event ` contains the event object and ` context ` any key - value info from the running context . Note that in this specific case we can leverage the token - extraction feature of SpeechRecognizedEvent through $ {} that operates on regex - like principles to extract any text that matches the pattern into context variables .
def on_music_play_command(event, title=None, artist=None, **context):
    results = run('music.mpd.search', filter={
        'artist': artist,
        'title': title,
    })
    if results:
        run('music.mpd.play', results[0]['file'])
    else:
        run('tts.say', "I can't find any music matching your query")
def on_music_play_command ( event , title = None , artist = None , ** context ) : results = run ( 'music.mpd.search' , filter = { 'artist' : artist , 'title' : title , } ) if results : run ( 'music.mpd.play' , results [ 0 ] [ 'file' ] ) else : run ( 'tts.say' , "I can't find any music matching your query" )
This function will be executed when a SpeechRecognizedEvent with `phrase="play the music"` is triggered.
This function will be executed when a SpeechRecognizedEvent with ` phrase = " play the music " ` is triggered .
"""
    This function will be executed when a SpeechRecognizedEvent with `phrase="play the music"` is triggered.
    `event` contains the event object and `context` any key-value info from the running context.
    Note that in this specific case we can leverage the token-extraction feature of SpeechRecognizedEvent through
    ${} that operates on regex-like principles to extract any text that matches the pattern into context variables.
    """
event
title
artist