Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update System.Speech to also recognize Speech_OneCore #110123

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ protected ObjectTokenCategory(string keyId, RegistryDataKey key)
internal static ObjectTokenCategory Create(string sCategoryId)
{
RegistryDataKey key = RegistryDataKey.Open(sCategoryId, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this doesn't throw if the key isn't there -- it ends up calling into the COM interface so I guess that's the case

return new ObjectTokenCategory(sCategoryId, key);
if (key != null)
{
return new ObjectTokenCategory(sCategoryId, key);
}

return null;
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ internal static int DefaultDeviceOut()
#endregion

private const string SpeechRegistryKey = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\";
private const string SpeechOneCoreRegistryKey = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\";

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

#region internal Fields

internal const string Recognizers = SpeechRegistryKey + "Recognizers";
internal const string Voices = SpeechRegistryKey + "Voices";
internal const string Voices_OneCore = SpeechOneCoreRegistryKey + "Voices";

internal const string AudioIn = SpeechRegistryKey + "AudioInput";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1480,20 +1480,25 @@ private static List<InstalledVoice> BuildInstalledVoices(VoiceSynthesis voiceSyn
{
List<InstalledVoice> voices = new();

using (ObjectTokenCategory category = ObjectTokenCategory.Create(SAPICategories.Voices))
ReadOnlySpan<string> categoryIds = [SAPICategories.Voices, SAPICategories.Voices_OneCore];
foreach (string categoryId in categoryIds)
{
if (category != null)
using (ObjectTokenCategory category = ObjectTokenCategory.Create(categoryId))
{
// Build a list with all the voicesInfo
foreach (ObjectToken voiceToken in category.FindMatchingTokens(null, null))
if (category != null)
{
if (voiceToken != null && voiceToken.Attributes != null)
// Build a list with all the voicesInfo
foreach (ObjectToken voiceToken in category.FindMatchingTokens(null, null))
{
voices.Add(new InstalledVoice(voiceSynthesizer, new VoiceInfo(voiceToken)));
if (voiceToken != null && voiceToken.Attributes != null)
{
voices.Add(new InstalledVoice(voiceSynthesizer, new VoiceInfo(voiceToken)));
}
}
}
}
}

return voices;
}

Expand Down
Loading