Skip to content

Commit 9b925c2

Browse files
author
David Kline
authored
Merge pull request #2643 from Microsoft/mrtk_development
merge mrtk_development -> mrdevsummit_2018_08
2 parents 684d418 + dc00841 commit 9b925c2

20 files changed

+359
-197
lines changed

Assets/MixedRealityToolkit-SDK/Features/Input/MixedRealityInputManager.cs

+46-9
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,21 @@ public class MixedRealityInputManager : MixedRealityEventManager, IMixedRealityI
7070

7171
#endif // UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN
7272

73+
/// <summary>
74+
/// Current Speech Input Source.
75+
/// </summary>
76+
public SpeechInputSource SpeechInputSource { get; private set; }
77+
78+
/// <summary>
79+
/// Current Dictation Input Source.
80+
/// </summary>
81+
public DictationInputSource DictationInputSource { get; private set; }
82+
83+
/// <summary>
84+
/// Current Touch Screen Input Source.
85+
/// </summary>
86+
public TouchscreenInputSource TouchscreenInputSource { get; private set; }
87+
7388
#region IMixedRealityManager Implementation
7489

7590
/// <summary>
@@ -188,6 +203,26 @@ private void InitializeInternal()
188203
dictationEventData = new DictationEventData(EventSystem.current);
189204

190205
#endif // UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN
206+
207+
if (MixedRealityManager.Instance.ActiveProfile.IsSpeechCommandsEnabled)
208+
{
209+
SpeechInputSource = new SpeechInputSource(
210+
MixedRealityManager.Instance.ActiveProfile.SpeechCommandsProfile.SpeechCommands
211+
#if UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN
212+
, (UnityEngine.Windows.Speech.ConfidenceLevel)MixedRealityManager.Instance.ActiveProfile.SpeechRecognitionConfidenceLevel
213+
#endif
214+
);
215+
}
216+
217+
if (MixedRealityManager.Instance.ActiveProfile.IsDictationEnabled)
218+
{
219+
DictationInputSource = new DictationInputSource();
220+
}
221+
222+
if (MixedRealityManager.Instance.ActiveProfile.IsTouchScreenInputEnabled)
223+
{
224+
TouchscreenInputSource = new TouchscreenInputSource();
225+
}
191226
}
192227

193228
/// <inheritdoc />
@@ -246,6 +281,9 @@ public override void Destroy()
246281
UnityEngine.Object.Destroy(gazeProvider);
247282
}
248283

284+
SpeechInputSource?.Dispose();
285+
DictationInputSource?.Dispose();
286+
TouchscreenInputSource?.Dispose();
249287
base.Destroy();
250288
}
251289

@@ -1444,10 +1482,10 @@ public void RaiseSpeechCommandRecognized(IMixedRealityInputSource source, MixedR
14441482
};
14451483

