Skip to content

Commit aebeca0

Browse files
Refactored to make initial silence timeout, auto silence timeout, and recording length based on passed parameters.
Fixed issue with text not clearing properly after result/completetion.
1 parent 7486ca5 commit aebeca0

File tree

3 files changed

+46
-98
lines changed

3 files changed

+46
-98
lines changed

Assets/HoloToolkit-Tests/Input/Scenes/DictationTest.unity

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ OcclusionCullingSettings:
1313
--- !u!104 &2
1414
RenderSettings:
1515
m_ObjectHideFlags: 0
16-
serializedVersion: 7
16+
serializedVersion: 8
1717
m_Fog: 0
1818
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
1919
m_FogMode: 3
@@ -25,6 +25,7 @@ RenderSettings:
2525
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
2626
m_AmbientIntensity: 1
2727
m_AmbientMode: 0
28+
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
2829
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
2930
m_HaloStrength: 0.5
3031
m_FlareStrength: 1
@@ -41,7 +42,7 @@ RenderSettings:
4142
--- !u!157 &3
4243
LightmapSettings:
4344
m_ObjectHideFlags: 0
44-
serializedVersion: 7
45+
serializedVersion: 9
4546
m_GIWorkflowMode: 1
4647
m_GISettings:
4748
serializedVersion: 2
@@ -53,7 +54,7 @@ LightmapSettings:
5354
m_EnableBakedLightmaps: 1
5455
m_EnableRealtimeLightmaps: 1
5556
m_LightmapEditorSettings:
56-
serializedVersion: 4
57+
serializedVersion: 8
5758
m_Resolution: 2
5859
m_BakeResolution: 40
5960
m_TextureWidth: 1024
@@ -66,13 +67,27 @@ LightmapSettings:
6667
m_LightmapParameters: {fileID: 0}
6768
m_LightmapsBakeMode: 1
6869
m_TextureCompression: 1
69-
m_DirectLightInLightProbes: 1
7070
m_FinalGather: 0
7171
m_FinalGatherFiltering: 1
7272
m_FinalGatherRayCount: 256
7373
m_ReflectionCompression: 2
74+
m_MixedBakeMode: 1
75+
m_BakeBackend: 0
76+
m_PVRSampling: 1
77+
m_PVRDirectSampleCount: 32
78+
m_PVRSampleCount: 500
79+
m_PVRBounces: 2
80+
m_PVRFiltering: 0
81+
m_PVRFilteringMode: 1
82+
m_PVRCulling: 1
83+
m_PVRFilteringGaussRadiusDirect: 1
84+
m_PVRFilteringGaussRadiusIndirect: 5
85+
m_PVRFilteringGaussRadiusAO: 2
86+
m_PVRFilteringAtrousColorSigma: 1
87+
m_PVRFilteringAtrousNormalSigma: 1
88+
m_PVRFilteringAtrousPositionSigma: 1
7489
m_LightingDataAsset: {fileID: 0}
75-
m_RuntimeCPUUsage: 25
90+
m_ShadowMaskMode: 2
7691
--- !u!196 &4
7792
NavMeshSettings:
7893
serializedVersion: 2
@@ -89,6 +104,8 @@ NavMeshSettings:
89104
minRegionArea: 2
90105
manualCellSize: 0
91106
cellSize: 0.16666667
107+
manualTileSize: 0
108+
tileSize: 256
92109
accuratePlacement: 0
93110
m_NavMeshData: {fileID: 0}
94111
--- !u!1001 &87622386
@@ -128,7 +145,7 @@ Prefab:
128145
objectReference: {fileID: 0}
129146
- target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2}
130147
propertyPath: m_RootOrder
131-
value: 1
148+
value: 2
132149
objectReference: {fileID: 0}
133150
m_RemovedComponents: []
134151
m_ParentPrefab: {fileID: 100100000, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2}
@@ -244,7 +261,7 @@ Transform:
244261
- {fileID: 666238358}
245262
- {fileID: 281442315}
246263
m_Father: {fileID: 0}
247-
m_RootOrder: 2
264+
m_RootOrder: 1
248265
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
249266
--- !u!1001 &630439407
250267
Prefab:
@@ -283,7 +300,7 @@ Prefab:
283300
objectReference: {fileID: 0}
284301
- target: {fileID: 4000011792100794, guid: a611e772ef8ddf64d8106a9cbb70f31c, type: 2}
285302
propertyPath: m_RootOrder
286-
value: 0
303+
value: 3
287304
objectReference: {fileID: 0}
288305
m_RemovedComponents: []
289306
m_ParentPrefab: {fileID: 100100000, guid: a611e772ef8ddf64d8106a9cbb70f31c, type: 2}
@@ -341,7 +358,7 @@ GameObject:
341358
- component: {fileID: 1385361781}
342359
- component: {fileID: 1385361780}
343360
m_Layer: 0
344-
m_Name: Directional light
361+
m_Name: DirectionalLight
345362
m_TagString: Untagged
346363
m_Icon: {fileID: 0}
347364
m_NavMeshLayer: 0
@@ -354,7 +371,7 @@ Light:
354371
m_PrefabInternal: {fileID: 0}
355372
m_GameObject: {fileID: 1385361779}
356373
m_Enabled: 1
357-
serializedVersion: 7
374+
serializedVersion: 8
358375
m_Type: 1
359376
m_Color: {r: 1, g: 1, b: 1, a: 1}
360377
m_Intensity: 1
@@ -379,6 +396,8 @@ Light:
379396
m_Lightmapping: 4
380397
m_AreaSize: {x: 1, y: 1}
381398
m_BounceIntensity: 1
399+
m_ColorTemperature: 6570
400+
m_UseColorTemperature: 0
382401
m_ShadowRadius: 0
383402
m_ShadowAngle: 0
384403
--- !u!4 &1385361781
@@ -392,7 +411,7 @@ Transform:
392411
m_LocalScale: {x: 1, y: 1, z: 1}
393412
m_Children: []
394413
m_Father: {fileID: 0}
395-
m_RootOrder: 3
414+
m_RootOrder: 0
396415
m_LocalEulerAnglesHint: {x: 50, y: 0, z: 0}
397416
--- !u!1001 &1487781069
398417
Prefab:

