c# - How to change .wav format audio file bitrate -
in application have .wav format audio files, here check audio file bit rates using naudio dll, if bitrate below 128kbps want change above 128kpbs, wrote below code check bit rate, if less 128kbps convert above 128kbps.
int bitrate; using (var reader = new wavefilereader(textbox1.text)) { bitrate = reader.waveformat.averagebytespersecond * 8; reader.dispose(); } if (bitrate < 128000) { using (var reader = new wavefilereader(textbox1.text)) { var newformat = new waveformat(8000, 16, 1); using (var conversionstream = new waveformatconversionstream(newformat, reader)) { wavefilewriter.createwavefile(@"c:\docs\files\", conversionstream); } } }
for files working fine, files getting below error,
an unhandled exception of type 'naudio.mmexception' occurred in naudio.dll additional information: acmnotpossible calling acmstreamopen
i attaching error snap here. error error snap here, how can slove issue?
i suggest take @ ffmpeg. use audio/video conversion tasks.
it command-line tool can convert pretty anything, lots of options. want, need run like:
$ ffmpeg -i input.wav -ab 128 output.wav
in above line, convert file 128 bitrate.
easiest way use in code include ffmpeg executable in project (or install globally environment variable) , invoke directly like:
process process = new process(); process.startinfo.redirectstandardoutput = true; process.startinfo.redirectstandarderror = true; process.startinfo.filename = "ffmpeg"; process.startinfo.arguments = $"-i \"{originalfile}\" -ab 128 \"{outputpath}\""; process.startinfo.useshellexecute = false; process.startinfo.createnowindow = false; process.start(); process.waitforexit();
there more elegant solutions - wrappers around ffmpeg - should trick.
Comments
Post a Comment