Skip to content

Commit 89bd614

Browse files
committed
[UI] Add voice dialog
Signed-off-by: Miguel Álvarez <[email protected]>
1 parent 1c03c60 commit 89bd614

File tree

17 files changed

+1982
-7
lines changed

17 files changed

+1982
-7
lines changed

bundles/org.openhab.ui/web/build/webpack.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ module.exports = {
6060
allowedHosts: "all",
6161
historyApiFallback: true,
6262
proxy: [{
63-
context: ['/auth', '/rest', '/chart', '/proxy', '/icon', '/static', '/changePassword', '/createApiToken', '/audio'],
64-
target: apiBaseUrl
63+
context: ['/auth', '/rest', '/chart', '/proxy', '/icon', '/static', '/changePassword', '/createApiToken', '/audio', '/ws/pcm-audio'],
64+
target: apiBaseUrl,
65+
ws: true
6566
}]
6667
},
6768
performance: {

bundles/org.openhab.ui/web/package-lock.json

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundles/org.openhab.ui/web/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
"path-browserify": "^1.0.1",
9494
"pkce-challenge": "^2.1.0",
9595
"qrcode": "^1.0.0",
96+
"reentrant-lock": "^3.0.0",
97+
"rustpotter-worklet": "^3.0.3",
9698
"scope-css": "^1.2.1",
9799
"sprintf-js": "^1.1.2",
98100
"stream-browserify": "^3.0.0",
@@ -115,6 +117,7 @@
115117
"vue2-leaflet": "^2.5.2",
116118
"vuetrend": "^0.3.4",
117119
"vuex": "^3.5.1",
120+
"wave-resampler": "^1.0.0",
118121
"yaml": "^2.3.4"
119122
},
120123
"devDependencies": {

bundles/org.openhab.ui/web/src/assets/i18n/theme-switcher/en.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,15 @@
1414
"about.miscellaneous.theme.disablePageTransition": "Disable page transition animations",
1515
"about.miscellaneous.webaudio.enable": "Enable Web Audio sink support",
1616
"about.miscellaneous.commandItem.title": "Listen for UI commands to ",
17-
"about.miscellaneous.commandItem.selectItem": "Item"
17+
"about.miscellaneous.commandItem.selectItem": "Item",
18+
"about.dialog": "Voice Support",
19+
"about.dialog.enable": "Enable Voice Dialog",
20+
"about.dialog.id": "Connection Id",
21+
"about.dialog.listeningItem": "Listening Item",
22+
"about.dialog.locationItem": "Location Item",
23+
"about.dialog.keyword": "Keyword File",
24+
"about.dialog.keyword.choose": "Choose",
25+
"about.dialog.keyword.remove": "Remove",
26+
"about.dialog.keyword.threshold": "Keyword Threshold",
27+
"about.dialog.keyword.minScores": "Keyword Min. Detections"
1828
}

bundles/org.openhab.ui/web/src/components/app.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,13 @@ import auth from './auth-mixin'
256256
import i18n from './i18n-mixin'
257257
import connectionHealth from './connection-health-mixin'
258258
import sseEvents from './sse-events-mixin'
259+
import dialog from './dialog-mixin'
259260
260261
import dayjs from 'dayjs'
261262
import dayjsLocales from 'dayjs/locale.json'
262263
263264
export default {
264-
mixins: [auth, i18n, connectionHealth, sseEvents],
265+
mixins: [auth, i18n, connectionHealth, sseEvents, dialog],
265266
components: {
266267
EmptyStatePlaceholder,
267268
PanelRight,
@@ -715,11 +716,16 @@ export default {
715716
}
716717
})
717718
719+
this.$f7.on('triggerDialog', () => {
720+
this.triggerDialog()
721+
})
722+
718723
if (window) {
719724
window.addEventListener('keydown', this.keyDown)
720725
}
721726
722727
this.startEventSource()
728+
this.startAudioWebSocket()
723729
})
724730
}
725731
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
export default {
2+
data () {
3+
return {
4+
audioMain: null,
5+
}
6+
},
7+
methods: {
8+
startAudioWebSocket () {
9+
if (this.audioMain) {
10+
return
11+
}
12+
const dialogEnabled = localStorage.getItem('openhab.ui:dialog.enabled') === 'true'
13+
if (!dialogEnabled) {
14+
console.warn("CHECK audio not enabled")
15+
return
16+
}
17+
const identifier = localStorage.getItem('openhab.ui:dialog.id') ?? 'anonymous';
18+
const dialogListeningItem = localStorage.getItem('openhab.ui:dialog.listeningItem') ?? ''
19+
const dialogLocationItem = localStorage.getItem('openhab.ui:dialog.locationItem') ?? ''
20+
const dialogKeywordThreshold = Number(localStorage.getItem('openhab.ui:dialog.keyword.threshold') ?? '0.75')
21+
const dialogKeywordMinScores = Number(localStorage.getItem('openhab.ui:dialog.keyword.minScores') ?? '5')
22+
import('../js/voice/audio-main.js').then(({ AudioMain }) => {
23+
if (this.audioMain) {
24+
return
25+
}
26+
let port = '';
27+
if (!((location.protocol === 'https:' && location.port === '443') || (location.protocol === 'http:' && location.port === '80'))) {
28+
port = `:${location.port}`
29+
}
30+
const ohURL = `${location.protocol}//${location.hostname}${port}`;
31+
this.audioMain = new AudioMain(ohURL, {
32+
onMessage: (...args) => {
33+
console.warn("MESSAGE: " + args[0])
34+
},
35+
onRunningChange (io) {
36+
console.warn("CHECK ONLINE: " + io.isRunning())
37+
},
38+
onListeningChange (io) {
39+
console.warn("CHECK LISTENING: " + io.isListening())
40+
},
41+
onSpeakingChange (io) {
42+
console.warn("CHECK SPEAKING: " + io.isSpeaking())
43+
},
44+
});
45+
const events = ['touchstart', 'touchend', 'mousedown', 'keydown']
46+
const startAudio = () => {
47+
clean()
48+
this.audioMain.initialize(identifier, dialogListeningItem, dialogLocationItem, {threshold: dialogKeywordThreshold, minScores: dialogKeywordMinScores})
49+
}
50+
const clean = () => events.forEach(e => document.body.removeEventListener(e, startAudio))
51+
events.forEach(e => document.body.addEventListener(e, startAudio, false))
52+
});
53+
},
54+
stopAudioWebSocket () {
55+
// TODO
56+
this.audioMain.close()
57+
this.audioMain = null
58+
},
59+
triggerDialog() {
60+
if(this.audioMain != null) {
61+
this.audioMain.sendSpot()
62+
}
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)