14461484
/// <inheritdoc />
1447-
public void RaiseDictationHypothesis(IMixedRealityInputSource source, MixedRealityInputAction inputAction, string dictationHypothesis, AudioClip dictationAudioClip = null)
1485+
public void RaiseDictationHypothesis(IMixedRealityInputSource source, string dictationHypothesis, AudioClip dictationAudioClip = null)
14481486
{
14491487
// Create input event
1450-
dictationEventData.Initialize(source, inputAction, dictationHypothesis, dictationAudioClip);
1488+
dictationEventData.Initialize(source, dictationHypothesis, dictationAudioClip);
14511489

14521490
// Pass handler through HandleEvent to perform modal/fallback logic
14531491
HandleEvent(dictationEventData, OnDictationHypothesisEventHandler);
@@ -1461,10 +1499,10 @@ public void RaiseDictationHypothesis(IMixedRealityInputSource source, MixedReali
14611499
};
14621500

14631501
/// <inheritdoc />
1464-
public void RaiseDictationResult(IMixedRealityInputSource source, MixedRealityInputAction inputAction, string dictationResult, AudioClip dictationAudioClip = null)
1502+
public void RaiseDictationResult(IMixedRealityInputSource source, string dictationResult, AudioClip dictationAudioClip = null)
14651503
{
14661504
// Create input event
1467-
dictationEventData.Initialize(source, inputAction, dictationResult, dictationAudioClip);
1505+
dictationEventData.Initialize(source, dictationResult, dictationAudioClip);
14681506

14691507
// Pass handler through HandleEvent to perform modal/fallback logic
14701508
HandleEvent(dictationEventData, OnDictationResultEventHandler);
@@ -1478,10 +1516,10 @@ public void RaiseDictationResult(IMixedRealityInputSource source, MixedRealityIn
14781516
};
14791517

14801518
/// <inheritdoc />
1481-
public void RaiseDictationComplete(IMixedRealityInputSource source, MixedRealityInputAction inputAction, string dictationResult, AudioClip dictationAudioClip)
1519+
public void RaiseDictationComplete(IMixedRealityInputSource source, string dictationResult, AudioClip dictationAudioClip)
14821520
{
14831521
// Create input event
1484-
dictationEventData.Initialize(source, inputAction, dictationResult, dictationAudioClip);
1522+
dictationEventData.Initialize(source, dictationResult, dictationAudioClip);
14851523

14861524
// Pass handler through HandleEvent to perform modal/fallback logic
14871525
HandleEvent(dictationEventData, OnDictationCompleteEventHandler);
@@ -1495,10 +1533,10 @@ public void RaiseDictationComplete(IMixedRealityInputSource source, MixedReality
14951533
};
14961534

14971535
/// <inheritdoc />
1498-
public void RaiseDictationError(IMixedRealityInputSource source, MixedRealityInputAction inputAction, string dictationResult, AudioClip dictationAudioClip = null)
1536+
public void RaiseDictationError(IMixedRealityInputSource source, string dictationResult, AudioClip dictationAudioClip = null)
14991537
{
15001538
// Create input event
1501-
dictationEventData.Initialize(source, inputAction, dictationResult, dictationAudioClip);
1539+
dictationEventData.Initialize(source, dictationResult, dictationAudioClip);
15021540

15031541
// Pass handler through HandleEvent to perform modal/fallback logic
15041542
HandleEvent(dictationEventData, OnDictationErrorEventHandler);
@@ -1509,6 +1547,5 @@ public void RaiseDictationError(IMixedRealityInputSource source, MixedRealityInp
15091547
#endif // UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN
15101548

15111549
#endregion Input Events
1512-
15131550
}
15141551
}

Assets/MixedRealityToolkit-SDK/Profiles/DefaultMixedRealityConfigurationProfile.asset

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ MonoBehaviour:
2929
enableSpeechCommands: 1
3030
speechCommandsProfile: {fileID: 11400000, guid: e8d0393e66374dae9646851a57dc6bc1,
3131
type: 2}
32+
enableDictation: 1
33+
recognitionConfidenceLevel: 1
34+
enableTouchScreenInput: 1
35+
touchScreenInputProfile: {fileID: 11400000, guid: efe3718cb67cffa46a5f6361a522baba,
36+
type: 2}
3237
enableControllerMapping: 1
3338
controllerMappingProfile: {fileID: 11400000, guid: 3b591b9f56584e888f557aa29796cbf8,
3439
type: 2}

Assets/MixedRealityToolkit-SDK/Profiles/DefaultMixedRealitySpeechCommandsProfile.asset

+2-8
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,9 @@ MonoBehaviour:
1212
m_Name: DefaultMixedRealitySpeechCommandsProfile
1313
m_EditorClassIdentifier:
1414
speechCommands:
15-
- keyword: Select
16-
keyCode: 32
17-
action:
18-
id: 1
19-
description: Menu
20-
axisConstraint: 2
2115
- keyword: Menu
2216
keyCode: 9
2317
action:
2418
id: 2
25-
description: Grip
26-
axisConstraint: 7
19+
description: Menu
20+
axisConstraint: 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_PrefabParentObject: {fileID: 0}
7+
m_PrefabInternal: {fileID: 0}
8+
m_GameObject: {fileID: 0}
9+
m_Enabled: 1
10+
m_EditorHideFlags: 0
11+
m_Script: {fileID: 11500000, guid: 76606fa160e04c018d09c679f16c94c8, type: 3}
12+
m_Name: DefaultMixedRealityTouchInputProfile
13+
m_EditorClassIdentifier:
14+
pointerAction:
15+
id: 1
16+
description: Select
17+
axisConstraint: 2
18+
holdAction:
19+
id: 0
20+
description:
21+
axisConstraint: 0

Assets/MixedRealityToolkit-SDK/Profiles/DefaultMixedRealityTouchInputProfile.asset.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/MixedRealityToolkit/InputSystem/Sources/BaseGenericInputSource.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4+
using System;
45
using Microsoft.MixedReality.Toolkit.Internal.Interfaces.InputSystem;
56
using Microsoft.MixedReality.Toolkit.Internal.Managers;
67
using System.Collections;
@@ -12,7 +13,7 @@ namespace Microsoft.MixedReality.Toolkit.InputSystem.Sources
1213
/// <remarks>This base class does not support adding or removing pointers, because many will never
1314
/// pass pointers in their constructors and will fall back to either the Gaze or Mouse Pointer.</remarks>
1415
/// </summary>
15-
public class BaseGenericInputSource : IMixedRealityInputSource
16+
public class BaseGenericInputSource : IMixedRealityInputSource, IDisposable
1617
{
1718
/// <summary>
1819
/// The Current Input System for this Input Source.
@@ -87,6 +88,11 @@ public override int GetHashCode()
8788
}
8889
}
8990

91+
/// <summary>
92+
/// Dispose.
93+
/// </summary>
94+
public virtual void Dispose() { }
95+
9096
#endregion IEquality Implementation
9197
}
9298
}

