Search code examples
c#speech

how i can change language on System.Speech.Synthesis?


I write Code and i use on it "System.Speech.Synthesis" library but its on default only English So How i can change it to French or other languages ??

This Part of my Code :

class Program
{
    static void Main(string[] args)
    {
       using (SpeechSynthesizer synth = new SpeechSynthesizer()) {  synth.Speak("Welcome To Calcualtor"); }
}

     }

i Search on internet how change it but i dont know much about c# this whats i found

so i appreciate any help or suggestions from you guys and thanks already.


Solution

  • You can select a pre-installed voice that will speak in you chosen language.

    I'm almost sure that the default language of your computer/server will be used if you don't select any voice.

    using (SpeechSynthesizer synthesizer = new SpeechSynthesizer())
    {
        synthesizer.SetOutputToDefaultAudioDevice();
    
        // this
        synthesizer.SelectVoice("ScanSoft Virginie_Dri40_16kHz");
    
        // or this
        synthesizer.SelectVoiceByHints(VoiceGender.Neutral, VoiceAge.NotSet, 0, CultureInfo.GetCultureInfo("fr-fr"));
    
        synthesizer.Speak("Bonjour !");
    }