/// <summary> /// 创建音频转换类 /// </summary> private void CreateAudioConvert(WaveFormat waveFormat) { lock (_lockAudio) { _pcm16kConvert = AudioConvert.Create(waveFormat, WaveFormat.PCM_ASR); } }
internal static async Task ConvertToWAVs(FanMission fm, AudioConvert type, bool doChecksAndProgressBox) { if (doChecksAndProgressBox) { if (!ChecksPassed(fm)) { return; } } if (!GameIsDark(fm.Game)) { return; } try { if (doChecksAndProgressBox) { Core.View.ShowProgressBox(ProgressTask.ConvertFiles); } await Task.Run(async() => { if (type == AudioConvert.WAVToWAV16) {
/// <summary> /// 释放音频转换非托管资源 /// </summary> private void DisposeAudioConvert() { if (_pcm16kConvert != null) { lock (_lockAudio) { _pcm16kConvert.Dispose(); _pcm16kConvert = null; } } }
private static void Worker_DoWork(object sender, DoWorkEventArgs e) { try { // start the NAudio.MediaFoundation.MediaFoundationApi.. AudioConvert.IsMediaFoundationApiStarted = true; foreach (var fileEntry in GetQueueFiles(queueIndex, toPath, conn)) { if (worker.CancellationPending) { break; } string sourceFile = fileEntry.fileNameFrom; string fileName = Path.GetFileName(fileEntry.fileNameFrom); if (fileName != null) { string destinationFile = Path.Combine(toPath, fileName); if (toMp3 && !Constants.FileIsMp3(sourceFile)) { AudioConvert.DesiredBitRate = bitRate; AudioConvert.ToMp3(sourceFile, Path.ChangeExtension(destinationFile, ".mp3"), true); } else { File.Copy(sourceFile, destinationFile, true); } worker.ReportProgress(GetPercentage(fileEntry.currentIndex, fileEntry.countTotal)); } } // stop the NAudio.MediaFoundation.MediaFoundationApi.. AudioConvert.IsMediaFoundationApiStarted = false; } catch (Exception ex) { // log the exception.. ExceptionLogger.LogError(ex); } }
protected void AudioConvert(object sender, System.EventArgs e) { AudioConvert convertaudio = new AudioConvert(); convertaudio.Show(); }