private void ConvertToMp3() { string audio_path = GetWavAudioName(); string mp3Path = GetMp3AudioPath(); if (mAudioWriter != null) { mAudioWriter.Dispose(); //Release file mAudioWriter.WavToMP3(audio_path, mp3Path); } }
private string SaveAudioFromBufferToFile() { try { string fileName = GetWavAudioChildName((mListOfflineAudioFile.Count + 1).ToString()); Queue <WaveInEventArgs> remainRawData = new Queue <WaveInEventArgs>(); double savedAudioLengthInArrayLength = 0; double saveAudioLengthInSecond = 0; int remainAudioLength = 0; AudioWriter wavWriter = new AudioWriter(fileName); lock (balanceLock) { while (saveAudioLengthInSecond < Int16.Parse(mRecordingTime) * 60 && mRawAudioData.Count > 0) { WaveInEventArgs rawData = mRawAudioData.Dequeue(); if (saveAudioLengthInSecond >= (Int16.Parse(mRecordingTime) * 60 - 3)) { remainRawData.Enqueue(rawData); remainAudioLength += rawData.BytesRecorded; } wavWriter.WriteStream(rawData.Buffer, rawData.BytesRecorded); savedAudioLengthInArrayLength += rawData.BytesRecorded; saveAudioLengthInSecond = savedAudioLengthInArrayLength / (16000 * 2); } while (mRawAudioData.Count > 0) { remainRawData.Enqueue(mRawAudioData.Dequeue()); } mRawAudioData = remainRawData; mRawAudioLength = remainAudioLength; } wavWriter.Dispose(); string mp3FileName = GetMp3AudioChildPath((mListOfflineAudioFile.Count + 1).ToString()); wavWriter.WavToMP3(fileName, mp3FileName); //Remove wavfile File.Delete(fileName); return(mp3FileName); } catch { return(null); } }
private string SaveAllAudioFromBufferFile() { lock (balanceLock) { if (mRawAudioData.Count < 20) { mRawAudioData.Clear(); mRawAudioLength = 0; return(null); } } try { string fileName = GetWavAudioChildName((mListOfflineAudioFile.Count + 1).ToString()); AudioWriter wavWriter = new AudioWriter(fileName); lock (balanceLock) { while (mRawAudioData.Count > 0) { WaveInEventArgs rawData = mRawAudioData.Dequeue(); wavWriter.WriteStream(rawData.Buffer, rawData.BytesRecorded); } mRawAudioLength = 0; } wavWriter.Dispose(); string mp3FileName = GetMp3AudioChildPath((mListOfflineAudioFile.Count + 1).ToString()); wavWriter.WavToMP3(fileName, mp3FileName); //Remove wavfile File.Delete(fileName); return(mp3FileName); } catch { return(null); } }