iTranslated by AI
Using Custom Synthetic Voices in .NET MAUI on Windows
Prerequisites
I want to be able to hear the cute voices of VOICEVOX!
Implementation-wise, I thought "I want to hear synthesized voices newly added via SAPIForVOICEVOX on Windows with MAUI!" and started working on it.
Please make sure to install VOICEVOX and SAPIForVOICEVOX beforehand.
By the way, as you might expect, this only works on Windows, so please apply platform restrictions when implementing it.
Conclusion
Impossible with default MAUI TextToSpeech
Basically, it's related to the recent state of synthesized voices on Windows. SAPIForVOICEVOX, as the name suggests, adds voices to SAPI, which is classified as a legacy feature in Windows. However, recent versions of Windows follow the policy of using UWP (Windows.Media.SpeechSynthesis). Since MAUI also uses UWP (Windows.Media.SpeechSynthesis) for that reason, it's not possible.
By the way, here is the content of TextToSpeech in the default MAUI...
Use System.Speech.Synthesis
It was explained very, very thoroughly.
Note that System.Speech.Synthesis has no particular dependencies, so you can use it with peace of mind.
Install System.Speech via NuGet.
For this test, I wanted to verify if various voices were included, so I wrote the following:
SpeechSynthesizer synth = new SpeechSynthesizer();
synth.SetOutputToDefaultAudioDevice();
foreach(InstalledVoice item in synth.GetInstalledVoices()){
synth.SelectVoice(item.VoiceInfo.Name);
synth.Speak(item.VoiceInfo.Name);
}
That's all. In this case, since I am using the Speak function, it runs synchronously, but by utilizing SpeakAsync and events, you can also use it properly in an asynchronous manner.
Discussion