Assets/MixedRealityToolkit/InputSystem/Sources/DictationInputSource.cs

+24-52
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.MixedReality.Toolkit.Internal.Definitions.InputSystem;
55
using Microsoft.MixedReality.Toolkit.Internal.Interfaces.InputSystem;
66
using Microsoft.MixedReality.Toolkit.Internal.Utilities.Async;
7+
using Microsoft.MixedReality.Toolkit.Internal.Utilities.Async.AwaitYieldInstructions;
78
using System.Threading.Tasks;
89
using UnityEngine;
910

@@ -25,49 +26,18 @@ public class DictationInputSource : BaseGenericInputSource
2526
/// </summary>
2627
public static bool IsListening { get; private set; } = false;
2728

28-
/// <summary>
29-
/// Action that will be associated with a dictation hypothesis input event.
30-
/// </summary>
31-
public static MixedRealityInputAction HypothesisAction { get; set; }
32-
33-
/// <summary>
34-
/// Action that will be associated with a dictation result input event.
35-
/// </summary>
36-
public static MixedRealityInputAction ResultAction { get; set; }
37-
38-
/// <summary>
39-
/// Action that will be associated with a dictation complete input event.
40-
/// </summary>
41-
public static MixedRealityInputAction CompleteAction { get; set; }
42-
43-
/// <summary>
44-
/// Action that will be associated with a dictation error input event.
45-
/// </summary>
46-
public static MixedRealityInputAction ErrorAction { get; set; }
47-
4829
#if UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN
4930

