C# Save text to speech to MP3 file

CodeMonkeyAlx picture CodeMonkeyAlx · Apr 15, 2013 · Viewed 13k times · Source

I am wondering if there is a way to save text to speech data to an mp3 or Wav file format to be played back at a later time?

SpeechSynthesizer reader = new SpeechSynthesizer();
reader.Rate = (int)-2;
reader.Speak("Hello this is an example expression from the computers TTS engine in C-Sharp);

I am trying to get that saved externally so I can play it back later. What is the best way to do this?

Answer

keyboardP picture keyboardP · Apr 15, 2013

There are multiple options such as saving to an existing stream. If you want to create a new WAV file, you can use the SetOutputToWaveFile method.

reader.SetOutputToWaveFile(@"C:\MyWavFile.wav");