From b600a1787cc27577a8251f0cfc1f14cad01e6138 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Sun, 7 Apr 2024 16:00:07 +0200 Subject: [PATCH] Update PFW + fix issue in batch mode - thx Purfview :) work on #8143 --- src/ui/Forms/AudioToText/WhisperAdvanced.cs | 2 +- .../Forms/AudioToText/WhisperAudioToText.cs | 14 +- src/ui/Forms/AudioToText/WhisperDownload.cs | 8 +- src/ui/Forms/Main.cs | 13 ++ src/ui/Forms/TextToSpeech.Designer.cs | 104 +++++++++++++++ src/ui/Forms/TextToSpeech.cs | 39 ++++++ src/ui/Forms/TextToSpeech.resx | 120 ++++++++++++++++++ src/ui/SubtitleEdit.csproj | 10 ++ 8 files changed, 300 insertions(+), 10 deletions(-) create mode 100644 src/ui/Forms/TextToSpeech.Designer.cs create mode 100644 src/ui/Forms/TextToSpeech.cs create mode 100644 src/ui/Forms/TextToSpeech.resx diff --git a/src/ui/Forms/AudioToText/WhisperAdvanced.cs b/src/ui/Forms/AudioToText/WhisperAdvanced.cs index c871da86c..bbe739474 100644 --- a/src/ui/Forms/AudioToText/WhisperAdvanced.cs +++ b/src/ui/Forms/AudioToText/WhisperAdvanced.cs @@ -138,7 +138,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText private void button1_Click(object sender, EventArgs e) { - comboBoxWhisperExtra.Text = $"--highlight_words true --sentence --max_line_width {Configuration.Settings.General.SubtitleLineMaximumLength} --max_line_count {Configuration.Settings.General.MaxNumberOfLines}"; + comboBoxWhisperExtra.Text = $"--highlight_words true --max_line_width {Configuration.Settings.General.SubtitleLineMaximumLength} --max_line_count {Configuration.Settings.General.MaxNumberOfLines}"; } private void buttonStandardAsia_Click(object sender, EventArgs e) diff --git a/src/ui/Forms/AudioToText/WhisperAudioToText.cs b/src/ui/Forms/AudioToText/WhisperAudioToText.cs index f2f8ff15e..71c54cfdb 100644 --- a/src/ui/Forms/AudioToText/WhisperAudioToText.cs +++ b/src/ui/Forms/AudioToText/WhisperAudioToText.cs @@ -446,7 +446,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText progressBar1.Style = ProgressBarStyle.Blocks; timer1.Start(); - var transcript = TranscribeViaWhisper(waveFileName); + var transcript = TranscribeViaWhisper(waveFileName, _videoFileName); timer1.Stop(); if (_cancel && (transcript == null || transcript.Paragraphs.Count == 0 || MessageBox.Show(LanguageSettings.Current.AudioToText.KeepPartialTranscription, Text, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)) { @@ -564,7 +564,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText _outputText.Add(string.Empty); progressBar1.Style = ProgressBarStyle.Blocks; - var transcript = TranscribeViaWhisper(waveFileName); + var transcript = TranscribeViaWhisper(waveFileName, videoFileName); if (_cancel) { TaskbarList.SetProgressState(_parentForm.Handle, TaskbarButtonProgressFlags.NoProgress); @@ -719,7 +719,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText var fileName = Path.Combine(Utilities.GetPathAndFileNameWithoutExtension(videoFileName)) + format.Extension; if (File.Exists(fileName)) { - fileName = $"{Path.Combine(Utilities.GetPathAndFileNameWithoutExtension(videoFileName))}.{Guid.NewGuid().ToString()}.{format.Extension}"; + fileName = $"{Path.Combine(Utilities.GetPathAndFileNameWithoutExtension(videoFileName))}.{Guid.NewGuid().ToString()}{format.Extension}"; } try @@ -761,7 +761,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText return language != null ? language.Code : "en"; } - public Subtitle TranscribeViaWhisper(string waveFileName) + public Subtitle TranscribeViaWhisper(string waveFileName, string videoFileName) { _showProgressPct = -1; var model = comboBoxModels.Items[comboBoxModels.SelectedIndex] as WhisperModel; @@ -823,9 +823,9 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText var inputFile = waveFileName; if (!_useCenterChannelOnly && comboBoxWhisperEngine.Text == WhisperChoice.PurfviewFasterWhisper && - _audioTrackNumber == 0) + _audioTrackNumber <= 0) { - inputFile = _videoFileName; + inputFile = videoFileName; } var process = GetWhisperProcess(inputFile, model.Name, _languageCode, checkBoxTranslateToEnglish.Checked, OutputHandler); @@ -895,7 +895,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText process.Dispose(); - if (GetResultFromSrt(waveFileName, _videoFileName, out var resultTexts, _outputText, _filesToDelete)) + if (GetResultFromSrt(waveFileName, videoFileName, out var resultTexts, _outputText, _filesToDelete)) { var subtitle = new Subtitle(); subtitle.Paragraphs.AddRange(resultTexts.Select(p => new Paragraph(p.Text, (double)p.Start * 1000.0, (double)p.End * 1000.0)).ToList()); diff --git a/src/ui/Forms/AudioToText/WhisperDownload.cs b/src/ui/Forms/AudioToText/WhisperDownload.cs index c6cde54b3..eaed36090 100644 --- a/src/ui/Forms/AudioToText/WhisperDownload.cs +++ b/src/ui/Forms/AudioToText/WhisperDownload.cs @@ -89,15 +89,17 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText }; - private const string DownloadUrlPurfviewFasterWhisper = "https://github.com/Purfview/whisper-standalone-win/releases/download/faster-whisper/Whisper-Faster_r192.1_windows.zip"; + private const string DownloadUrlPurfviewFasterWhisper = "https://github.com/Purfview/whisper-standalone-win/releases/download/faster-whisper/Whisper-Faster_r192.3_windows.zip"; private static readonly string[] Sha512HashesPurfviewFasterWhisper = { - "94faae09146e33e0d55d9190d5b3ed79ea3bda0cf9e7f308dd47812827e4f0c24d2037718aa3c647881008eaaa04bbed033ea338aaa8333aae536bb2f2b83256", // r192.1 + "7e289659ff5622cdf99144602729a714985a7f11ebdc988f3f0721fe433d72e7fb751afeece94029f602b304690ad34f8a35bf5980af5517b2718ba07c163279", // r192.3 }; private static readonly string[] OldSha512HashesPurfviewFasterWhisper = { + "3b84e21134b7f24b81d7252fe895299d14087cccc1d8b1e7ae187c190b87b0bf7d84d3ce0a4a2fc5d2f9c436a33003663763fd6f62e7f87da1683df7fbd6d10b", // r192.2 + "94faae09146e33e0d55d9190d5b3ed79ea3bda0cf9e7f308dd47812827e4f0c24d2037718aa3c647881008eaaa04bbed033ea338aaa8333aae536bb2f2b83256", // r192.1 "3dee9ece233be4e661bab7555a2b4e7d4c53d823bf2b4032bd75857554a14a04745c57112946e735dc5ab6f8ec832483444cb95a0921f18b5f736787dbbc515c", // r189.1 "e78616511a92b21cb8ac82e23cdbd06f5b9310751e5f3fa940b5c48743b69bad130aaf6d629ae07c5388326f117be8f181b125ed04aacd23f1a80d8891be889b", // r186.1 "a16e2b5460d7f4b0d45de3f0e07b231d58ad4c79d077ad6b9c84a4e2ced4bd1cd3a7d9f01689f1d847ec8ff59c8f81cb742fcf2b153291ed6f15ec8b27adb998", // r167.2 @@ -396,6 +398,8 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText "628dee27ab3030798c42983d0f544668f54e7c8d1c7a433b322b9c07286eedd10666d9b1f89764a75301b334cea9c7ad8bfbfeee00a98113b4730ee5cafe8812", "56faadc85291049b1ad912de8c20fd262288f315d881e517085a15213690f2b242d80aedb2a4c213a7aa26b6ec43d2d26fe3674354a31f816d0e4bca07d002bc", "d53002d273287bfcfcd678d3d9f1faabbbca533ac3fa11867be0e7e365d386bf8fddf591cad41345006406cac663868dd7214d680f36906abe0f7d851d989fa2", + "0f463526879a83b938c315d8ca865db89945beb8ba9fd44e74319ba567affb0fcf223d1ee662bf8be280e736e54f44beec2f1e33aac9d537d7d7ae9ba155b049", + "78365ba55f66ac018aa8ca405bf11bcb93ce0bff44a528e9304be14f99dc4f84f08ce1679c9cf3d135dd56ade79881318833d69397ca55caa062c6214a0d4cff", }; return oldHashes.Contains(hash); diff --git a/src/ui/Forms/Main.cs b/src/ui/Forms/Main.cs index 8be29a93f..9030fc6a6 100644 --- a/src/ui/Forms/Main.cs +++ b/src/ui/Forms/Main.cs @@ -19025,6 +19025,19 @@ namespace Nikse.SubtitleEdit.Forms RunCustomSearch(Configuration.Settings.VideoControls.CustomSearchUrl5); e.SuppressKeyPress = true; } + else if (e.Modifiers == (Keys.Alt | Keys.Shift | Keys.Control) && e.KeyCode == Keys.T) + { + using (var form = new TextToSpeech(_subtitle, _videoFileName)) + { + if (form.ShowDialog(this) != DialogResult.OK) + { + return; + } + } + + e.SuppressKeyPress = true; + } + // put new entries above tabs diff --git a/src/ui/Forms/TextToSpeech.Designer.cs b/src/ui/Forms/TextToSpeech.Designer.cs new file mode 100644 index 000000000..d819778f5 --- /dev/null +++ b/src/ui/Forms/TextToSpeech.Designer.cs @@ -0,0 +1,104 @@ +namespace Nikse.SubtitleEdit.Forms +{ + partial class TextToSpeech + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonOK = new System.Windows.Forms.Button(); + this.labelDescription = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); + this.textBox1 = new Nikse.SubtitleEdit.Controls.NikseTextBox(); + this.SuspendLayout(); + // + // buttonOK + // + this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonOK.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.buttonOK.Location = new System.Drawing.Point(724, 407); + this.buttonOK.Name = "buttonOK"; + this.buttonOK.Size = new System.Drawing.Size(75, 23); + this.buttonOK.TabIndex = 7; + this.buttonOK.Text = "&OK"; + this.buttonOK.UseVisualStyleBackColor = true; + this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click); + // + // labelDescription + // + this.labelDescription.AutoSize = true; + this.labelDescription.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.labelDescription.Location = new System.Drawing.Point(9, 33); + this.labelDescription.Name = "labelDescription"; + this.labelDescription.Size = new System.Drawing.Size(76, 13); + this.labelDescription.TabIndex = 9; + this.labelDescription.Text = "Name of voice"; + // + // button1 + // + this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.button1.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.button1.Location = new System.Drawing.Point(12, 75); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 11; + this.button1.Text = "Go"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // textBox1 + // + this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBox1.FocusedColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215))))); + this.textBox1.Location = new System.Drawing.Point(12, 49); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(229, 20); + this.textBox1.TabIndex = 10; + this.textBox1.Text = "Hello, how are you?"; + // + // TextToSpeech + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(811, 442); + this.Controls.Add(this.button1); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.labelDescription); + this.Controls.Add(this.buttonOK); + this.Name = "TextToSpeech"; + this.Text = "TextToSpeach"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private System.Windows.Forms.Button buttonOK; + private Controls.NikseTextBox textBox1; + private System.Windows.Forms.Label labelDescription; + private System.Windows.Forms.Button button1; + } +} \ No newline at end of file diff --git a/src/ui/Forms/TextToSpeech.cs b/src/ui/Forms/TextToSpeech.cs new file mode 100644 index 000000000..32e75df05 --- /dev/null +++ b/src/ui/Forms/TextToSpeech.cs @@ -0,0 +1,39 @@ +using Nikse.SubtitleEdit.Logic; +using System; +using System.Speech.Synthesis; +using System.Windows.Forms; + +namespace Nikse.SubtitleEdit.Forms +{ + public partial class TextToSpeech : Form + { + public TextToSpeech(Core.Common.Subtitle subtitle, string videoFileName) + { + UiUtil.PreInitialize(this); + InitializeComponent(); + UiUtil.FixFonts(this); + + buttonOK.Text = LanguageSettings.Current.General.Ok; + UiUtil.FixLargeFonts(this, buttonOK); + } + + private void button1_Click(object sender, EventArgs e) + { + var text = textBox1.Text; + + using (SpeechSynthesizer synth = new SpeechSynthesizer()) + { + synth.SetOutputToWaveFile(@"C:\data\Sample.wav"); + synth.SelectVoiceByHints(VoiceGender.Male, VoiceAge.Adult); + var builder = new PromptBuilder(); + builder.AppendText(text); + synth.Speak(builder); + } + } + + private void buttonOK_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.OK; + } + } +} diff --git a/src/ui/Forms/TextToSpeech.resx b/src/ui/Forms/TextToSpeech.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/src/ui/Forms/TextToSpeech.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/src/ui/SubtitleEdit.csproj b/src/ui/SubtitleEdit.csproj index b9ddef421..b0d7bb4b0 100644 --- a/src/ui/SubtitleEdit.csproj +++ b/src/ui/SubtitleEdit.csproj @@ -92,6 +92,7 @@ ..\..\packages\System.Security.Principal.Windows.5.0.0\lib\net461\System.Security.Principal.Windows.dll + @@ -679,6 +680,12 @@ SeJobExport.cs + + Form + + + TextToSpeech.cs + Form @@ -1944,6 +1951,9 @@ AdjustTimingViaShotChanges.cs + + TextToSpeech.cs + TimedTextPropertiesImsc11.cs