5031
/// <summary>
5132
/// Constructor.
5233
/// </summary>
53-
/// <param name="hypothesisAction">Action that will be associated with a dictation hypothesis input event</param>
54-
/// <param name="resultAction">Action that will be associated with a dictation result input event</param>
55-
/// <param name="completeAction">Action that will be associated with a dictation complete input event</param>
56-
/// <param name="errorAction">Action that will be associated with a dictation error input event.</param>
57-
public DictationInputSource(MixedRealityInputAction hypothesisAction,
58-
MixedRealityInputAction resultAction,
59-
MixedRealityInputAction completeAction,
60-
MixedRealityInputAction errorAction)
61-
: base("Dictation")
34+
public DictationInputSource() : base("Dictation")
6235
{
36+
if (!Application.isPlaying) { return; }
37+
6338
source = this;
6439
dictationResult = string.Empty;
6540

66-
HypothesisAction = hypothesisAction;
67-
ResultAction = resultAction;
68-
CompleteAction = completeAction;
69-
ErrorAction = errorAction;
70-
7141
dictationRecognizer = new DictationRecognizer();
7242
dictationRecognizer.DictationHypothesis += DictationRecognizer_DictationHypothesis;
7343
dictationRecognizer.DictationResult += DictationRecognizer_DictationResult;
@@ -81,16 +51,17 @@ public DictationInputSource(MixedRealityInputAction hypothesisAction,
8151
Run();
8252
}
8353

84-
/// <summary>
85-
/// Destructor.
86-
/// </summary>
87-
~DictationInputSource()
54+
/// <inheritdoc />
55+
public override void Dispose()
8856
{
89-
dictationRecognizer.DictationHypothesis -= DictationRecognizer_DictationHypothesis;
90-
dictationRecognizer.DictationResult -= DictationRecognizer_DictationResult;
91-
dictationRecognizer.DictationComplete -= DictationRecognizer_DictationComplete;
92-
dictationRecognizer.DictationError -= DictationRecognizer_DictationError;
93-
dictationRecognizer.Dispose();
57+
if (dictationRecognizer != null)
58+
{
59+
dictationRecognizer.DictationHypothesis -= DictationRecognizer_DictationHypothesis;
60+
dictationRecognizer.DictationResult -= DictationRecognizer_DictationResult;
61+
dictationRecognizer.DictationComplete -= DictationRecognizer_DictationComplete;
62+
dictationRecognizer.DictationError -= DictationRecognizer_DictationError;
63+
dictationRecognizer?.Dispose();
64+
}
9465
}
9566

9667
private static IMixedRealityInputSource source;
@@ -126,7 +97,7 @@ public DictationInputSource(MixedRealityInputAction hypothesisAction,
12697
/// </summary>
12798
private static AudioClip dictationAudioClip;
12899

129-
private static readonly WaitForFixedUpdate nextUpdate = new WaitForFixedUpdate();
100+
private static readonly WaitForUpdate NextUpdate = new WaitForUpdate();
130101

131102
private static async void Run()
132103
{
@@ -141,10 +112,10 @@ private static async void Run()
141112
if (!hasFailed && dictationRecognizer.Status == SpeechSystemStatus.Failed)
142113
{
143114
hasFailed = true;
144-
InputSystem.RaiseDictationError(source, ErrorAction, "Dictation recognizer has failed!");
115+
InputSystem.RaiseDictationError(source, "Dictation recognizer has failed!");
145116
}
146117

147-
await nextUpdate;
118+
await NextUpdate;
148119
}
149120
}
150121

@@ -192,7 +163,7 @@ public static async Task StartRecordingAsync(GameObject listener = null, float i
192163

193164
if (dictationRecognizer.Status == SpeechSystemStatus.Failed)
194165
{
195-
InputSystem.RaiseDictationError(source, ErrorAction, "Dictation recognizer failed to start!");
166+
InputSystem.RaiseDictationError(source, "Dictation recognizer failed to start!");
196167
return;
197168
}
198169

@@ -201,7 +172,8 @@ public static async Task StartRecordingAsync(GameObject listener = null, float i
201172
textSoFar = new StringBuilder();
202173
isTransitioning = false;
203174
#else
204-
throw new NotImplementedException("Unable to start recording! Dictation is unsupported for this platform.");
175+
176+
Debug.LogError("Unable to start recording! Dictation is unsupported for this platform.");
205177
#endif // UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN
206178
}
207179

@@ -256,7 +228,7 @@ private static void DictationRecognizer_DictationHypothesis(string text)
256228
// We don't want to append to textSoFar yet, because the hypothesis may have changed on the next event.
257229
dictationResult = $"{textSoFar} {text}...";
258230

259-
InputSystem.RaiseDictationHypothesis(source, HypothesisAction, dictationResult);
231+
InputSystem.RaiseDictationHypothesis(source, dictationResult);
260232
}
261233

262234
/// <summary>
@@ -270,7 +242,7 @@ private static void DictationRecognizer_DictationResult(string text, ConfidenceL
270242

271243
dictationResult = textSoFar.ToString();
272244

273-
InputSystem.RaiseDictationResult(source, ResultAction, dictationResult);
245+
InputSystem.RaiseDictationResult(source, dictationResult);
274246
}
275247

276248
/// <summary>
@@ -288,7 +260,7 @@ private static void DictationRecognizer_DictationComplete(DictationCompletionCau
288260
dictationResult = "Dictation has timed out. Please try again.";
289261
}
290262

291-
InputSystem.RaiseDictationComplete(source, CompleteAction, dictationResult, dictationAudioClip);
263+
InputSystem.RaiseDictationComplete(source, dictationResult, dictationAudioClip);
292264
textSoFar = null;
293265
dictationResult = string.Empty;
294266
}
@@ -302,7 +274,7 @@ private static void DictationRecognizer_DictationError(string error, int hresult
302274
{
303275
dictationResult = $"{error}\nHRESULT: {hresult}";
304276

305-
InputSystem.RaiseDictationError(source, ErrorAction, dictationResult);
277+
InputSystem.RaiseDictationError(source, dictationResult);
306278
textSoFar = null;
307279
dictationResult = string.Empty;
308280
}

0 commit comments

Comments
 (0)