Enhance DSL rules for say and interpret (#206)
* Enhance DSL rules for say and interpret Submitted for publication by Laurent Garnier <lg.hc@free.fr> (github:lolodomo) Submitted at https://github.com/openhab/openhab-docs/pull/149 Closes #149 Signed-off-by: Thomas Dietrich <Thomas.Dietrich@tu-ilmenau.de> * Update multimedia.md Signed-off-by: Thomas Dietrich <thomas.dietrich@tu-ilmenau.de> (github: ThomDietrich)pull/215/head
parent
17007395b8
commit
4e6a5439c6
|
@ -11,7 +11,7 @@ title: Multimedia
|
|||
|
||||
openHAB is able to play sound either from the file system (files need to be put in the folder `conf/sounds`), from urls (e.g. Internet radio streams) or generated by text-to-speech engines (which are available as optional [Voice add-ons]({{base}}/addons/voice.html)).
|
||||
|
||||
There are different options for output devices (so called audio sinks):
|
||||
There are different options for output devices (so called audio sinks):
|
||||
|
||||
The distribution comes with these options built-in:
|
||||
|
||||
|
@ -23,7 +23,7 @@ Additionally, certain bindings register their supported devices as audio sinks,
|
|||
|
||||
To check, which audio sinks are available, you can use the console:
|
||||
|
||||
```
|
||||
```text
|
||||
openhab> smarthome:audio sinks
|
||||
enhancedjavasound
|
||||
javasound
|
||||
|
@ -32,20 +32,18 @@ webaudio
|
|||
|
||||
You can define the default audio sink either by textual configuration in `conf/services/runtime.cfg` or in the Paper UI in `Configuration->System->Audio`.
|
||||
|
||||
In order to play a sound, you can use
|
||||
In order to play a sound, you can use the following command on the console:
|
||||
|
||||
```
|
||||
```text
|
||||
openhab> smarthome:audio play doorbell.mp3
|
||||
```
|
||||
|
||||
on the console or
|
||||
Alternatively the [`playSound()` function](https://www.eclipse.org/smarthome/documentation/javadoc/org/eclipse/smarthome/model/script/actions/Audio.html#playSound-java.lang.String-) can be used in DSL rules:
|
||||
|
||||
```
|
||||
```java
|
||||
playSound("doorbell.mp3")
|
||||
```
|
||||
|
||||
within DSL rules.
|
||||
|
||||
## Voice
|
||||
|
||||
### Text-to-Speech
|
||||
|
@ -53,7 +51,7 @@ within DSL rules.
|
|||
In order to use text-to-speech, you need to install at least one [TTS service]({{base}}/addons/voice.html).
|
||||
Once you have done so, you will find voices available in your system:
|
||||
|
||||
```
|
||||
```text
|
||||
openhab> smarthome:voice voices
|
||||
mactts:Jorge Jorge (es_ES)
|
||||
mactts:Moira Moira (en_IE)
|
||||
|
@ -64,24 +62,28 @@ mactts:Kanya Kanya (th_TH)
|
|||
|
||||
You can define a default TTS service and a default voice to use either by textual configuration in `conf/services/runtime.cfg` or in the Paper UI in `Configuration->System->Voice`.
|
||||
|
||||
In order to say a text, you can enter
|
||||
In order to say a text, you can enter such a command on the console (The default voice and default audio sink will be used):
|
||||
|
||||
```
|
||||
openhab> smarthome:voice say Hello world!
|
||||
```
|
||||
|
||||
on the console or
|
||||
Alternatively you can execute such commands within DSL rules by using the [`say()` function](https://www.eclipse.org/smarthome/documentation/javadoc/org/eclipse/smarthome/core/voice/VoiceManager.html#say-java.lang.String-):
|
||||
|
||||
```
|
||||
say("Hello world!")
|
||||
say("Hello world!", "voicerss:enGB")
|
||||
say("Hello world!", "voicerss:enUS", "sonos:PLAY5:kitchen")
|
||||
```
|
||||
|
||||
within DSL rules.
|
||||
You can select a particular voice (second parameter) and a particular audio sink (third parameter).
|
||||
If no voice or no audio sink is provided, the default voice and default audio sink will be used.
|
||||
|
||||
### Speech-to-Text
|
||||
|
||||
Although there are already interfaces defined in openHAB for speech-to-text, up to now there is no add-on available for this functionality.
|
||||
So the only choice that is available right now is to use the Android voice recognition feature that is built into the openHAB Android app. Currently, the Android app is [not yet adapted to the openHAB 2 voice features](https://github.com/openhab/openhab.android/issues/242), though - to use it, you will need to have a String item with the name "VoiceCommand" defined, to which the app sends any recognized text as a string command.
|
||||
So the only choice that is available right now is to use the Android voice recognition feature that is built into the openHAB Android app.
|
||||
Currently, the Android app is [not yet adapted to the openHAB 2 voice features](https://github.com/openhab/openhab.android/issues/242), though - to use it, you will need to have a String item with the name "VoiceCommand" defined, to which the app sends any recognized text as a string command.
|
||||
|
||||
### Human Language Interpreter
|
||||
|
||||
|
@ -90,11 +92,29 @@ Human language interpreters are meant to process prose that e.g. is a result of
|
|||
There are two implementations available by default:
|
||||
|
||||
| `rulehli` | Rule-based Interpreter | This mimicks the behavior of the Android app - it sends the string as a command to a (configurable, default is "VoiceCommand") item and expects a rule to pick it up and further process it.
|
||||
| `system` | Built-in Interpreter | This is a simple implementation that understands basic home automation commands like "turn on the light" or "stop the music". It currently supports only English and German and the vocabulary is still very limited. The exact syntax still needs to be documented, for the moment you need to refer to the [source code](https://github.com/eclipse/smarthome/blob/master/bundles/core/org.eclipse.smarthome.core.voice/src/main/java/org/eclipse/smarthome/core/voice/internal/text/StandardInterpreter.java#L37).
|
||||
| `system` | Built-in Interpreter | This is a simple implementation that understands basic home automation commands like "turn on the light" or "stop the music". It currently supports only English, German and French and the vocabulary is still very limited. The exact syntax still needs to be documented, for the moment you need to refer to the [source code](https://github.com/eclipse/smarthome/blob/master/bundles/core/org.eclipse.smarthome.core.voice/src/main/java/org/eclipse/smarthome/core/voice/internal/text/StandardInterpreter.java#L37).
|
||||
|
||||
To test the interpreter, you can use the command line (assuming you have an item called 'light'):
|
||||
To test the interpreter, you can enter such a command on the console (assuming you have an item with label 'light'):
|
||||
|
||||
```
|
||||
```text
|
||||
openhab> smarthome:voice interpret turn on the light
|
||||
```
|
||||
|
||||
The default human language interpreter will be used.
|
||||
In case of interpretation error, the error message will be said using the default voice and default audio sink.
|
||||
|
||||
Again, such a command can also be entered within DSL rules (using the [`interpret()` function](https://www.eclipse.org/smarthome/documentation/javadoc/org/eclipse/smarthome/core/voice/VoiceManager.html#interpret-java.lang.String-))
|
||||
|
||||
```java
|
||||
interpret("turn on the light")
|
||||
var String result = interpret("turn on the light", "system")
|
||||
result = interpret("turn on the light", "system", null)
|
||||
result = interpret(VoiceCommand.state, "system", "sonos:PLAY5:kitchen")
|
||||
```
|
||||
|
||||
You can select a particular human language interpreter (second parameter) and a particular audio sink (third parameter).
|
||||
The audio sink parameter is used when the interpretation fails; in this case, the error message is said using the default voice and the provided audio sink.
|
||||
If the provided audio sink is set to null, the error message will not be said.
|
||||
If no human language interpreter or no audio sink is provided, the default human language interpreter and default audio sink will be used.
|
||||
The interpretation result is returned as a string.
|
||||
Note that this result is always a null string with the rule-based Interpreter (rulehli).
|
||||
|
|
Loading…
Reference in New Issue