private void GenerateBatch() { groupBoxInputFiles.Enabled = false; _batchFileNumber = 0; textBoxLog.AppendText("Batch mode" + Environment.NewLine); foreach (ListViewItem lvi in listViewInputFiles.Items) { _batchFileNumber++; var videoFileName = lvi.Text; listViewInputFiles.SelectedIndices.Clear(); lvi.Selected = true; progressBar1.Maximum = 100; progressBar1.Value = 0; progressBar1.Visible = true; var modelFileName = Path.Combine(_voskFolder, comboBoxModels.Text); buttonGenerate.Enabled = false; buttonDownload.Enabled = false; buttonBatchMode.Enabled = false; var waveFileName = GenerateWavFile(videoFileName, 0); textBoxLog.AppendText("Wav file name: " + waveFileName + Environment.NewLine); progressBar1.Style = ProgressBarStyle.Blocks; var transcript = TranscribeViaVosk(waveFileName, modelFileName); if (_cancel) { TaskbarList.SetProgressState(_parentForm.Handle, TaskbarButtonProgressFlags.NoProgress); if (!_batchMode) { DialogResult = DialogResult.Cancel; } groupBoxInputFiles.Enabled = true; return; } var postProcessor = new AudioToTextPostProcessor(GetLanguage(comboBoxModels.Text)) { ParagraphMaxChars = Configuration.Settings.General.SubtitleLineMaximumLength * 2, }; TranscribedSubtitle = postProcessor.Generate(transcript, checkBoxUsePostProcessing.Checked, true, true, true, true); SaveToSourceFolder(videoFileName); TaskbarList.SetProgressValue(_parentForm.Handle, _batchFileNumber, listViewInputFiles.Items.Count); } progressBar1.Visible = false; labelTime.Text = string.Empty; TaskbarList.StartBlink(_parentForm, 10, 1, 2); MessageBox.Show(string.Format(LanguageSettings.Current.AudioToText.XFilesSavedToVideoSourceFolder, listViewInputFiles.Items.Count)); groupBoxInputFiles.Enabled = true; buttonGenerate.Enabled = true; buttonDownload.Enabled = true; buttonBatchMode.Enabled = true; DialogResult = DialogResult.Cancel; }
private void ButtonGenerate_Click(object sender, EventArgs e) { if (comboBoxModels.Items.Count == 0) { buttonDownload_Click(null, null); return; } if (_batchMode) { if (listViewInputFiles.Items.Count == 0) { buttonAddFile_Click(null, null); return; } GenerateBatch(); TaskbarList.SetProgressState(_parentForm.Handle, TaskbarButtonProgressFlags.NoProgress); return; } progressBar1.Maximum = 100; progressBar1.Value = 0; progressBar1.Visible = true; var modelFileName = Path.Combine(_voskFolder, comboBoxModels.Text); buttonGenerate.Enabled = false; buttonDownload.Enabled = false; buttonBatchMode.Enabled = false; var waveFileName = GenerateWavFile(_videoFileName, 0); textBoxLog.AppendText("Wav file name: " + waveFileName); textBoxLog.AppendText(Environment.NewLine); progressBar1.Style = ProgressBarStyle.Blocks; var transcript = TranscribeViaVosk(waveFileName, modelFileName); if (_cancel) { DialogResult = DialogResult.Cancel; return; } var postProcessor = new AudioToTextPostProcessor(GetLanguage(comboBoxModels.Text)) { ParagraphMaxChars = Configuration.Settings.General.SubtitleLineMaximumLength * 2, }; TranscribedSubtitle = postProcessor.Generate(transcript, checkBoxUsePostProcessing.Checked, true, true, true, true); DialogResult = DialogResult.OK; }
private void GenerateBatch() { groupBoxInputFiles.Enabled = false; _batchFileNumber = 0; textBoxLog.AppendText("Batch mode" + Environment.NewLine); var postProcessor = new AudioToTextPostProcessor(GetLanguage(comboBoxModels.Text)) { ParagraphMaxChars = Configuration.Settings.General.SubtitleLineMaximumLength * 2, }; progressBar1.Visible = true; foreach (ListViewItem lvi in listViewInputFiles.Items) { _batchFileNumber++; var videoFileName = lvi.Text; listViewInputFiles.SelectedIndices.Clear(); lvi.Selected = true; var modelFileName = Path.Combine(_voskFolder, comboBoxModels.Text); buttonGenerate.Enabled = false; buttonDownload.Enabled = false; var waveFileName = videoFileName; textBoxLog.AppendText("Wav file name: " + waveFileName + Environment.NewLine); var transcript = TranscribeViaVosk(waveFileName, modelFileName); if (_cancel) { TaskbarList.SetProgressState(_parentForm.Handle, TaskbarButtonProgressFlags.NoProgress); DialogResult = DialogResult.Cancel; return; } TranscribedSubtitle = postProcessor.Generate(transcript, checkBoxUsePostProcessing.Checked, false, true, false, false); progressBar1.Value = (int)Math.Round(_batchFileNumber * 100.0 / _audioClips.Count, MidpointRounding.AwayFromZero); progressBar1.Refresh(); Application.DoEvents(); SaveToAudioClip(_batchFileNumber - 1); TaskbarList.SetProgressValue(_parentForm.Handle, _batchFileNumber, listViewInputFiles.Items.Count); } progressBar1.Value = 100; labelTime.Text = string.Empty; PostFix(postProcessor); DialogResult = DialogResult.OK; }
private void PostFix(AudioToTextPostProcessor postProcessor) { var postSub = new Subtitle(); foreach (var audioClip in _audioClips) { postSub.Paragraphs.Add(audioClip.Paragraph); } var postSubFixed = postProcessor.Generate(postSub, checkBoxUsePostProcessing.Checked, true, false, true, false); for (var index = 0; index < _audioClips.Count; index++) { var audioClip = _audioClips[index]; if (index < postSubFixed.Paragraphs.Count) { audioClip.Paragraph.Text = postSubFixed.Paragraphs[index].Text; } } }