-
Notifications
You must be signed in to change notification settings - Fork 51
/
client_ipc_vi.py
62 lines (47 loc) · 1.84 KB
/
client_ipc_vi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#------------------------------------------------------------------------------
# This script registers voice commands on the HoloLens and continously checks
# if any of the registered commands has been heard.
# Press esc to stop.
#------------------------------------------------------------------------------
from pynput import keyboard
import hl2ss
import hl2ss_lnm
# Settings --------------------------------------------------------------------
# HoloLens address
host = '192.168.1.7'
# Voice commands
strings = ['cat', 'dog', 'red', 'blue']
#------------------------------------------------------------------------------
enable = True
def on_press(key):
global enable
enable = key != keyboard.Key.esc
return enable
def get_word(strings, index):
if ((index < 0) or (index >= len(strings))):
return '_UNKNOWN_'
else:
return strings[index]
listener = keyboard.Listener(on_press=on_press)
listener.start()
client = hl2ss_lnm.ipc_vi(host, hl2ss.IPCPort.VOICE_INPUT)
client.open()
# See
# https://learn.microsoft.com/en-us/windows/mixed-reality/develop/native/voice-input-in-directx
# for details
client.create_recognizer()
if (client.register_commands(True, strings)):
print('Ready. Try saying any of the commands you defined.')
client.start()
while (enable):
events = client.pop()
for event in events:
event.unpack()
# See
# https://learn.microsoft.com/en-us/uwp/api/windows.media.speechrecognition.speechrecognitionresult?view=winrt-22621
# for result details
print(f'Event: Command={get_word(strings, event.index)} Index={event.index} Confidence={event.confidence} Duration={event.phrase_duration} Start={event.phrase_start_time} RawConfidence={event.raw_confidence}')
client.stop()
client.clear()
client.close()
listener.join()