Snips ASR and NLU component#8156
Conversation
|
Hi @michaelfester, It seems you haven't yet signed a CLA. Please do so here. Once you do that we will be able to review and accept this pull request. Thanks! |
There was a problem hiding this comment.
multiple statements on one line (colon)
There was a problem hiding this comment.
multiple statements on one line (colon)
There was a problem hiding this comment.
multiple statements on one line (colon)
There was a problem hiding this comment.
multiple statements on one line (colon)
There was a problem hiding this comment.
multiple statements on one line (colon)
There was a problem hiding this comment.
multiple statements on one line (colon)
There was a problem hiding this comment.
line too long (110 > 79 characters)
There was a problem hiding this comment.
local variable 'a' is assigned to but never used
There was a problem hiding this comment.
continuation line under-indented for visual indent
|
Very cool! Looking forward to Snips support. This will also require a test to be written. Could be something like this (untested): import asyncio
from homeassistant.bootstrap import async_setup_component
from tests.common import async_fire_mqtt_message, mock_service
EXAMPLE_MSG = """
{
// snips message from hermes/nlu/intentParsed for intent Lights
}
"""
@asyncio.coroutine
def test_snips_call_action(hass, mqtt_mock):
"""Test calling action via Snips."""
calls = mock_service(hass, 'test', 'service')
result = yield from async_setup_component(hass, 'snips', {
'snips': {
'intents': {
'Lights': {
'action': {
'service': 'test.service'
}
}
}
}
})
assert result
async_fire_mqtt_message(hass, 'hermes/nlu/intentParsed',
EXAMPLE_MSG)
yield from hass.async_block_till_done()
assert len(calls) == 1 |
balloob
left a comment
There was a problem hiding this comment.
Off to a good start, will need some more work. There is also a bunch of lint issues that need to be addressed https://travis-ci.org/home-assistant/home-assistant/jobs/245793758#L282
There was a problem hiding this comment.
Since message_received only cares about messages from hermes/nlu/intentParsed, better to just listen to that topic instead and not allow it to be configured?
There was a problem hiding this comment.
This can raise a TypeError if invalid JSON.
There was a problem hiding this comment.
It's probably the easiest to write a voluptuous schema to validate the schema that Snips is sending. That way you can get rid of all other checks if some piece of data is available.
There was a problem hiding this comment.
Catch KeyError. Bare exceptions are not allowed.
There was a problem hiding this comment.
This is not possible. Python will raise if a key does not exists. Unless the JSON value of slots can be set to null ? Again, probably easier to write a voluptuous schema to validate this info.
There was a problem hiding this comment.
Errrrrr, what is happening here? 🤔
There was a problem hiding this comment.
indentation contains mixed spaces and tabs
|
Hello. |
|
Hi @bastshoes! Currently this is not possible but we are fixing this :) |
c3bc81c to
4241d4e
Compare
|
Component never worked because the name extraction code was wrong. It referenced Another issue was that Converted it to async because there was no reason to use threads. I've added some schema validation to validate incoming data instead of having to check each value individually. Now all tests should pass and this is good to go. |
4241d4e to
858c354
Compare
858c354 to
ffab784
Compare
|
Cherry-picked for 0.48. |
* Snips ASR and NLU component * Fix warning * Fix warnings * Fix lint issues * Add tests * Fix tabs * Fix newline * Fix quotes * Fix docstrings * Update tests * Remove logs * Fix lint warning * Update API * Fix Snips
|
Excellent stuff. Thanks @balloob! |
|
Are you certain about the I had to build a MQTT bridge that adapts the output from Snips: var mqtt = require('mqtt');
var snipsClient = mqtt.connect('mqtt://localhost:9898');
var hassClient = mqtt.connect('mqtt://192.168.1.247:1884');
snipsClient.on('connect', function() {
console.log('Connected to Snips broker');
});
hassClient.on('connect', function() {
console.log('Connected to HASS broker');
});
snipsClient.on('message', function(topic, message) {
console.log(' < '+topic);
message = message.toString();
if(message) {
message = JSON.parse(message);
//console.log(message);
if(message.hasOwnProperty('intent')) {
message.intent.intent_name = message.intent.intentName;
}
if(message.hasOwnProperty('slots')) {
for(var i=0;i<message.slots.length;i++) {
message.slots[i].slot_name = message.slots[i].slotName;
}
}
if(message.hasOwnProperty('input')) {
message.text = message.input;
}
//console.log(message);
hassClient.publish(topic, JSON.stringify(message));
}
else {
hassClient.publish(topic, message);
}
});
snipsClient.subscribe('#'); |
|
@Mika56 that's weird. I see I do admit that I didn't test it with an actual Snips instance. @michaelfester can you chime in what the right variable names are ?
|
|
Yes, change of API. Update throughout :) |
* Snips ASR and NLU component * Fix warning * Fix warnings * Fix lint issues * Add tests * Fix tabs * Fix newline * Fix quotes * Fix docstrings * Update tests * Remove logs * Fix lint warning * Update API * Fix Snips
Description:
Snips on-device ASR and NLU custom component.
For installation and setup of the Snips SDK, check out the Snips Installation Guide.
The Snips SDK must be installed and running locally, and Home Assistant should use the Snips SDK as an MQTT broker for simplicity. For instance, if the Snips platform is running locally on port 9898, the following should be added to
configuration.yaml:Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#2892
Example entry for
configuration.yaml:Just like Alexa and API.ai, Snips transforms voice and text into intents. Intents are created via the Snips Console, and can then be handled in Home Assistant by adding the intents, and accompanying actions, to the
snipsentry inconfiguration.yaml: