Skip to content

Commit ef231c2

Browse files
Moved to Input namespace
1 parent 9098382 commit ef231c2

File tree

1 file changed

+103
-102
lines changed

1 file changed

+103
-102
lines changed
Lines changed: 103 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,129 @@
1-
using Microsoft.MixedReality.Toolkit;
2-
using Microsoft.MixedReality.Toolkit.Input;
3-
using System.Collections;
4-
using System.Collections.Generic;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
54
using UnityEngine;
65
using UnityEngine.Events;
7-
using UnityEngine.UI;
86

9-
/// <summary>
10-
/// Script used to start and stop recording sessions in the current dictation system and report the transcribed text via UnityEvents.
11-
/// For this script to work, a dictation system like 'Windows Dictation Input Provider' must be added to the Data Providers in the Input System profile.
12-
/// </summary>
13-
public class DictationHandler : BaseInputHandler, IMixedRealityDictationHandler
7+
namespace Microsoft.MixedReality.Toolkit.Input
148
{
15-
[SerializeField]
16-
[Tooltip("Time length in seconds before the dictation session ends due to lack of audio input in case there was no audio heard in the current session")]
17-
private float initialSilenceTimeout = 5f;
18-
19-
[SerializeField]
20-
[Tooltip("Time length in seconds before the dictation session ends due to lack of audio input.")]
21-
private float autoSilenceTimeout = 20f;
22-
23-
[SerializeField]
24-
[Tooltip("Length in seconds for the dictation service to listen")]
25-
private int recordingTime = 10;
26-
27-
[SerializeField]
28-
[Tooltip("Whether recording should start automatically on start")]
29-
private bool startRecordingOnStart = false;
30-
31-
[System.Serializable]
32-
public class StringUnityEvent : UnityEvent<string> { }
33-
349
/// <summary>
35-
/// Event raised while the user is talking. As the recognizer listens, it provides text of what it's heard so far.
10+
/// Script used to start and stop recording sessions in the current dictation system and report the transcribed text via UnityEvents.
11+
/// For this script to work, a dictation system like 'Windows Dictation Input Provider' must be added to the Data Providers in the Input System profile.
3612
/// </summary>
37-
public StringUnityEvent OnDictationHypothesis;
38-
39-
/// <summary>
40-
/// Event raised after the user pauses, typically at the end of a sentence. Contains the full recognized string so far.
41-
/// </summary>
42-
public StringUnityEvent OnDictationResult;
43-
44-
/// <summary>
45-
/// Event raised when the recognizer stops. Contains the final recognized string.
46-
/// </summary>
47-
public StringUnityEvent OnDictationComplete;
48-
49-
/// <summary>
50-
/// Event raised when an error occurs. Contains the string representation of the error reason.
51-
/// </summary>
52-
public StringUnityEvent OnDictationError;
53-
54-
private bool isRecording = false;
55-
private IMixedRealityDictationSystem dictationSystem;
56-
57-
/// <summary>
58-
/// Start a recording session in the dictation system.
59-
/// </summary>
60-
public void StartRecording()
13+
public class DictationHandler : BaseInputHandler, IMixedRealityDictationHandler
6114
{
62-
if (dictationSystem != null)
15+
[SerializeField]
16+
[Tooltip("Time length in seconds before the dictation session ends due to lack of audio input in case there was no audio heard in the current session")]
17+
private float initialSilenceTimeout = 5f;
18+
19+
[SerializeField]
20+
[Tooltip("Time length in seconds before the dictation session ends due to lack of audio input.")]
21+
private float autoSilenceTimeout = 20f;
22+
23+
[SerializeField]
24+
[Tooltip("Length in seconds for the dictation service to listen")]
25+
private int recordingTime = 10;
26+
27+
[SerializeField]
28+
[Tooltip("Whether recording should start automatically on start")]
29+
private bool startRecordingOnStart = false;
30+
31+
[System.Serializable]
32+
public class StringUnityEvent : UnityEvent<string> { }
33+
34+
/// <summary>
35+
/// Event raised while the user is talking. As the recognizer listens, it provides text of what it's heard so far.
36+
/// </summary>
37+
public StringUnityEvent OnDictationHypothesis;
38+
39+
/// <summary>
40+
/// Event raised after the user pauses, typically at the end of a sentence. Contains the full recognized string so far.
41+
/// </summary>
42+
public StringUnityEvent OnDictationResult;
43+
44+
/// <summary>
45+
/// Event raised when the recognizer stops. Contains the final recognized string.
46+
/// </summary>
47+
public StringUnityEvent OnDictationComplete;
48+
49+
/// <summary>
50+
/// Event raised when an error occurs. Contains the string representation of the error reason.
51+
/// </summary>
52+
public StringUnityEvent OnDictationError;
53+
54+
private bool isRecording = false;
55+
private IMixedRealityDictationSystem dictationSystem;
56+
57+
/// <summary>
58+
/// Start a recording session in the dictation system.
59+
/// </summary>
60+
public void StartRecording()
6361
{
64-
isRecording = true;
65-
dictationSystem.StartRecording(gameObject, initialSilenceTimeout, autoSilenceTimeout, recordingTime);
62+
if (dictationSystem != null)
63+
{
64+
isRecording = true;
65+
dictationSystem.StartRecording(gameObject, initialSilenceTimeout, autoSilenceTimeout, recordingTime);
66+
}
6667
}
67-
}
6868

69-
/// <summary>
70-
/// Stop a recording session in the dictation system.
71-
/// </summary>
72-
public void StopRecording()
73-
{
74-
if (dictationSystem != null)
69+
/// <summary>
70+
/// Stop a recording session in the dictation system.
71+
/// </summary>
72+
public void StopRecording()
7573
{
76-
dictationSystem.StopRecording();
77-
isRecording = false;
74+
if (dictationSystem != null)
75+
{
76+
dictationSystem.StopRecording();
77+
isRecording = false;
78+
}
7879
}
79-
}
8080

81-
#region IMixedRealityDictationHandler implementation
81+
#region IMixedRealityDictationHandler implementation
8282

83-
void IMixedRealityDictationHandler.OnDictationHypothesis(DictationEventData eventData)
84-
{
85-
OnDictationHypothesis.Invoke(eventData.DictationResult);
86-
}
83+
void IMixedRealityDictationHandler.OnDictationHypothesis(DictationEventData eventData)
84+
{
85+
OnDictationHypothesis.Invoke(eventData.DictationResult);
86+
}
8787

88-
void IMixedRealityDictationHandler.OnDictationResult(DictationEventData eventData)
89-
{
90-
OnDictationResult.Invoke(eventData.DictationResult);
91-
}
88+
void IMixedRealityDictationHandler.OnDictationResult(DictationEventData eventData)
89+
{
90+
OnDictationResult.Invoke(eventData.DictationResult);
91+
}
9292

93-
void IMixedRealityDictationHandler.OnDictationComplete(DictationEventData eventData)
94-
{
95-
OnDictationComplete.Invoke(eventData.DictationResult);
96-
}
93+
void IMixedRealityDictationHandler.OnDictationComplete(DictationEventData eventData)
94+
{
95+
OnDictationComplete.Invoke(eventData.DictationResult);
96+
}
9797

98-
void IMixedRealityDictationHandler.OnDictationError(DictationEventData eventData)
99-
{
100-
OnDictationError.Invoke(eventData.DictationResult);
101-
}
98+
void IMixedRealityDictationHandler.OnDictationError(DictationEventData eventData)
99+
{
100+
OnDictationError.Invoke(eventData.DictationResult);
101+
}
102102

103-
#endregion IMixedRealityDictationHandler implementation
103+
#endregion IMixedRealityDictationHandler implementation
104104

105-
#region MonoBehaviour implementation
105+
#region MonoBehaviour implementation
106106

107-
protected override void Start()
108-
{
109-
base.Start();
107+
protected override void Start()
108+
{
109+
base.Start();
110110

111-
dictationSystem = MixedRealityToolkit.Instance.GetService<IMixedRealityDictationSystem>();
112-
Debug.Assert(dictationSystem != null, "No dictation system found. In order to use dictation, add a dictation system like 'Windows Dictation Input Provider' to the Data Providers in the Input System profile");
111+
dictationSystem = MixedRealityToolkit.Instance.GetService<IMixedRealityDictationSystem>();
112+
Debug.Assert(dictationSystem != null, "No dictation system found. In order to use dictation, add a dictation system like 'Windows Dictation Input Provider' to the Data Providers in the Input System profile");
113113

114-
if (startRecordingOnStart)
115-
{
116-
StartRecording();
114+
if (startRecordingOnStart)
115+
{
116+
StartRecording();
117+
}
117118
}
118-
}
119119

120-
protected override void OnDisable()
121-
{
122-
StopRecording();
120+
protected override void OnDisable()
121+
{
122+
StopRecording();
123123

124-
base.OnDisable();
125-
}
124+
base.OnDisable();
125+
}
126126

127-
#endregion MonoBehaviour implementation
128-
}
127+
#endregion MonoBehaviour implementation
128+
}
129+
}

0 commit comments

Comments
 (0)