public static void Export(string waveFileDirectoryName, string filenameFilter, string outputFilePath) { try { System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; var files = Directory.GetFiles(waveFileDirectoryName, filenameFilter); // sort the files var sorted = new SortedList <float, string>(); foreach (var file in files) { var fileFloat = -1f; if (float.TryParse(Regex.Match(Path.GetFileName(file), @"^[0-9.]+").Value, out fileFloat)) { sorted.Add(fileFloat, file); } } // delete old version of the MP3 file if (File.Exists(outputFilePath)) { File.Delete(outputFilePath); } // if the file still exists, we can't continue if (File.Exists(outputFilePath)) { var msg = LocalizationManager.GetString( "SessionsView.Transcription.TextAnnotation.ExportMenu.AudioExportFileLocked", "Audio export failed because the selected output file already exists and is locked."); throw new Exception(msg); } using (var tempFile = TempFile.WithExtension(".wav")) { // combine the chunks into a single wave file CombineChunks(sorted.Values, tempFile.Path); // convert to MP3 ConvertMediaDlg.Show(tempFile.Path, "Extract audio to mono mp3 audio file (low quality)", outputFilePath); } } finally { System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default; } }
/// ------------------------------------------------------------------------------------ private void HandleConvertButtonClick(object sender, EventArgs e) { var index = _grid.CurrentCellAddress.Y; var file = (index >= 0 && index < _files.Count() ? _files.ElementAt(index) : null); if (file == null) { SystemSounds.Beep.Play(); return; } var outputFile = ConvertMediaDlg.Show(file.PathToAnnotatedFile, null); if (outputFile != null && PostMenuCommandRefreshAction != null) { PostMenuCommandRefreshAction(outputFile); } }