Click here to Skip to main content
16,021,125 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello. I want to save the text-to-speech as a WAV file, right after it is being played.

SpeechSynthesizer ss = new SpeechSynthesizer();
SpeechAudioFormatInfo info = new SpeechAudioFormatInfo(8, AudioBitsPerSample.Sixteen, AudioChannel.Mono);

SpVoice voice = new SpeechLib.SpVoice();

ss.Volume = 100; //set the volume of voice (100 is highest)
ss.Rate = 3; //set how fast the speaker speaks 

voice.Speak("Hello there. How are you?", SpeechVoiceSpeakFlags.SVSFlagsAsync);

ss.SetOutputToWaveFile(@"C:\Sound\HelpSound.wav", info);


That's what I have. Yes, there is HelpSound.wav file in my C after that. However, the size of the file is 0 byte. When I click, it's not playing anything.
Does anybody have any idea?

Thanks.
Posted
Updated 18-Nov-10 18:05pm
v2

1 solution

Code bellow is given in the sample.
SpeechStreamFileMode SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite;
            SpFileStream SpFileStream = new SpFileStream();
            SpFileStream.Open(@"C:\test.wav", SpFileMode, false);
            voice.AudioOutputStream = SpFileStream;
            voice.Speak(textBox1.Text.Trim(), flag);
            voice.WaitUntilDone(Timeout.Infinite);//Using System.Threading;
            SpFileStream.Close()
 
Share this answer
 
Comments
Little Daffodil 19-Nov-10 0:46am    
It worked!

Thanks a lot, Alegria_Lee.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900