Skip to content

Commit 38366f0

Browse files
authored
Update System.Speech to also recognize Speech_OneCore (#110123)
1 parent 2979d1b commit 38366f0

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/libraries/System.Speech/src/Internal/ObjectToken/ObjectTokenCategory.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ protected ObjectTokenCategory(string keyId, RegistryDataKey key)
2121
internal static ObjectTokenCategory Create(string sCategoryId)
2222
{
2323
RegistryDataKey key = RegistryDataKey.Open(sCategoryId, true);
24-
return new ObjectTokenCategory(sCategoryId, key);
24+
if (key != null)
25+
{
26+
return new ObjectTokenCategory(sCategoryId, key);
27+
}
28+
29+
return null;
2530
}
2631

2732
#endregion

src/libraries/System.Speech/src/Internal/ObjectToken/SAPICategories.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,15 @@ internal static int DefaultDeviceOut()
5959
#endregion
6060

6161
private const string SpeechRegistryKey = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\";
62+
private const string SpeechOneCoreRegistryKey = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\";
6263

6364
internal const string CurrentUserVoices = @"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Speech\Voices";
6465

6566
#region internal Fields
6667

6768
internal const string Recognizers = SpeechRegistryKey + "Recognizers";
6869
internal const string Voices = SpeechRegistryKey + "Voices";
70+
internal const string Voices_OneCore = SpeechOneCoreRegistryKey + "Voices";
6971

7072
internal const string AudioIn = SpeechRegistryKey + "AudioInput";
7173

src/libraries/System.Speech/src/Internal/Synthesis/VoiceSynthesis.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,20 +1480,25 @@ private static List<InstalledVoice> BuildInstalledVoices(VoiceSynthesis voiceSyn
14801480
{
14811481
List<InstalledVoice> voices = new();
14821482

1483-
using (ObjectTokenCategory category = ObjectTokenCategory.Create(SAPICategories.Voices))
1483+
ReadOnlySpan<string> categoryIds = [SAPICategories.Voices, SAPICategories.Voices_OneCore];
1484+
foreach (string categoryId in categoryIds)
14841485
{
1485-
if (category != null)
1486+
using (ObjectTokenCategory category = ObjectTokenCategory.Create(categoryId))
14861487
{
1487-
// Build a list with all the voicesInfo
1488-
foreach (ObjectToken voiceToken in category.FindMatchingTokens(null, null))
1488+
if (category != null)
14891489
{
1490-
if (voiceToken != null && voiceToken.Attributes != null)
1490+
// Build a list with all the voicesInfo
1491+
foreach (ObjectToken voiceToken in category.FindMatchingTokens(null, null))
14911492
{
1492-
voices.Add(new InstalledVoice(voiceSynthesizer, new VoiceInfo(voiceToken)));
1493+
if (voiceToken != null && voiceToken.Attributes != null)
1494+
{
1495+
voices.Add(new InstalledVoice(voiceSynthesizer, new VoiceInfo(voiceToken)));
1496+
}
14931497
}
14941498
}
14951499
}
14961500
}
1501+
14971502
return voices;
14981503
}
14991504

0 commit comments

Comments
 (0)