Skip to content

Commit 2762136

Browse files
Stephen HodgsonStephen Hodgson
authored andcommitted
Dictation update
1 parent f2a0c12 commit 2762136

File tree

9 files changed

+277
-70
lines changed

9 files changed

+277
-70
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using UnityEngine;
5+
using UnityEngine.EventSystems;
6+
7+
namespace HoloToolkit.Unity.InputModule
8+
{
9+
public class DictationEventData : InputEventData
10+
{
11+
/// <summary>
12+
/// String result of the current dictation.
13+
/// </summary>
14+
public string DictationResult { get; private set; }
15+
/// <summary>
16+
/// Audio Clip of the last Dictation recording Session.
17+
/// </summary>
18+
public AudioClip DictationAudioClip { get; private set; }
19+
20+
public DictationEventData(EventSystem eventSystem) : base(eventSystem) { }
21+
22+
public void Initialize(IInputSource inputSource, uint sourceId, string dictationResult, AudioClip dictationAudioClip = null)
23+
{
24+
BaseInitialize(inputSource, sourceId);
25+
DictationResult = dictationResult;
26+
DictationAudioClip = dictationAudioClip;
27+
}
28+
}
29+
}

Assets/HoloToolkit/Input/Scripts/InputEvents/DictationEventData.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using UnityEngine.EventSystems;
5+
6+
namespace HoloToolkit.Unity.InputModule
7+
{
8+
/// <summary>
9+
/// Interface to implement dictation events.
10+
/// </summary>
11+
public interface IDictationHandler : IEventSystemHandler
12+
{
13+
void OnDictationHypothesis(DictationEventData eventData);
14+
15+
void OnDictationResult(DictationEventData eventData);
16+
17+
void OnDictationComplete(DictationEventData eventData);
18+
19+
void OnDictationError(DictationEventData eventData);
20+
}
21+
}

Assets/HoloToolkit/Input/Scripts/InputEvents/IDictationHandler.cs.meta

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

Assets/HoloToolkit/Input/Scripts/InputEvents/SpeechKeywordRecognizedEventData.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using System;
5-
using UnityEngine;
65
using UnityEngine.EventSystems;
76
using UnityEngine.Windows.Speech;
87

@@ -38,9 +37,7 @@ public class SpeechKeywordRecognizedEventData : InputEventData
3837
/// </summary>
3938
public string RecognizedText { get; private set; }
4039

41-
public SpeechKeywordRecognizedEventData(EventSystem eventSystem) : base(eventSystem)
42-
{
43-
}
40+
public SpeechKeywordRecognizedEventData(EventSystem eventSystem) : base(eventSystem) { }
4441

4542
public void Initialize(IInputSource inputSource, uint sourceId, ConfidenceLevel confidence, TimeSpan phraseDuration, DateTime phraseStartTime, SemanticMeaning[] semanticMeanings, string recognizedText)
4643
{

Assets/HoloToolkit/Input/Scripts/InputManager.cs

Lines changed: 126 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using UnityEngine;
77
using UnityEngine.EventSystems;
8+
using UnityEngine.Windows.Speech;
89

910
namespace HoloToolkit.Unity.InputModule
1011
{
@@ -41,6 +42,8 @@ public class InputManager : Singleton<InputManager>
4142
private ManipulationEventData manipulationEventData;
4243
private HoldEventData holdEventData;
4344
private NavigationEventData navigationEventData;
45+
private SpeechKeywordRecognizedEventData speechKeywordRecognizedEventData;
46+
private DictationEventData dictationEventData;
4447

4548
/// <summary>
4649
/// Indicates if input is currently enabled or not.
@@ -170,18 +173,6 @@ public void ClearInputDisableStack()
170173
}
171174
}
172175

173-
private void Start()
174-
{
175-
InitializeEventDatas();
176-
177-
if (GazeManager.Instance == null)
178-
{
179-
Debug.LogError("InputManager requires an active GazeManager in the scene");
180-
}
181-
182-
RegisterGazeManager();
183-
}
184-
185176
private void InitializeEventDatas()
186177
{
187178
inputEventData = new InputEventData(EventSystem.current);
@@ -190,11 +181,22 @@ private void InitializeEventDatas()
190181
manipulationEventData = new ManipulationEventData(EventSystem.current);
191182
navigationEventData = new NavigationEventData(EventSystem.current);
192183
holdEventData = new HoldEventData(EventSystem.current);
184+
speechKeywordRecognizedEventData = new SpeechKeywordRecognizedEventData(EventSystem.current);
185+
dictationEventData = new DictationEventData(EventSystem.current);
193186
}
194187

195-
protected override void OnDestroy()
188+
#region Unity Methods
189+
190+
private void Start()
196191
{
197-
UnregisterGazeManager();
192+
InitializeEventDatas();
193+
194+
if (GazeManager.Instance == null)
195+
{
196+
Debug.LogError("InputManager requires an active GazeManager in the scene");
197+
}
198+
199+
RegisterGazeManager();
198200
}
199201

200202
private void OnEnable()
@@ -207,10 +209,17 @@ private void OnDisable()
207209
UnregisterGazeManager();
208210
}
209211

212+
protected override void OnDestroy()
213+
{
214+
UnregisterGazeManager();
215+
}
216+
217+
#endregion // Unity Methods
218+
210219
public void HandleEvent<T>(BaseEventData eventData, ExecuteEvents.EventFunction<T> eventHandler)
211220
where T : IEventSystemHandler
212221
{
213-
if (!enabled || disabledRefCount > 0)
222+
if (!Instance.enabled || disabledRefCount > 0)
214223
{
215224
return;
216225
}
@@ -439,6 +448,8 @@ public void RaiseSourceLost(IInputSource source, uint sourceId)
439448
HandleEvent(sourceStateEventData, OnSourceLostEventHandler);
440449
}
441450

