Using real numbers in sentences (0.5, 22 point 5, etc)

I have the following Rhasspy-sentence:

\[stelle|mache|schalte] $Device{Device} [$Room{Room}] auf (0..10){Value!float} [prozent|grad]{Unit}

When using the command “stelle die heizung auf 10 grad” via “Recognize” in the Rhasspy-UI or hermes/nlu/query

{
  "input" : "stell die heizung im wohnzimmer auf 10 grad",
  "siteId" : "default",
  "id" : "9e4f5423-e64f-483c-8733-d35e0f1732ec",
  "intentFilter" : null,
  "sessionId" : "9e4f5423-e64f-483c-8733-d35e0f1732ec",
  "wakewordId" : null,
  "lang" : null
}

I get the following:

"slots": {
        "Device": "heizung",
        "Room": "wohnzimmer",
        "Unit": "grad",
        "Value": 10
},

When using “stelle die heizung auf 10.5 grad” (or 10,5) or hermes/nlu/query

{
  "input" : "stell die heizung im wohnzimmer auf 10.5 grad",
  "siteId" : "default",
  "id" : "93906f73-c55f-4c34-a358-1caecc30e5d7",
  "intentFilter" : null,
  "sessionId" : "93906f73-c55f-4c34-a358-1caecc30e5d7",
  "wakewordId" : null,
  "lang" : null
}

the intent isn’t recognized.

Why?

Could be (0…10) only recognizing full numbers, or it could be how you try to input 10.5. Do you try zehn punk fünf" or “zehneinhalb” or “zehn komma fünf”? That could make a difference. I can’t test my system right now, because my mic drivers are busted again so I can only offer suggestions on why it won’t work.

If I write “10 komma fünf” or “zehn komma fünf” the Value is always 5

It seems the number range really does only use full numbers. The code that is used behind the scenes (as noted by the documentation) seems to use 1 as a step size. The documentation says that it can be replaced with a custom program, so you could experiment with the stepsize if that fixes it.

Another way would be to split the numbers in two different slots by the decimal like (0..10){Value_0}(.|komma)(0..100){Value_1}
I did not test if that is the correct syntax for it and I do not know if rhasspy can actually work with a . in a sentence, but it might be worth a try.

The strange thing is, I’m quite sure, I had this working in previous versions of Rhasspy.

Have to bump this problem as I still need to set my heating to 22.5° :wink:

The dot isn’t working. Doesn’t matter in german, because I’m using “komma” in spoken sentences. But the logic and the intent handler would get way more complicated.

Any other idea in the meantime to handle a spoken sentence like “set the heating to 22 point 5 degree”?

Here’s one idea that uses a custom converter named float_spacy.

[SetHeating]
set heating [to] (0..30 [point:. 0..99]){temp!float_spacy}

Notice the substitution with “point” being replaced with a “.”
This produces values for temp like “22 . 5”, which needs to be cleaned up with the converter (stored in converters/float_spacy in your profile, marked as executable):

#!/usr/bin/env python3
import sys
import json

# [22, ".", 5]
args = json.load(sys.stdin)

# 22.5
num = "".join(str(s).strip() for s in args)

print(num)

The “words” captured for temp come into the converter as a JSON array. This little program just smushes them all together and prints the result, which is a valid JSON number.

Thanks @synesthesiam, looks great!

Unfortunately, I always get an empty value back.

So I tried something rudimentary:

#!/usr/bin/env python3
import sys
import json
value = json.load(sys.stdin)
print(value)

And a sentence:

[testconv]
test (1..9){value!float_spacy}

value stays empty using a sentence like “test 1”

    "entities": [
        {
            "end": 4,
            "entity": "value",
            "raw_end": 9,
            "raw_start": 5,
            "raw_value": "eins",
            "start": 5,
            "value": "",
            "value_details": {
                "kind": "Unknown",
                "value": ""
            }
        }
    ],
    "intent": {
        "confidence": 1,
        "name": "testconv"
    },
    "raw_text": "test 1",
    "raw_tokens": [
        "test",
        "1"
    ],
    "recognize_seconds": 0.07136579999996684,
    "slots": {
        "value": ""
    },
    "speech_confidence": 1,
    "text": "test",
    "tokens": [
        "test"
    ],
    "wakeword_id": null
}

Do you have any idea, what’s going on here?

My fault. Wrong line endings. :man_facepalming:

1 Like

Those catch the best of us :slight_smile:

I suspect a misplaced carriage return will be responsible for the end of the universe some day \r

1 Like