public static void ConvertWavToMp3(string WavFile, string outPutFile) { CheckAddBinPath(); WaveFileReader rdr = new WaveFileReader(WavFile); using (var wtr = new LameMP3FileWriter(outPutFile, rdr.WaveFormat, 128)) { rdr.CopyTo(wtr); rdr.Dispose(); wtr.Dispose(); return; } }
// Method needed to cleanup outputStream and waveOut file private void DisposeWave() { if (sourceStream != null) { sourceStream.StopRecording(); sourceStream.Dispose(); sourceStream = null; } if (waveWriter != null) { waveWriter.Dispose(); waveWriter = null; } if (waveOut != null) { if (waveOut.PlaybackState == NAudio.Wave.PlaybackState.Playing) { waveOut.Stop(); } waveOut.Dispose(); waveOut.Stop(); waveOut = null; } if (waveReader != null) { waveReader.Dispose(); waveReader.Close(); waveReader = null; } }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (soundOut != null) { soundOut.Stop(); soundOut.Dispose(); soundOut = null; } if (waveFileReader != null) { waveFileReader.Dispose(); waveFileReader = null; } }
private void DisposeWave() { if (output != null) { if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) { output.Stop(); } output.Dispose(); output = null; } if (wave != null) { wave.Dispose(); wave = null; } }
public void DisposeWave() { if (_output != null) { if (_output.PlaybackState == NAudio.Wave.PlaybackState.Playing || _output.PlaybackState == NAudio.Wave.PlaybackState.Paused) { _output.Stop(); } _output.Dispose(); _output = null; } if (_wav != null) { _wav.Dispose(); _wav = null; } }
private IEnumerator ImportAudioNAudioRoutine(string url) { var loader = new WWW(url); while (!loader.isDone) { yield return(loader); } Debug.Log("NAudio file play"); NAudio.Wave.WaveOut waveOut = new NAudio.Wave.WaveOut(); NAudio.Wave.WaveFileReader wavReader = new NAudio.Wave.WaveFileReader("bardintro.wav"); Debug.Log("Format : " + wavReader.WaveFormat.ToString() + "sample count : " + wavReader.SampleCount + " :: " + wavReader.Length); var pcmLength = (int)wavReader.Length; var buffer = new byte[pcmLength]; var bytesRead = wavReader.Read(buffer, 0, pcmLength); using (FileStream fs = File.Open("generatedaudiofile", FileMode.Create)) { StreamWriter sw = new StreamWriter(fs); int i = 0; for (i = 0; i < buffer.Length; i += 3) { short int16 = (short)(((buffer[i] & 0xFF) << 8) | (buffer[i + 1] & 0xFF)); float f = int16; sw.WriteLine(f); } } //waveOut.Play(); yield return(new WaitForSeconds(3)); //waveOut.Stop(); wavReader.Dispose(); waveOut.Dispose(); }
void unFX() { try { if (fx_out != null) { fx_out.Stop(); } if (fx_out != null) { fx_out.Dispose(); } if (fx_wav != null) { fx_wav.Dispose(); } if (fx_stream != null) { fx_stream.Dispose(); } unFxTimer.Stop(); } catch { } }
private void EncodeButton_Click(object sender, EventArgs e) { vol = VolumeTrk.Value*float.Parse((0.01).ToString()); text = MainRTextBox.Text; Stream str; SoundPlayer sp = new SoundPlayer(); WaveFileReader wfr = new WaveFileReader(Properties.Resources.background); WaveChannel32 wc = new WaveChannel32(wfr,vol,0); DirectSoundOut wfo = new DirectSoundOut(); wfo.Init(wc); wfo.Play(); System.Timers.Timer glc = new System.Timers.Timer(Int32.Parse(IntervalBox.Text)); if (IntervalBox.Enabled) { glc.Start(); glc.Elapsed += new ElapsedEventHandler(glctick); } System.Timers.Timer la = new System.Timers.Timer(2000); la.Elapsed += new ElapsedEventHandler(latick); la.Start(); foreach (char a in text.ToLower()) { //Ищем совпадения по буквам и произносим символ if (english.IndexOf(a) != -1) { switch (a) { case 'a': str = Properties.Resources.a; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(474 + Int32.Parse(TextSpeed.Text)); break; case 'b': str = Properties.Resources.b; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(504 + Int32.Parse(TextSpeed.Text)); break; case 'c': str = Properties.Resources.c; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(517 + Int32.Parse(TextSpeed.Text)); break; case 'd': str = Properties.Resources.d; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(478 + Int32.Parse(TextSpeed.Text)); break; case 'e': str = Properties.Resources.e; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(388 + Int32.Parse(TextSpeed.Text)); break; case 'f': str = Properties.Resources.f; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(623 + Int32.Parse(TextSpeed.Text)); break; case 'g': str = Properties.Resources.g; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(359 + Int32.Parse(TextSpeed.Text)); break; case 'h': str = Properties.Resources.h; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(571 + Int32.Parse(TextSpeed.Text)); break; case 'i': str = Properties.Resources.i; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(432 + Int32.Parse(TextSpeed.Text)); break; case 'j': str = Properties.Resources.j; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(548 + Int32.Parse(TextSpeed.Text)); break; case 'k': str = Properties.Resources.k; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(457 + Int32.Parse(TextSpeed.Text)); break; case 'l': str = Properties.Resources.l; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(434 + Int32.Parse(TextSpeed.Text)); break; case 'm': str = Properties.Resources.m; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(511 + Int32.Parse(TextSpeed.Text)); break; case 'n': str = Properties.Resources.n; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(614 + Int32.Parse(TextSpeed.Text)); break; case 'o': str = Properties.Resources.o; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(460 + Int32.Parse(TextSpeed.Text)); break; case 'p': str = Properties.Resources.p; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(420 + Int32.Parse(TextSpeed.Text)); break; case 'q': str = Properties.Resources.q; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(500 + Int32.Parse(TextSpeed.Text)); break; case 'r': str = Properties.Resources.r; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(632 + Int32.Parse(TextSpeed.Text)); break; case 's': str = Properties.Resources.s; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(704 + Int32.Parse(TextSpeed.Text)); break; case 't': str = Properties.Resources.t; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(571 + Int32.Parse(TextSpeed.Text)); break; case 'u': str = Properties.Resources.u; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(707 + Int32.Parse(TextSpeed.Text)); break; case 'v': str = Properties.Resources.v; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(646 + Int32.Parse(TextSpeed.Text)); break; case 'w': str = Properties.Resources.w; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(580 + Int32.Parse(TextSpeed.Text)); break; case 'x': str = Properties.Resources.x; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(636 + Int32.Parse(TextSpeed.Text)); break; case 'y': str = Properties.Resources.y; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(666 + Int32.Parse(TextSpeed.Text)); break; case 'z': str = Properties.Resources.z; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(486 + Int32.Parse(TextSpeed.Text)); break; case '0': str = Properties.Resources.n0; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(503 + Int32.Parse(TextSpeed.Text)); break; case '1': str = Properties.Resources.n1; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(463 + Int32.Parse(TextSpeed.Text)); break; case '2': str = Properties.Resources.n2; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(418 + Int32.Parse(TextSpeed.Text)); break; case '3': str = Properties.Resources.n3; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(450 + Int32.Parse(TextSpeed.Text)); break; case '4': str = Properties.Resources.n4; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(507 + Int32.Parse(TextSpeed.Text)); break; case '5': str = Properties.Resources.n5; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(582 + Int32.Parse(TextSpeed.Text)); break; case '6': str = Properties.Resources.n6; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(582 + Int32.Parse(TextSpeed.Text)); break; case '7': str = Properties.Resources.n7; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(520 + Int32.Parse(TextSpeed.Text)); break; case '8': str = Properties.Resources.n8; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(373 + Int32.Parse(TextSpeed.Text)); break; case '9': str = Properties.Resources.n9; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(523 + Int32.Parse(TextSpeed.Text)); break; case '.': str = Properties.Resources.dot; sp = new SoundPlayer(str); sp.Play(); Thread.Sleep(663 + Int32.Parse(TextSpeed.Text)); break; case ' ': Thread.Sleep(Math.Abs(Int32.Parse(TextSpeed.Text))); break; } } } try { glc.Stop(); glc.Dispose(); } catch{} la.Stop(); la.Dispose(); wfo.Dispose(); wc.Dispose(); wfr.Dispose(); GC.Collect(); }
/// <summary> /// Function to encode a Wave file to OGG /// </summary> /// <param name="infile">Wave file name</param> /// <param name="outfile">Ogg file name</param> public void Encode(string infile, string outfile) { WaveFileReader reader = new WaveFileReader(infile); Stream stdout = File.OpenWrite(outfile); try { // Encode setup OggInterop.vorbis_info_init(vi); // choose an encoding mode /********************************************************************* Encoding using a VBR quality mode. The usable range is -.1 (lowest quality, smallest file) to 1. (highest quality, largest file). Example quality mode .4: 44kHz stereo coupled, roughly 128kbps VBR ret = vorbis_encode_init_vbr(&vi,2,44100,.4); --------------------------------------------------------------------- Encoding using an average bitrate mode (ABR). example: 44kHz stereo coupled, average 128kbps VBR ret = vorbis_encode_init(&vi,2,44100,-1,128000,-1); --------------------------------------------------------------------- Encode using a qulity mode, but select that quality mode by asking for an approximate bitrate. This is not ABR, it is true VBR, but selected using the bitrate interface, and then turning bitrate management off: ret = ( vorbis_encode_setup_managed(&vi,2,44100,-1,128000,-1) || vorbis_encode_ctl(&vi,OV_ECTL_RATEMANAGE_AVG,NULL) || vorbis_encode_setup_init(&vi)); *********************************************************************/ // do not continue if setup failed; this can happen if we ask for a // mode that libVorbis does not support (eg, too low a bitrate, etc, // will return 'OV_EIMPL') if(OggInterop.vorbis_encode_init_vbr(vi,reader.WaveFormat.Channels,reader.WaveFormat.SampleRate,0.5f) != 0) throw new ApplicationException("vorbis_encode_init_vbr"); // add a comment //vorbis_comment_init(vc); //vorbis_comment_add_tag(vc,"ENCODER","OggEncoder.cs"); //vorbis_comment_add_tag(vc,"ARTIST","Mark Heath"); //vorbis_comment_add_tag(vc,"TITLE",Path.GetFileNameWithoutExtension(infile)); // MRH: possibly redundant step, but in the oggtools app // seems to let us get past the null reference exception in // vorbis_analysis_init the second time through // (but then we get stuck on vorbis_info_clear) OggInterop.vorbis_encode_setup_init(vi); // set up the analysis state and auxiliary encoding storage if(OggInterop.vorbis_analysis_init(vd,vi) != 0) throw new ApplicationException("vorbis_analysis_init error"); if(OggInterop.vorbis_block_init(vd,vb) != 0) throw new ApplicationException("vorbis_block_init error"); // set up our packet->stream encoder // pick a random serial number; that way we can more likely build // chained streams just by concatenation Random rand = new Random(); if(OggInterop.ogg_stream_init(os,rand.Next()) != 0) throw new ApplicationException("ogg_stream_init error"); // Vorbis streams begin with three headers; the initial header (with // most of the codec setup parameters) which is mandated by the Ogg // bitstream spec. The second header holds any comment fields. The // third header holds the bitstream codebook. We merely need to // make the headers, then pass them to libvorbis one at a time; // libvorbis handles the additional Ogg bitstream constraints IntPtr header = AllocateHGlobal(64); //ogg_packet IntPtr header_comments = AllocateHGlobal(64); //ogg_packet IntPtr header_codebook = AllocateHGlobal(64); //ogg_packet OggInterop.vorbis_analysis_headerout(vd,vc,header,header_comments,header_codebook); OggInterop.ogg_stream_packetin(os,header); // automatically placed in its own page OggInterop.ogg_stream_packetin(os,header_comments); OggInterop.ogg_stream_packetin(os,header_codebook); // This ensures the actual audio data will start on a new page, as per spec while(OggInterop.ogg_stream_flush(os,og) != 0) { WriteOg(og,stdout); } float[][] samplebuffer = new float[reader.WaveFormat.Channels][]; for(int channel = 0; channel < reader.WaveFormat.Channels; channel++) { samplebuffer[channel] = new float[READ]; } bool eos=false; while(!eos) { int samples = reader.Read(samplebuffer,READ); if(samples == 0) { // end of file. this can be done implicitly in the mainline, //but it's easier to see here in non-clever fashion. //Tell the library we're at end of stream so that it can handle //the last frame and mark end of stream in the output properly OggInterop.vorbis_analysis_wrote(vd,0); } else { // data to encode // expose the buffer to submit data IntPtr bufferpointer = OggInterop.vorbis_analysis_buffer(vd,samples); int[] floatpointers = new int[reader.WaveFormat.Channels]; Marshal.Copy(bufferpointer,floatpointers,0,reader.WaveFormat.Channels); for(int channel = 0; channel < reader.WaveFormat.Channels; channel++) { IntPtr channelbuffer = new IntPtr(floatpointers[channel]); Marshal.Copy(samplebuffer[channel],0,channelbuffer,samples); } // tell the library how much we actually submitted OggInterop.vorbis_analysis_wrote(vd,samples); } // vorbis does some data preanalysis, then divvies up blocks for // more involved (potentially parallel) processing. Get a single // block for encoding now while(OggInterop.vorbis_analysis_blockout(vd,vb)==1) { /* analysis, assume we want to use bitrate management */ OggInterop.vorbis_analysis(vb,IntPtr.Zero); OggInterop.vorbis_bitrate_addblock(vb); while(OggInterop.vorbis_bitrate_flushpacket(vd,op) != 0) { /* weld the packet into the bitstream */ OggInterop.ogg_stream_packetin(os,op); /* write out pages (if any) */ while(!eos) { int result=OggInterop.ogg_stream_pageout(os,og); if(result==0) break; WriteOg(og,stdout); /* this could be set above, but for illustrative purposes, I do it here (to show that vorbis does know where the stream ends) */ if(OggInterop.ogg_page_eos(og) != 0) eos=true; } } } } // clean up and exit. vorbis_info_clear() must be called last */ if(OggInterop.ogg_stream_clear(os) != 0) throw new ApplicationException("ogg_stream_clear error"); if(OggInterop.vorbis_block_clear(vb) != 0) throw new ApplicationException("vorbis_block_clear error"); OggInterop.vorbis_dsp_clear(vd); //vorbis_comment_clear(vc); OggInterop.vorbis_info_clear(vi); // ogg_page and ogg_packet structs always point to storage in // libvorbis. They're never freed or manipulated directly } finally { reader.Dispose(); stdout.Close(); } GC.KeepAlive(this); }
private void waveIn_RecordingStopped(object sender, EventArgs e) { if (writeToFile == 1) { waveIn.Dispose(); waveIn = null; writer.Close(); writer = null; int bytes_to_read = (rec_times + 1) * 6400; byte[] wav_bytes = new byte[bytes_to_read]; WaveFileReader wfr = new WaveFileReader("file.wav"); if (wfr.Length < bytes_to_read) { wfr.Read(wav_bytes, 0, (int)wfr.Length); } else { wfr.Position = wfr.Length - 1 - bytes_to_read; wfr.Read(wav_bytes, 0, bytes_to_read); } wfr.Dispose(); wfr.Close(); WaveIn second_waveIn = new WaveIn(); second_waveIn.DeviceNumber = 0; second_waveIn.WaveFormat = new WaveFormat(16000, 2); WaveFileWriter second_writer = new WaveFileWriter("cmd.wav", second_waveIn.WaveFormat); second_waveIn.StartRecording(); second_writer.Write(wav_bytes, 0, bytes_to_read); second_waveIn.StopRecording(); second_waveIn.Dispose(); second_waveIn = null; second_writer.Close(); second_writer = null; listBox1.Items.Add("CONVERTING"); listBox1.SelectedIndex = listBox1.Items.Count - 1; Wav2Flac("cmd.wav", "file.flac"); result = GoogleSpeechRequest(16000); string res = result; int k = res.IndexOf("utterance\":\"") + "utterance\":\"".Length; int k1 = res.IndexOf("\"", k + 1); string cmd = res.Substring(k, k1 - k); listBox1.Items.Add("RECOGNIZED"); richTextBox1.Text += cmd + "\n"; File.Delete("cmd.wav"); rec_times = 0; writeToFile = 0; } else if (writeToFile == 0) { waveIn.Dispose(); waveIn = null; writer.Close(); writer = null; } }
public static void HighPassFilter(string innPath, string outtPath) { string inPath = "C:\\Users\\Administratorius\\Documents\\GitHub\\MusicEditor\\PawellsMusicEditor\\PawellsMusicEditor\\Content\\Songs\\NowEdited.WAV"; string outPath = "C:\\Users\\Administratorius\\Documents\\GitHub\\MusicEditor\\PawellsMusicEditor\\PawellsMusicEditor\\Content\\Songs\\NowEdited3.WAV"; Mp3ToWav(innPath, inPath); WaveFileReader reader = new WaveFileReader(inPath); var myFilter = BiQuadFilter.HighPassFilter(44F, 10F, 0.5F); WaveFileWriter writer = new WaveFileWriter(outPath, reader.WaveFormat); reader.Position = 0; var endPos = reader.Length; while (reader.Position < endPos) { int bytesRequired = (int)(endPos - reader.Position); if (bytesRequired > 0) { float[] sample = new float[4]; for (int i = 0; i < 2; i++) { sample[i] = myFilter.Transform(reader.ReadNextSampleFrame()[i]); } writer.WriteSamples(sample, 0, 4); } } reader.Dispose(); writer.Dispose(); ConvertWavToMp3(outPath, outtPath); File.Delete(inPath); File.Delete(outPath); }
private static void TrimWavFile(WaveFileReader reader, WaveFileWriter writer, int startPos, int endPos) { reader.Position = startPos; byte[] buffer = new byte[1024]; while (reader.Position < endPos) { int bytesRequired = (int)(endPos - reader.Position); if (bytesRequired > 0) { int bytesToRead = Math.Min(bytesRequired, buffer.Length); int bytesRead = reader.Read(buffer, 0, bytesToRead); if (bytesRead > 0) { writer.WriteData(buffer, 0, bytesRead); } } } reader.Dispose(); writer.Dispose(); }
public static void TrimWavFile(string innPath, string outtPath, TimeSpan cutFromStart, TimeSpan cutFromEnd) { string inPath = "C:\\Users\\Administratorius\\Documents\\GitHub\\MusicEditor\\PawellsMusicEditor\\PawellsMusicEditor\\Content\\Songs\\NowEdited.WAV"; string outPath = "C:\\Users\\Administratorius\\Documents\\GitHub\\MusicEditor\\PawellsMusicEditor\\PawellsMusicEditor\\Content\\Songs\\NowEdited2.WAV"; Mp3ToWav(innPath, inPath); using (WaveFileReader reader = new WaveFileReader(inPath)) { using (WaveFileWriter writer = new WaveFileWriter(outPath, reader.WaveFormat)) { int bytesPerMillisecond = reader.WaveFormat.AverageBytesPerSecond / 1000; int startPos = (int)cutFromStart.TotalMilliseconds * bytesPerMillisecond; startPos = startPos - startPos % reader.WaveFormat.BlockAlign; int endBytes = (int)cutFromEnd.TotalMilliseconds * bytesPerMillisecond; endBytes = endBytes - endBytes % reader.WaveFormat.BlockAlign; int endPos = (int)reader.Length - endBytes; TrimWavFile(reader, writer, startPos, endPos); reader.Dispose(); writer.Dispose(); } ConvertWavToMp3(outPath, outtPath); } File.Delete(inPath); File.Delete(outPath); }
private void wAVsCWAVsToolStripMenuItem_Click(object sender, EventArgs e) { if (!File.Exists("CTR_WaveConverter32.exe")) { MessageBox.Show(messages[11],"Please understand",MessageBoxButtons.OK,MessageBoxIcon.Error); return; } try { OpenFileDialog opn = new OpenFileDialog(); opn.Filter = "WAV file|*.wav|Every file|*.*"; opn.Title = "Select a WAV file"; opn.Multiselect = true; if (opn.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (opn.FileNames.Length == 1) { Wav2CWAV(opn.FileName); } else { for (int i = 0; i < opn.FileNames.Length; i++) { if (!APP_not_Optimize_Cwavs) { Debug.Print("Optimizing CWAV: " + Path.GetTempPath() + Path.GetFileName(opn.FileNames[i]) + ".tmp.wav"); WaveFormat New = new WaveFormat(APP_opt_samples, 8, 1); WaveStream Original = new WaveFileReader(opn.FileNames[i]); WaveFormatConversionStream stream = new WaveFormatConversionStream(New, Original); if (System.IO.File.Exists(Path.GetTempPath() + Path.GetFileName(opn.FileNames[i]) + ".tmp.wav")) File.Delete(Path.GetTempPath() + Path.GetFileName(opn.FileNames[i]) + ".tmp.wav"); WaveFileWriter.CreateWaveFile(Path.GetTempPath() + Path.GetFileName(opn.FileNames[i]) + ".tmp.wav", stream); stream.Dispose(); Original.Dispose(); } Process prc = new Process(); prc.StartInfo.FileName = "CTR_WaveConverter32.exe"; if (!APP_not_Optimize_Cwavs) prc.StartInfo.Arguments = "-o \"" + opn.FileNames[i] + ".bcwav\" \"" + Path.GetTempPath() + Path.GetFileName(opn.FileNames[i]) + ".tmp.wav\""; else prc.StartInfo.Arguments = "-o \"" + opn.FileNames[i] + ".bcwav\" \"" + opn.FileNames[i] + "\""; Debug.Print("Converting CWAV: " + Path.GetTempPath() + Path.GetFileName(opn.FileNames[i]) + ".tmp.wav"); prc.Start(); prc.WaitForExit(); if (System.IO.File.Exists(Path.GetTempPath() + Path.GetFileName(opn.FileNames[i]) + ".tmp.wav")) File.Delete(Path.GetTempPath() + Path.GetFileName(opn.FileNames[i]) + ".tmp.wav"); } MessageBox.Show("Done !"); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }
void Wav2CWAV(string input) { SaveFileDialog sv = new SaveFileDialog(); sv.Filter = "CWAVs|*.bcwav|Every file|*.*"; sv.Title = "Save the CWAV file"; if (sv.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (!APP_not_Optimize_Cwavs) { Debug.Print("Optimizing CWAV: " + Path.GetTempPath() + Path.GetFileName(input) + ".tmp.wav"); WaveFormat New = new WaveFormat(APP_opt_samples, 8, 1); WaveStream Original = new WaveFileReader(input); WaveFormatConversionStream stream = new WaveFormatConversionStream(New, Original); if (System.IO.File.Exists(Path.GetTempPath() + Path.GetFileName(input) + ".tmp.wav")) File.Delete(Path.GetTempPath() + Path.GetFileName(input) + ".tmp.wav"); WaveFileWriter.CreateWaveFile(Path.GetTempPath() + Path.GetFileName(input) + ".tmp.wav", stream); stream.Dispose(); Original.Dispose(); } Process prc = new Process(); prc.StartInfo.FileName = "CTR_WaveConverter32.exe"; if (!APP_not_Optimize_Cwavs) prc.StartInfo.Arguments = "-o \"" + sv.FileName + "\" \"" + Path.GetTempPath() + Path.GetFileName(input) + ".tmp.wav\""; else prc.StartInfo.Arguments = "-o \"" + sv.FileName + "\" \"" +input+ "\""; prc.Start(); prc.WaitForExit(); if (System.IO.File.Exists(Path.GetTempPath() + Path.GetFileName(input) + ".tmp.wav")) File.Delete(Path.GetTempPath() + Path.GetFileName(input) + ".tmp.wav"); if (File.Exists(sv.FileName)) MessageBox.Show("Done !"); else MessageBox.Show("Error while converting the file, run the command in the cmd to check the output"); } }
public void StopRecording() { lock (_recordingAccessLock) { Log.Info("Finished Recording"); MicrophoneStream.StopRecording(); _waveWriter.Dispose(); _waveWriter = null; var read = new WaveFileReader(_recordedFile); var d = new Description(_recordedFile, 0, read.TotalTime.TotalMilliseconds, _descriptionStartTime, _recordExtended); OnDescriptionRecorded(d); read.Dispose(); IsRecording = false; } }