Skip to content

Commit bfe10c5

Browse files
authored
Merge pull request #2913 from StephenHodgson/vNEXT-SpeechInputHandlerUpdate
Fixed a few issues with speech input handler
2 parents 10d9ab7 + 0cd7579 commit bfe10c5

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

Assets/MixedRealityToolkit-SDK/Inspectors/Input/Handlers/SpeechInputHandlerInspector.cs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ public override void OnInspectorGUI()
4949
return;
5050
}
5151

52+
if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.SpeechCommandsProfile == null)
53+
{
54+
EditorGUILayout.HelpBox("No Speech Commands Profile Found, be sure to specify a profile in the Input System's configuration profile.", MessageType.Error);
55+
return;
56+
}
57+
5258
if (registeredKeywords == null || registeredKeywords.Length == 0)
5359
{
5460
registeredKeywords = RegisteredKeywords().Distinct().ToArray();
@@ -99,9 +105,9 @@ private void ShowList(SerializedProperty list)
99105
for (int index = 0; index < list.arraySize; index++)
100106
{
101107
// the element
102-
SerializedProperty elementProperty = list.GetArrayElementAtIndex(index);
108+
SerializedProperty speechCommandProperty = list.GetArrayElementAtIndex(index);
103109
EditorGUILayout.BeginHorizontal();
104-
bool elementExpanded = EditorGUILayout.PropertyField(elementProperty);
110+
bool elementExpanded = EditorGUILayout.PropertyField(speechCommandProperty);
105111
GUILayout.FlexibleSpace();
106112
// the remove element button
107113
bool elementRemoved = GUILayout.Button(RemoveButtonContent, EditorStyles.miniButton, MiniButtonWidth);
@@ -113,9 +119,25 @@ private void ShowList(SerializedProperty list)
113119

114120
EditorGUILayout.EndHorizontal();
115121

122+
SerializedProperty keywordProperty = speechCommandProperty.FindPropertyRelative("keyword");
123+
124+
bool invalidKeyword = true;
125+
foreach (string keyword in registeredKeywords)
126+
{
127+
if (keyword == keywordProperty.stringValue)
128+
{
129+
invalidKeyword = false;
130+
break;
131+
}
132+
}
133+
134+
if (invalidKeyword)
135+
{
136+
EditorGUILayout.HelpBox("Registered keyword is not recognized in the speech command profile!", MessageType.Error);
137+
}
138+
116139
if (!elementRemoved && elementExpanded)
117140
{
118-
SerializedProperty keywordProperty = elementProperty.FindPropertyRelative("keyword");
119141
string[] keywords = availableKeywords.Concat(new[] { keywordProperty.stringValue }).OrderBy(keyword => keyword).ToArray();
120142
int previousSelection = ArrayUtility.IndexOf(keywords, keywordProperty.stringValue);
121143
int currentSelection = EditorGUILayout.Popup("keyword", previousSelection, keywords);
@@ -125,7 +147,7 @@ private void ShowList(SerializedProperty list)
125147
keywordProperty.stringValue = keywords[currentSelection];
126148
}
127149

128-
SerializedProperty responseProperty = elementProperty.FindPropertyRelative("response");
150+
SerializedProperty responseProperty = speechCommandProperty.FindPropertyRelative("response");
129151
EditorGUILayout.PropertyField(responseProperty, true);
130152
}
131153
}
@@ -151,8 +173,8 @@ private void ShowList(SerializedProperty list)
151173
private static IEnumerable<string> RegisteredKeywords()
152174
{
153175
if (!MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled ||
154-
!MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.IsSpeechCommandsEnabled ||
155-
MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.SpeechCommandsProfile.SpeechCommands.Length == 0)
176+
MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.SpeechCommandsProfile == null ||
177+
MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.SpeechCommandsProfile.SpeechCommands.Length == 0)
156178
{
157179
yield break;
158180
}

0 commit comments

Comments
 (0)