views:

248

answers:

1

My C# application needs to covert text to wav file and inject it into a Skype call. The code that creates the wav file is below. The problem is that the file has 22kHz sample rate and Skype accepts only 16kHz.

Is there any way to adjust this setting?

using (System.IO.FileStream stream = System.IO.File.Create("message.wav"))
{

System.Speech.Synthesis.SpeechSynthesizer speechEngine = new System.Speech.Synthesis.SpeechSynthesizer();

 speechEngine.SetOutputToWaveStream(stream);
 speechEngine.Speak(number);
 stream.Flush();
}
+3  A: 

SetOutputToWaveFile() has an overload that accepts a SpeechAudioFormatInfo parameter, which can be used to set the sample rate. Don't see one for SetOutputToWaveStream(), oddly, but since you're writing to a file anyway, that should work.

Edit:

As @Hans points out, the correct overload is SetOutputToAudioStream() to write to a stream.

Tanzelax
SetOutputToAudioStream() is the alternative.
Hans Passant
@Hans, Ahh, I see. Odd that they weren't consistent in their naming... `SetOutputToAudioFile()` for non-wave format, or an overloaded `SetOutputToWaveStream()`. Updated answer. :)
Tanzelax
Perfect solution. I have my wav files in just the right format!
Adrian