451+
#region Manipulation Events
452+
442453
private static readonly ExecuteEvents.EventFunction<IManipulationHandler> OnManipulationStartedEventHandler =
443454
delegate (IManipulationHandler handler, BaseEventData eventData)
444455
{
@@ -503,6 +514,10 @@ public void RaiseManipulationCanceled(IInputSource source, uint sourceId, Vector
503514
HandleEvent(manipulationEventData, OnManipulationCanceledEventHandler);
504515
}
505516

517+
#endregion // Manipulation Events
518+
519+
#region Hold Events
520+
506521
private static readonly ExecuteEvents.EventFunction<IHoldHandler> OnHoldStartedEventHandler =
507522
delegate (IHoldHandler handler, BaseEventData eventData)
508523
{
@@ -551,6 +566,10 @@ public void RaiseHoldCanceled(IInputSource source, uint sourceId)
551566
HandleEvent(holdEventData, OnHoldCanceledEventHandler);
552567
}
553568

569+
#endregion // Hold Events
570+
571+
#region Navigation Events
572+
554573
private static readonly ExecuteEvents.EventFunction<INavigationHandler> OnNavigationStartedEventHandler =
555574
delegate (INavigationHandler handler, BaseEventData eventData)
556575
{
@@ -615,5 +634,97 @@ public void RaiseNavigationCanceled(IInputSource source, uint sourceId, Vector3
615634
HandleEvent(navigationEventData, OnNavigationCanceledEventHandler);
616635
}
617636

637+
#endregion // Navigation Events
638+
639+
#region Speech Events
640+
641+
642+
private static readonly ExecuteEvents.EventFunction<ISpeechHandler> OnSpeechKeywordRecognizedEventHandler =
643+
delegate (ISpeechHandler handler, BaseEventData eventData)
644+
{
645+
SpeechKeywordRecognizedEventData casted = ExecuteEvents.ValidateEventData<SpeechKeywordRecognizedEventData>(eventData);
646+
handler.OnSpeechKeywordRecognized(casted);
647+
};
648+
649+
650+
public void RaiseSpeechKeywordPhraseRecognized(IInputSource source, uint sourceId, ConfidenceLevel confidence, TimeSpan phraseDuration, DateTime phraseStartTime, SemanticMeaning[] semanticMeanings, string text)
651+
{
652+
// Create input event
653+
speechKeywordRecognizedEventData.Initialize(source, sourceId, confidence, phraseDuration, phraseStartTime, semanticMeanings, text);
654+
655+
// Pass handler through HandleEvent to perform modal/fallback logic
656+
HandleEvent(speechKeywordRecognizedEventData, OnSpeechKeywordRecognizedEventHandler);
657+
}
658+
659+
private static readonly ExecuteEvents.EventFunction<IDictationHandler> OnDictationHypothesisEventHandler =
660+
delegate (IDictationHandler handler, BaseEventData eventData)
661+
{
662+
DictationEventData casted = ExecuteEvents.ValidateEventData<DictationEventData>(eventData);
663+
handler.OnDictationHypothesis(casted);
664+
};
665+
666+
#endregion // Speech Events
667+
668+
#region Dictation Events
669+
670+
public void RaiseDictationHypothesis(IInputSource source, uint sourceId, string dictationHypothesis, AudioClip dictationAudioClip = null)
671+
{
672+
// Create input event
673+
dictationEventData.Initialize(source, sourceId, dictationHypothesis, dictationAudioClip);
674+
675+
// Pass handler through HandleEvent to perform modal/fallback logic
676+
HandleEvent(dictationEventData, OnDictationHypothesisEventHandler);
677+
}
678+
679+
private static readonly ExecuteEvents.EventFunction<IDictationHandler> OnDictationResultEventHandler =
680+
delegate (IDictationHandler handler, BaseEventData eventData)
681+
{
682+
DictationEventData casted = ExecuteEvents.ValidateEventData<DictationEventData>(eventData);
683+
handler.OnDictationResult(casted);
684+
};
685+
686+
public void RaiseDictationResult(IInputSource source, uint sourceId, string dictationResult, AudioClip dictationAudioClip = null)
687+
{
688+
// Create input event
689+
dictationEventData.Initialize(source, sourceId, dictationResult, dictationAudioClip);
690+
691+
// Pass handler through HandleEvent to perform modal/fallback logic
692+
HandleEvent(dictationEventData, OnDictationResultEventHandler);
693+
}
694+
695+
private static readonly ExecuteEvents.EventFunction<IDictationHandler> OnDictationCompleteEventHandler =
696+
delegate (IDictationHandler handler, BaseEventData eventData)
697+
{
698+
DictationEventData casted = ExecuteEvents.ValidateEventData<DictationEventData>(eventData);
699+
handler.OnDictationComplete(casted);
700+
};
701+
702+
public void RaiseDictationComplete(IInputSource source, uint sourceId, string dictationResult, AudioClip dictationAudioClip)
703+
{
704+
// Create input event
705+
dictationEventData.Initialize(source, sourceId, dictationResult, dictationAudioClip);
706+
707+
// Pass handler through HandleEvent to perform modal/fallback logic
708+
HandleEvent(dictationEventData, OnDictationCompleteEventHandler);
709+
}
710+
711+
private static readonly ExecuteEvents.EventFunction<IDictationHandler> OnDictationErrorEventHandler =
712+
delegate (IDictationHandler handler, BaseEventData eventData)
713+
{
714+
DictationEventData casted = ExecuteEvents.ValidateEventData<DictationEventData>(eventData);
715+
handler.OnDictationComplete(casted);
716+
};
717+
718+
public void RaiseDictationError(IInputSource source, uint sourceId, string dictationResult, AudioClip dictationAudioClip = null)
719+
{
720+
// Create input event
721+
dictationEventData.Initialize(source, sourceId, dictationResult, dictationAudioClip);
722+
723+
// Pass handler through HandleEvent to perform modal/fallback logic
724+
HandleEvent(dictationEventData, OnDictationErrorEventHandler);
725+
}
726+
727+
#endregion // Dictation Events
728+
618729
}
619730
}

0 commit comments

Comments
 (0)