nAudio WAV to MP3 muLaw error -
i grabbing wav file (successfully) via web service , able play on windows 7 machine. need grab same wav file , convert mp3 file. failing. have tried retrieving file wav (above) using --
wavestream pcmstream = waveformatconversionstream.createpcmstream(reader);
to convert mulaw pcm.
this failing attached error. have tried converting directly using lamemp3filewriter fails telling me "mulaw format cannot converted mp3.
what missing? coder snippet private void writemp3(string inum, string callid) { //construct replay url using inum string url = "http://" + _verintserver + "/searchapi?command=replay&id=" + inum;
// name new mp3 file string mp3file =_basepath + "mp3\\" + callid + ".mp3"; string tempwav = _basepath + "mp3\\" + callid + ".wav"; string temppcm = _basepath + "mp3\\" + callid + "_pcm.wav"; //issue web service request httpwebrequest request = (httpwebrequest)system.net.webrequest.create(url); //retrieve content type raw pcm (.wav) request.contenttype = "audio/wav"; //encode , include basic authentication credentials string encoded = system.convert.tobase64string(system.text.encoding.getencoding("iso-8859-1").getbytes(_username + ":" + _password)); request.headers.add("authorization", "basic " + encoded); //retrieve response httpwebresponse response = (system.net.httpwebresponse)request.getresponse(); //copy stream of bytes local directory using callid file name if (request.haveresponse) { //create temporary wav file using (var receivestream = response.getresponsestream()) { using (var pstream = new filestream(tempwav, filemode.create,fileaccess.write)) { receivestream.copyto(pstream); } } wavetopcm(tempwav, temppcm); wavetomp3(temppcm, mp3file, 128); } return; } //convert mulaw wav pcm private void wavetopcm(string wavefilename, string pcmfilename) { using (var reader = new cuewavefilereader(wavefilename)) { wavestream pcmstream = waveformatconversionstream.createpcmstream(reader); using (var pstream = new filestream(pcmfilename, filemode.create, fileaccess.write)) { pcmstream.copyto(pstream); } } return; } // convert wav mp3 using libmp3lame library public void wavetomp3(string wavefilename, string mp3filename, int bitrate = 128) { using (var reader = new wavefilereader(wavefilename)) using (var writer = new lamemp3filewriter(mp3filename, reader.waveformat, bitrate)) reader.copyto(writer); }
stack trace: {"$id":"1","message":"an error has occurred.","exceptionmessage":"not wave file - no riff header","exceptiontype":"system.formatexception","stacktrace":" @ naudio.fileformats.wav.wavefilechunkreader.readriffheader(binaryreader br)\r\n @ naudio.fileformats.wav.wavefilechunkreader.readwaveheader(stream stream)\r\n @ naudio.wave.wavefilereader..ctor(stream inputstream)\r\n @ naudio.wave.wavefilereader..ctor(string wavefile)\r\n @ dataservices.controllers.recordingscontroller.wavetomp3(string wavefilename, string mp3filename, int32 bitrate) in c:\codebank\dataaccess\dataservices\controllers\recordingscontroller.cs:line 179\r\n @ dataservices.controllers.recordingscontroller.writemp3(string inum,
in wavetopcm
function writing raw samples file. need use wavefilewriter.createwavefile
passing in pcmstream
make 16 bit pcm wav file can pass lame mp3 writer
Comments
Post a Comment