开发者

How to compress speech stream in silverlight

开发者 https://www.devze.com 2023-01-29 11:08 出处:网络
I have recorded audio using silverligh4 and trying to save it through service on the server. The problem is recorded .WAV file has lakhs ofbytes of data as stream. But when this stream is passed to se

I have recorded audio using silverligh4 and trying to save it through service on the server. The problem is recorded .WAV file has lakhs ofbytes of data as stream. But when this stream is passed to service its getting transmitted as 1526 bytes max only. I have set max properties in web.config. I think we need to encode the stream on the client and pass this encoded stream and decode it on 开发者_JAVA技巧the server. How to encode the audio stream on sileverlight application and decode it on the server? Please advice me. Thanks for your time. Nspeex or CSpeex do not work for me. If any one has implemented the same please suggest how to do it?


The only way to compress WAV to any reasonable size (without trading quality) is to convert it to another format.

I don't know if this is an option for you but it would be very easy to use lame.exe to convert to MP3 before sending to the server. Of course you'd need to make sure that licensing allows you to distribute with your application.

Here is an open source program to convert MP3 to WAV: http://www.codeproject.com/KB/audio-video/madlldlib.aspx

Something like this to convert to MP3, you might be able to convert MP3 to WAV with lame also using the --decompress option.

using System.Diagnostics;

public string WAV2MP3(string fileName, bool waitFlag) {

    string newFileName = fullpathDir + fileName.Replace(".wav",".mp3");
    string lameArgs = "-b 32 --resample 22.05 -m m \"" + 
        fullpathDir + fileName + "\" \"" + 
        newFileName + "\"";

    ProcessStartInfo processInfo = new ProcessStartInfo();

    Arguments = lameArgs;
    WindowStyle = ProcessWindowStyle.Hidden;
    WorkingDirectory = Application.StartupPath;

    Process startedProcess = new Process.Start(processInfo);

    if (waitFlag) {
      startedProcess.WaitForExit();
    }
    return newFileName;

};


I'd probably just take the raw audio stream, sample it at a low rate, and send it out via a compressed stream. If you wanted to get fancy, you could farm the compression out to an MP3 encoder like LAME (in a separate thread/process!).

0

精彩评论

暂无评论...
验证码 换一张
取 消