title: .wav to .flac converter in C#
body: <p>My program is recording voice in .wav and convert it to .flac <br />
  I will send this .flac file to google, hope I will get the text of the voice.<br/>
  But there's error when my program trying to send the file to google, "The process cannot access the file 'C:\Users\Ahmad Mustofa\Documents\Visual Studio 2010\Projects\FP\voice.flac' because it is being used by another process." . I don't know which process that still use that file.
  Here is my code : <br/></p>
  
  <pre><code>        string inputFile = Path.Combine("wav ", input);//the converter
          string outputFile = Path.Combine("flac", Path.ChangeExtension(input, ".flac"));
  
          if (!File.Exists(inputFile))
              throw new ApplicationException("Input file " + inputFile + " cannot be found!");
  
          WavReader wav = new WavReader(inputFile);
          FlacWriter flac = new FlacWriter(File.Create(outputFile), wav.BitDepth, wav.Channels, wav.SampleRate);
          // Buffer for 1 second's worth of audio data
          byte[] buffer = new byte[wav.Bitrate / 8];
          int bytesRead;
          do
          {
              bytesRead = wav.InputStream.Read(buffer, 0, buffer.Length);
              flac.Convert(buffer, 0, bytesRead);
          } while (bytesRead &gt; 0);
          flac.Dispose();
          flac = null;
          wav.Dispose();
          wav = null;
          //the sender
              FileStream FS_Audiofile = new FileStream("C:\\Users\\Ahmad Mustofa\\Documents\\Visual Studio 2010\\Projects\\FP\\voice.flac", FileMode.Open, FileAccess.Read);
              BinaryReader BR_Audiofile = new BinaryReader(FS_Audiofile);
              byte[] BA_AudioFile = BR_Audiofile.ReadBytes((Int32)FS_Audiofile.Length);
              FS_Audiofile.Close();
              BR_Audiofile.Close();
  
              HttpWebRequest _HWR_SpeechToText = null;
  
              _HWR_SpeechToText = (HttpWebRequest)WebRequest.Create("http://www.google.com/speech-api/v1/recognize?xjerr=1&amp;client=chromium&amp;lang=de-DE&amp;maxresults=1&amp;pfilter=0");
  
              _HWR_SpeechToText.Method = "POST";
              _HWR_SpeechToText.ContentType = "audio/x-flac; rate=44100";
              _HWR_SpeechToText.ContentLength = BA_AudioFile.Length;
              _HWR_SpeechToText.GetRequestStream().Write(BA_AudioFile, 0, BA_AudioFile.Length);
  
              HttpWebResponse HWR_Response = (HttpWebResponse)_HWR_SpeechToText.GetResponse();
              if (HWR_Response.StatusCode == HttpStatusCode.OK)
              {
                  StreamReader SR_Response = new StreamReader(HWR_Response.GetResponseStream());
              }
  </code></pre>