Assets/HoloToolkit-Tests/Input/Scripts/DictationRecordButton.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ public class DictationRecordButton : MonoBehaviour, IInputClickHandler, IDictati
3535
private void Awake()
3636
{
3737
buttonRenderer = GetComponent<Renderer>();
38-
DictationInputManager.InitialSilenceTimeout = initialSilenceTimeout;
39-
DictationInputManager.AutoSilenceTimeout = autoSilenceTimeout;
40-
DictationInputManager.RecordingTime = recordingTime;
4138
}
4239

4340
public void OnInputClicked(InputClickedEventData eventData)
@@ -58,7 +55,7 @@ private void ToggleRecording()
5855
else
5956
{
6057
isRecording = true;
61-
StartCoroutine(DictationInputManager.StartRecording());
58+
StartCoroutine(DictationInputManager.StartRecording(initialSilenceTimeout, autoSilenceTimeout, recordingTime));
6259
speechToTextOutput.color = Color.green;
6360
recordLight.SetActive(true);
6461
buttonRenderer.enabled = false;

Assets/HoloToolkit/Input/Scripts/Microphone/DictationInputManager.cs

Lines changed: 15 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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;
54
using System.Collections;
65
using System.Text;
76
using UnityEngine;
@@ -15,82 +14,6 @@ namespace HoloToolkit.Unity.InputModule
1514
/// </summary>
1615
public class DictationInputManager : Singleton<DictationInputManager>, IInputSource
1716
{
18-
/// <summary>
19-
/// Initial value for InitialSilenceTimeout.
20-
/// </summary>
21-
private static float initialSilenceTimeout = 5f;
22-
23-
/// <summary>
24-
/// The time length in seconds before dictation recognizer session ends due to lack of audio input in case there was no audio heard in the current session.
25-
/// </summary>
26-
public static float InitialSilenceTimeout
27-
{
28-
get
29-
{
30-
return dictationRecognizer != null ? dictationRecognizer.InitialSilenceTimeoutSeconds : initialSilenceTimeout;
31-
}
32-
set
33-
{
34-
if (value <= 0) throw new ArgumentOutOfRangeException("value");
35-
36-
initialSilenceTimeout = value;
37-
38-
if (dictationRecognizer != null)
39-
{
40-
dictationRecognizer.InitialSilenceTimeoutSeconds = initialSilenceTimeout;
41-
}
42-
}
43-
}
44-
45-
/// <summary>
46-
/// Initial value for AutoSilenceTimeout.
47-
/// </summary>
48-
private static float autoSilenceTimeout = 20f;
49-
50-
/// <summary>
51-
/// The time length in seconds before dictation recognizer session ends due to lack of audio input.
52-
/// </summary>
53-
public static float AutoSilenceTimeout
54-
{
55-
get
56-
{
57-
return dictationRecognizer != null ? dictationRecognizer.AutoSilenceTimeoutSeconds : autoSilenceTimeout;
58-
}
59-
set
60-
{
61-
if (value <= 0) throw new ArgumentOutOfRangeException("value");
62-
63-
autoSilenceTimeout = value;
64-
65-
if (dictationRecognizer != null)
66-
{
67-
dictationRecognizer.AutoSilenceTimeoutSeconds = autoSilenceTimeout;
68-
}
69-
}
70-
}
71-
72-
/// <summary>
73-
/// Initial value for RecordingTime.
74-
/// </summary>
75-
private static int recordingTime = 10;
76-
77-
/// <summary>
78-
/// Length in seconds for the manager to listen.
79-
/// </summary>
80-
public static int RecordingTime
81-
{
82-
get
83-
{
84-
return recordingTime;
85-
}
86-
set
87-
{
88-
if (value <= 0) throw new ArgumentOutOfRangeException("value");
89-
90-
recordingTime = value;
91-
}
92-
}
93-
9417
/// <summary>
9518
/// Caches the text currently being displayed in dictation display text.
9619
/// </summary>
@@ -143,12 +66,9 @@ protected override void Awake()
14366
// Query the maximum frequency of the default microphone.
14467
int minSamplingRate; // Unsued.
14568
Microphone.GetDeviceCaps(DeviceName, out minSamplingRate, out samplingRate);
146-
147-
// Use this string to cache the text currently displayed.
148-
textSoFar = new StringBuilder();
14969
}
15070

151-
private void Update()
71+
private void LateUpdate()
15272
{
15373
if (IsListening && !Microphone.IsRecording(DeviceName) && dictationRecognizer.Status == SpeechSystemStatus.Running)
15474
{
@@ -175,7 +95,11 @@ protected override void OnDestroy()
17595
/// <summary>
17696
/// Turns on the dictation recognizer and begins recording audio from the default microphone.
17797
/// </summary>
178-
public static IEnumerator StartRecording()
98+
/// <param name="initialSilenceTimeout">The time length in seconds before dictation recognizer session ends due to lack of audio input in case there was no audio heard in the current session.</param>
99+
/// <param name="autoSilenceTimeout">The time length in seconds before dictation recognizer session ends due to lack of audio input.</param>
100+
/// <param name="recordingTime">Length in seconds for the manager to listen.</param>
101+
/// <returns></returns>
102+
public static IEnumerator StartRecording(float initialSilenceTimeout = 5f, float autoSilenceTimeout = 20f, int recordingTime = 10)
179103
{
180104
if (IsListening) { yield break; }
181105

@@ -191,6 +115,8 @@ public static IEnumerator StartRecording()
191115
yield return null;
192116
}
193117

118+
dictationRecognizer.InitialSilenceTimeoutSeconds = initialSilenceTimeout;
119+
dictationRecognizer.AutoSilenceTimeoutSeconds = autoSilenceTimeout;
194120
dictationRecognizer.Start();
195121

196122
while (dictationRecognizer.Status == SpeechSystemStatus.Failed)
@@ -205,8 +131,10 @@ public static IEnumerator StartRecording()
205131
}
206132

207133
// Start recording from the microphone.
208-
dictationAudioClip = Microphone.Start(DeviceName, false, RecordingTime, samplingRate);
134+
dictationAudioClip = Microphone.Start(DeviceName, false, recordingTime, samplingRate);
209135

136+
// Use this string to cache the text currently displayed.
137+
textSoFar = new StringBuilder();
210138
}
211139

212140
/// <summary>
@@ -277,6 +205,8 @@ private static void DictationRecognizer_DictationComplete(DictationCompletionCau
277205
}
278206

279207
InputManager.Instance.RaiseDictationComplete(Instance, 0, dictationResult, dictationAudioClip);
208+
textSoFar = null;
209+
dictationResult = string.Empty;
280210
}
281211

282212
/// <summary>
@@ -289,6 +219,8 @@ private static void DictationRecognizer_DictationError(string error, int hresult
289219
dictationResult = error + "\nHRESULT: " + hresult.ToString();
290220

291221
InputManager.Instance.RaiseDictationError(Instance, 0, dictationResult);
222+
textSoFar = null;
223+
dictationResult = string.Empty;
292224
}
293225

294226
#endregion // Dictation Recognizer Callbacks

0 commit comments

Comments
 (0)