Search code examples
c#text-to-speechsapi

How to save text-to-speech as a wav with Microsoft SAPI?


I need to turn a text into speech and then save it as wav file.


Solution

  • The following C# code uses the System.Speech namespace in the .Net framework. It is necessary to reference the namespace before using it, because it is not automatically referenced by Visual Studio.

            SpeechSynthesizer ss = new SpeechSynthesizer();
            ss.Volume = 100;
            ss.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult);
            ss.SetOutputToWaveFile(@"C:\MyAudioFile.wav");
            ss.Speak("Hello World");
    

    I hope this is relevant and helpful.