views:

1029

answers:

3

Hi,

I think what I am about to want might be easy for you,so I decided to ask it to you,

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

Could you help me ?

Thanks.

+2  A: 

This is from a few moments' play, so caveat emptor. Worked well for me. I did notice that SpFileStream (which doesn't implement IDisposable, thus the try/finally) prefers absolute paths to relative. C#.

   SpFileStream fs = null;
    try
    {
        SpVoice voice = new SpVoice();
        fs = new SpFileStream();
        fs.Open(@"c:\hello.wav", SpeechStreamFileMode.SSFMCreateForWrite, false);
        voice.AudioOutputStream = fs;
        voice.Speak("Hello world.", SpeechVoiceSpeakFlags.SVSFDefault);
    }
    finally
    {
        if (fs != null)
        {
         fs.Close();
        }
    }
Michael Petrotta
Thanks for you effort.
Braveyard
+4  A: 

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.

Mackenzie
Hi, before that I need to import some dll, because System.Speech is not available in my project even though I added by using "using System.Speech".
Braveyard
@Mackenzie: this is a better answer than mine, as it uses .net native classes rather than mucking around with COM.
Michael Petrotta
@atarikg: Reference the System.Speech assembly.
Michael Petrotta
Hi, Thanks for every thing, I handled the latest question of mine and it works charmingly right now.
Braveyard
+1  A: 

And as I've found for how to change output format, we code something like this :

SpeechAudioFormatInfo info = new SpeechAudioFormatInfo(6, AudioBitsPerSample.Sixteen, AudioChannel.Mono);

//Same code comes here 

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

That's pretty easy and comprehensible.

Cool .net

Braveyard