Question

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;  
    }
Was it helpful?

Solution

.wav output is uncompressed.

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

OTHER TIPS

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/

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top