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

Tarik picture Tarik · Jun 8, 2009 · Viewed 9.8k times · Source

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

Answer

Mackenzie picture Mackenzie · Jun 8, 2009

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.