views:

276

answers:

4

I wrote a little application that takes in some text and converts it to an audio wav. now, it works fine except that the wav file produced is too big.

I'm looking on ways to make the wav output smaller and make the whole process take less time.

Sample Code :

 public byte[] ConvertText2Wav(string text)
    {
        MemoryStream wavAudioStream = new MemoryStream();            
        SpeechSynthesizer speechEngine = new SpeechSynthesizer();
        speechEngine.SetOutputToWaveStream(wavAudioStream);
        speechEngine.Speak(text);
        wavAudioStream.Flush();
        Byte[] wavBytes = wavAudioStream.GetBuffer();
        return wavBytes;  
    }
+4  A: 

.wav output is uncompressed.

If you want "smaller" output, use an appropriate codec and compress it.

Anon.
plz, could you please explain some more ?
Attilah
Your .wav output will always be (comparatively) huge. That's because it's the raw sound values with no compression. What you want to do is, once you've got that raw sound, run it through an encoder to cut down the file size. FLAC is good for lossless audio, but if you don't need perfect precision you'll generally get better compression with a lossy codec.
Anon.
thanks. Oh and is there a way to make the process of converting the text to wav a little bit faster ? have a look at the code in the question.
Attilah
Run a profiler over the code. That will identify the slowest thing. It's very difficult to guess what the slowest thing is just by reading code; use a tool to help you.
Eric Lippert
A: 

Wave files are long per se. You should pass it through a codec as XVID for movies or MP3 or OGG for audio for example.

Take a look at this tutorial on how to use DirectShow

Jorge Córdoba
+1  A: 

You can use the LAME MP3 encoder to convert the WAV output to MP3. This will result in a smaller output file like Anon says.

http://lame.sourceforge.net/

Jan Jongboom
+1  A: 

You should use a compression codec that is built specifically for speech to get the greatest possible benefit. Speex is free and excellent. You can use it from c# like this: http://www.codeproject.com/KB/cs/speexincsharp.aspx.

That will yield better results than a general purpose or music codec would.

Clay Fowler