Skip to content

Commit c6993dd

Browse files
author
Alex Cooper (ANALOG)
committed
Helper methods to determine if speech is active and supported
1 parent a0fc18f commit c6993dd

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

Assets/MixedRealityToolkit/_Core/Definitions/InputSystem/MixedRealityInputSystemProfile.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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.Globalization;
5+
using System.Collections.Generic;
46
using Microsoft.MixedReality.Toolkit.Core.Definitions.Devices;
57
using Microsoft.MixedReality.Toolkit.Core.Definitions.Utilities;
68
using Microsoft.MixedReality.Toolkit.Core.Interfaces.Devices;
@@ -74,6 +76,24 @@ public MixedRealityPointerProfile PointerProfile
7476
/// </summary>
7577
public IMixedRealitySpeechSystem SpeechSystem => speechSystem ?? (speechSystem = MixedRealityToolkit.Instance.GetService<IMixedRealitySpeechSystem>());
7678

79+
80+
/// <summary>
81+
/// The list of cultures where speech recognition is supported. Cultures added as needed
82+
/// </summary>
83+
private List<CultureInfo> supportedVoiceCultures = new List<CultureInfo>
84+
{
85+
new CultureInfo("en-US")
86+
};
87+
88+
/// <summary>
89+
/// REturns whether speech is supported for the current language/culture or not
90+
/// </summary>
91+
public bool IsSpeechSupported
92+
{
93+
// Use UI Culture instead of just culture since that will match the current display lang/culture
94+
get { return supportedVoiceCultures.Contains(CultureInfo.CurrentUICulture); }
95+
}
96+
7797
/// <summary>
7898
/// Is the speech Commands Enabled?
7999
/// </summary>

Assets/MixedRealityToolkit/_Core/Devices/VoiceInput/WindowsSpeechInputDeviceManager.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,16 @@ public WindowsSpeechInputDeviceManager(string name, uint priority) : base(name,
3030
/// </summary>
3131
public IMixedRealityInputSource InputSource = null;
3232

33-
3433
private KeywordRecognizer keywordRecognizer;
3534

35+
/// <summary>
36+
/// Query whether or not the speech system is active
37+
/// </summary>
38+
public bool IsRecognitionActive
39+
{
40+
get { return keywordRecognizer != null && keywordRecognizer.IsRunning; }
41+
}
42+
3643
public RecognitionConfidenceLevel RecognitionConfidenceLevel { get; set; }
3744

3845
/// <inheritdoc />
@@ -127,4 +134,4 @@ private void OnPhraseRecognized(ConfidenceLevel confidence, TimeSpan phraseDurat
127134
}
128135
}
129136
#endif // UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN
130-
}
137+
}

Assets/MixedRealityToolkit/_Core/Interfaces/Devices/IMixedRealitySpeechSystem.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ namespace Microsoft.MixedReality.Toolkit.Core.Interfaces.Devices
88
/// </summary>
99
public interface IMixedRealitySpeechSystem : IMixedRealityDeviceManager, IMixedRealityExtensionService
1010
{
11+
/// <summary>
12+
/// Query whether or not the speech system is active
13+
/// </summary>
14+
bool IsRecognitionActive { get; }
15+
1116
/// <summary>
1217
/// Make sure the keyword recognizer is on, then stop it.
1318
/// Otherwise, leave it alone because it's already in the desired state.
@@ -20,4 +25,4 @@ public interface IMixedRealitySpeechSystem : IMixedRealityDeviceManager, IMixedR
2025
/// </summary>
2126
void StopRecognition();
2227
}
23-
}
28+
}

0 commit comments

Comments
 (0)