From bbf6bff6ffecd02e72db20474f2f51d391b8f9da Mon Sep 17 00:00:00 2001 From: Besterquester Date: Wed, 18 Dec 2024 11:30:35 +0100 Subject: [PATCH 1/3] new timings --- src/ui/Forms/Tts/TextToSpeech.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/Forms/Tts/TextToSpeech.cs b/src/ui/Forms/Tts/TextToSpeech.cs index ae71818e2b..1869521372 100644 --- a/src/ui/Forms/Tts/TextToSpeech.cs +++ b/src/ui/Forms/Tts/TextToSpeech.cs @@ -758,7 +758,7 @@ private bool GenerateParagraphAudioPiperTts(Subtitle subtitle, bool showProgress } var p = subtitle.Paragraphs[index]; - if (string.IsNullOrWhiteSpace(p.Text)) + if (string.IsNullOrWhiteSpace(p.Text)) // p.Duration.TotalMilliseconds available for translation { continue; } From d02beab0acf989a1c18ecb9f5b16757c9f0112d3 Mon Sep 17 00:00:00 2001 From: Besterquester Date: Tue, 14 Jan 2025 13:31:07 +0100 Subject: [PATCH 2/3] VOice Over Function added --- src/ui/Forms/Tts/TextToSpeech.Designer.cs | 68 ++++++++--- src/ui/Forms/Tts/TextToSpeech.cs | 136 ++++++++++++++++++++-- src/ui/Logic/Language.cs | 2 +- src/ui/Logic/VideoPlayers/QuartsPlayer.cs | 1 + src/ui/Logic/VideoPreviewGenerator.cs | 25 ++++ src/ui/Properties/Settings.Designer.cs | 2 +- src/ui/SubtitleEdit.csproj | 9 ++ 7 files changed, 217 insertions(+), 26 deletions(-) diff --git a/src/ui/Forms/Tts/TextToSpeech.Designer.cs b/src/ui/Forms/Tts/TextToSpeech.Designer.cs index c81d25f049..b6e40674c5 100644 --- a/src/ui/Forms/Tts/TextToSpeech.Designer.cs +++ b/src/ui/Forms/Tts/TextToSpeech.Designer.cs @@ -35,6 +35,7 @@ private void InitializeComponent() this.progressBar1 = new System.Windows.Forms.ProgressBar(); this.labelEngine = new System.Windows.Forms.Label(); this.groupBoxSettings = new System.Windows.Forms.GroupBox(); + this.checkBox_AdjustAudio = new System.Windows.Forms.CheckBox(); this.labelLanguage = new System.Windows.Forms.Label(); this.linkLabelCustomAudio = new System.Windows.Forms.LinkLabel(); this.checkBoxAudioEncoding = new System.Windows.Forms.CheckBox(); @@ -53,6 +54,7 @@ private void InitializeComponent() this.contextMenuStripActors = new System.Windows.Forms.ContextMenuStrip(this.components); this.labelActors = new System.Windows.Forms.Label(); this.buttonCancel = new System.Windows.Forms.Button(); + this.chkusePiper2Pass = new System.Windows.Forms.CheckBox(); this.nikseUpDownStability = new Nikse.SubtitleEdit.Controls.NikseUpDown(); this.nikseUpDownSimilarity = new Nikse.SubtitleEdit.Controls.NikseUpDown(); this.labelSimilarity = new Nikse.SubtitleEdit.Controls.NikseLabel(); @@ -63,6 +65,7 @@ private void InitializeComponent() this.TextBoxTest = new Nikse.SubtitleEdit.Controls.NikseTextBox(); this.nikseComboBoxVoice = new Nikse.SubtitleEdit.Controls.NikseComboBox(); this.nikseComboBoxEngine = new Nikse.SubtitleEdit.Controls.NikseComboBox(); + this.chkVoiceOver = new System.Windows.Forms.CheckBox(); this.groupBoxSettings.SuspendLayout(); this.contextMenuStripVoices.SuspendLayout(); this.SuspendLayout(); @@ -71,7 +74,7 @@ private void InitializeComponent() // 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(720, 486); + this.buttonOK.Location = new System.Drawing.Point(676, 478); this.buttonOK.Name = "buttonOK"; this.buttonOK.Size = new System.Drawing.Size(75, 23); this.buttonOK.TabIndex = 100; @@ -84,7 +87,7 @@ private void InitializeComponent() this.labelProgress.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.labelProgress.AutoSize = true; this.labelProgress.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.labelProgress.Location = new System.Drawing.Point(12, 463); + this.labelProgress.Location = new System.Drawing.Point(12, 455); this.labelProgress.Name = "labelProgress"; this.labelProgress.Size = new System.Drawing.Size(70, 13); this.labelProgress.TabIndex = 9; @@ -94,7 +97,7 @@ private void InitializeComponent() // this.buttonGenerateTTS.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonGenerateTTS.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonGenerateTTS.Location = new System.Drawing.Point(648, 453); + this.buttonGenerateTTS.Location = new System.Drawing.Point(604, 445); this.buttonGenerateTTS.Name = "buttonGenerateTTS"; this.buttonGenerateTTS.Size = new System.Drawing.Size(228, 23); this.buttonGenerateTTS.TabIndex = 90; @@ -106,9 +109,9 @@ private void InitializeComponent() // this.progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.progressBar1.Location = new System.Drawing.Point(12, 486); + this.progressBar1.Location = new System.Drawing.Point(12, 478); this.progressBar1.Name = "progressBar1"; - this.progressBar1.Size = new System.Drawing.Size(699, 10); + this.progressBar1.Size = new System.Drawing.Size(655, 10); this.progressBar1.TabIndex = 12; // // labelEngine @@ -125,6 +128,9 @@ private void InitializeComponent() // this.groupBoxSettings.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); + this.groupBoxSettings.Controls.Add(this.chkVoiceOver); + this.groupBoxSettings.Controls.Add(this.chkusePiper2Pass); + this.groupBoxSettings.Controls.Add(this.checkBox_AdjustAudio); this.groupBoxSettings.Controls.Add(this.nikseUpDownStability); this.groupBoxSettings.Controls.Add(this.nikseUpDownSimilarity); this.groupBoxSettings.Controls.Add(this.labelSimilarity); @@ -148,11 +154,22 @@ private void InitializeComponent() this.groupBoxSettings.Controls.Add(this.nikseComboBoxEngine); this.groupBoxSettings.Location = new System.Drawing.Point(15, 12); this.groupBoxSettings.Name = "groupBoxSettings"; - this.groupBoxSettings.Size = new System.Drawing.Size(391, 435); + this.groupBoxSettings.Size = new System.Drawing.Size(391, 427); this.groupBoxSettings.TabIndex = 1; this.groupBoxSettings.TabStop = false; this.groupBoxSettings.Text = "Settings"; // + // checkBox_AdjustAudio + // + this.checkBox_AdjustAudio.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.checkBox_AdjustAudio.AutoSize = true; + this.checkBox_AdjustAudio.Location = new System.Drawing.Point(214, 344); + this.checkBox_AdjustAudio.Name = "checkBox_AdjustAudio"; + this.checkBox_AdjustAudio.Size = new System.Drawing.Size(127, 17); + this.checkBox_AdjustAudio.TabIndex = 105; + this.checkBox_AdjustAudio.Text = "Adapt speed (ffmpeg)"; + this.checkBox_AdjustAudio.UseVisualStyleBackColor = true; + // // labelLanguage // this.labelLanguage.AutoSize = true; @@ -167,7 +184,7 @@ private void InitializeComponent() // this.linkLabelCustomAudio.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.linkLabelCustomAudio.AutoSize = true; - this.linkLabelCustomAudio.Location = new System.Drawing.Point(168, 400); + this.linkLabelCustomAudio.Location = new System.Drawing.Point(47, 408); this.linkLabelCustomAudio.Name = "linkLabelCustomAudio"; this.linkLabelCustomAudio.Size = new System.Drawing.Size(45, 13); this.linkLabelCustomAudio.TabIndex = 43; @@ -179,7 +196,7 @@ private void InitializeComponent() // this.checkBoxAudioEncoding.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.checkBoxAudioEncoding.AutoSize = true; - this.checkBoxAudioEncoding.Location = new System.Drawing.Point(32, 401); + this.checkBoxAudioEncoding.Location = new System.Drawing.Point(30, 388); this.checkBoxAudioEncoding.Name = "checkBoxAudioEncoding"; this.checkBoxAudioEncoding.Size = new System.Drawing.Size(137, 17); this.checkBoxAudioEncoding.TabIndex = 42; @@ -212,7 +229,7 @@ private void InitializeComponent() this.checkBoxShowPreview.AutoSize = true; this.checkBoxShowPreview.Checked = true; this.checkBoxShowPreview.CheckState = System.Windows.Forms.CheckState.Checked; - this.checkBoxShowPreview.Location = new System.Drawing.Point(17, 352); + this.checkBoxShowPreview.Location = new System.Drawing.Point(17, 344); this.checkBoxShowPreview.Name = "checkBoxShowPreview"; this.checkBoxShowPreview.Size = new System.Drawing.Size(115, 17); this.checkBoxShowPreview.TabIndex = 40; @@ -245,7 +262,7 @@ private void InitializeComponent() this.checkBoxAddToVideoFile.AutoSize = true; this.checkBoxAddToVideoFile.Checked = true; this.checkBoxAddToVideoFile.CheckState = System.Windows.Forms.CheckState.Checked; - this.checkBoxAddToVideoFile.Location = new System.Drawing.Point(17, 376); + this.checkBoxAddToVideoFile.Location = new System.Drawing.Point(17, 368); this.checkBoxAddToVideoFile.Name = "checkBoxAddToVideoFile"; this.checkBoxAddToVideoFile.Size = new System.Drawing.Size(176, 17); this.checkBoxAddToVideoFile.TabIndex = 41; @@ -291,7 +308,7 @@ private void InitializeComponent() this.listViewActors.HideSelection = false; this.listViewActors.Location = new System.Drawing.Point(412, 42); this.listViewActors.Name = "listViewActors"; - this.listViewActors.Size = new System.Drawing.Size(464, 405); + this.listViewActors.Size = new System.Drawing.Size(420, 397); this.listViewActors.TabIndex = 40; this.listViewActors.UseCompatibleStateImageBehavior = false; this.listViewActors.View = System.Windows.Forms.View.Details; @@ -326,7 +343,7 @@ private void InitializeComponent() this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.buttonCancel.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonCancel.Location = new System.Drawing.Point(801, 486); + this.buttonCancel.Location = new System.Drawing.Point(757, 478); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(75, 23); this.buttonCancel.TabIndex = 101; @@ -334,6 +351,17 @@ private void InitializeComponent() this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); // + // chkusePiper2Pass + // + this.chkusePiper2Pass.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.chkusePiper2Pass.AutoSize = true; + this.chkusePiper2Pass.Location = new System.Drawing.Point(214, 367); + this.chkusePiper2Pass.Name = "chkusePiper2Pass"; + this.chkusePiper2Pass.Size = new System.Drawing.Size(171, 17); + this.chkusePiper2Pass.TabIndex = 106; + this.chkusePiper2Pass.Text = "2 pass speed correction (piper)"; + this.chkusePiper2Pass.UseVisualStyleBackColor = true; + // // nikseUpDownStability // this.nikseUpDownStability.BackColor = System.Drawing.SystemColors.Window; @@ -554,11 +582,22 @@ private void InitializeComponent() this.nikseComboBoxEngine.Text = "nikseComboBox1"; this.nikseComboBoxEngine.UsePopupWindow = false; // + // chkVoiceOver + // + this.chkVoiceOver.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.chkVoiceOver.AutoSize = true; + this.chkVoiceOver.Location = new System.Drawing.Point(214, 390); + this.chkVoiceOver.Name = "chkVoiceOver"; + this.chkVoiceOver.Size = new System.Drawing.Size(93, 17); + this.chkVoiceOver.TabIndex = 107; + this.chkVoiceOver.Text = "use voiceover"; + this.chkVoiceOver.UseVisualStyleBackColor = true; + // // TextToSpeech // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(888, 521); + this.ClientSize = new System.Drawing.Size(844, 513); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.labelActors); this.Controls.Add(this.listViewActors); @@ -623,5 +662,8 @@ private void InitializeComponent() private Controls.NikseUpDown nikseUpDownSimilarity; private Controls.NikseLabel labelSimilarity; private Controls.NikseLabel labelStability; + private System.Windows.Forms.CheckBox checkBox_AdjustAudio; + private System.Windows.Forms.CheckBox chkusePiper2Pass; + private System.Windows.Forms.CheckBox chkVoiceOver; } } \ No newline at end of file diff --git a/src/ui/Forms/Tts/TextToSpeech.cs b/src/ui/Forms/Tts/TextToSpeech.cs index 1869521372..a4716fcd60 100644 --- a/src/ui/Forms/Tts/TextToSpeech.cs +++ b/src/ui/Forms/Tts/TextToSpeech.cs @@ -395,6 +395,8 @@ private bool GenerateParagraphAudio(Subtitle subtitle, bool showProgressBar, str private void AddAudioToVideoFile(string audioFileName) { + + Process addAudioProcess; var videoExt = ".mkv"; if (_videoFileName.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase)) { @@ -415,8 +417,16 @@ private void AddAudioToVideoFile(string audioFileName) { stereo = true; } + if (chkVoiceOver.Checked) + { + addAudioProcess = VideoPreviewGenerator.AddVoiceOver(_videoFileName, audioFileName, outputFileName, audioEncoding, stereo); + + } + else + { + addAudioProcess = VideoPreviewGenerator.AddAudioTrack(_videoFileName, audioFileName, outputFileName, audioEncoding, stereo); + } - var addAudioProcess = VideoPreviewGenerator.AddAudioTrack(_videoFileName, audioFileName, outputFileName, audioEncoding, stereo); addAudioProcess.Start(); while (!addAudioProcess.HasExited) { @@ -452,7 +462,10 @@ private static void Cleanup(string waveFolder, string resultAudioFile) private List FixParagraphAudioSpeed(Subtitle subtitle, string overrideFileName) { var fileNames = new List(subtitle.Paragraphs.Count); - + //if (!checkBox_AdjustAudio.Checked) + //{ + // return fileNames; + //} labelProgress.Text = string.Empty; labelProgress.Refresh(); Application.DoEvents(); @@ -462,14 +475,23 @@ private List FixParagraphAudioSpeed(Subtitle subtitle, s progressBar1.Visible = true; const string ext = ".wav"; + for (var index = 0; index < subtitle.Paragraphs.Count; index++) { progressBar1.Value = index + 1; - labelProgress.Text = string.Format(LanguageSettings.Current.TextToSpeech.AdjustingSpeedXOfY, index + 1, subtitle.Paragraphs.Count); + labelProgress.Text = string.Format(LanguageSettings.Current.TextToSpeech.AdjustingSpeedXOfY, index + 1, subtitle.Paragraphs.Count, 1.0); + var p = subtitle.Paragraphs[index]; + var pFileName = Path.Combine(_waveFolder, index + ".wav"); + + if (!checkBox_AdjustAudio.Checked) + { + fileNames.Add(new FileNameAndSpeedFactor { Filename = pFileName, Factor = 1 }); + continue; + } + var next = subtitle.GetParagraphOrDefault(index + 1); - var pFileName = Path.Combine(_waveFolder, index + ".wav"); if (!string.IsNullOrEmpty(overrideFileName) && File.Exists(Path.Combine(_waveFolder, overrideFileName))) { pFileName = Path.Combine(_waveFolder, overrideFileName); @@ -524,12 +546,16 @@ private List FixParagraphAudioSpeed(Subtitle subtitle, s } var waveInfo = UiUtil.GetVideoInfo(outputFileName1); - if (waveInfo.TotalMilliseconds <= p.DurationTotalMilliseconds + addDuration) + if (!checkBox_AdjustAudio.Checked) { - fileNames.Add(new FileNameAndSpeedFactor { Filename = outputFileName1, Factor = 1 }); - continue; + if (waveInfo.TotalMilliseconds <= p.DurationTotalMilliseconds + addDuration) + { + fileNames.Add(new FileNameAndSpeedFactor { Filename = outputFileName1, Factor = 1 }); + continue; + } } + var divisor = (decimal)(p.DurationTotalMilliseconds + addDuration); if (divisor <= 0) { @@ -539,12 +565,23 @@ private List FixParagraphAudioSpeed(Subtitle subtitle, s } var factor = (decimal)waveInfo.TotalMilliseconds / divisor; + var outputFileName2 = Path.Combine(_waveFolder, $"{index}_{Guid.NewGuid()}{ext}"); if (!string.IsNullOrEmpty(overrideFileName) && File.Exists(Path.Combine(_waveFolder, overrideFileName))) { outputFileName2 = Path.Combine(_waveFolder, $"{Path.GetFileNameWithoutExtension(overrideFileName)}_{Guid.NewGuid()}{ext}"); } + if (factor <= (decimal)0.8) + { + factor = (decimal)0.8; + } + if (factor >= (decimal)1.5) + { + factor = (decimal)1.5; + } + labelProgress.Text = string.Format(LanguageSettings.Current.TextToSpeech.AdjustingSpeedXOfY, index + 1, subtitle.Paragraphs.Count, (double)factor); + fileNames.Add(new FileNameAndSpeedFactor { Filename = outputFileName2, Factor = factor }); var mergeProcess = VideoPreviewGenerator.ChangeSpeed(outputFileName1, outputFileName2, (float)factor); mergeProcess.Start(); @@ -714,6 +751,11 @@ private void GenerateParagraphAudioMs(Subtitle subtitle, bool showProgressBar, s } private bool GenerateParagraphAudioPiperTts(Subtitle subtitle, bool showProgressBar, string overrideFileName) + { + return GenerateParagraphAudioPiperTts(subtitle, showProgressBar, overrideFileName, true); + } + + private bool GenerateParagraphAudioPiperTts(Subtitle subtitle, bool showProgressBar, string overrideFileName, bool twopass) { var ttsPath = Path.Combine(Configuration.DataDirectory, "TextToSpeech"); if (!Directory.Exists(ttsPath)) @@ -803,13 +845,15 @@ private bool GenerateParagraphAudioPiperTts(Subtitle subtitle, bool showProgress } } + + var processPiper = new Process { StartInfo = { WorkingDirectory = piperPath, FileName = Configuration.IsRunningOnWindows ? piperExe : "piper", - Arguments = $"-m \"{voice.ModelShort}\" -c \"{voice.ConfigShort}\" -f out.wav", + Arguments = $"-m \"{voice.ModelShort}\" -c \"{voice.ConfigShort}\" -f out.wav ", // --rate {1.5} --cuda --sentence_silence 0.5// Put the speed as parameter here also UseShellExecute = false, CreateNoWindow = true, RedirectStandardInput = true, @@ -835,6 +879,76 @@ private bool GenerateParagraphAudioPiperTts(Subtitle subtitle, bool showProgress } var inputFile = Path.Combine(piperPath, "out.wav"); + + // ************ CHANGE ************** + // implement a second pass. take the duration of the generated wav out.wav and + // adpat the factor by using the lenght_scale parameter of piper. This will genrate more realistic results than the speed adaption using ffmpeg ;) + // + if (chkusePiper2Pass.Checked) + { + var waveInfo = UiUtil.GetVideoInfo(inputFile); + + var divisor = (decimal)(p.DurationTotalMilliseconds); + if (divisor <= 0) + { + continue; + + } + var factor = divisor / (decimal)waveInfo.TotalMilliseconds; + + File.Delete(inputFile); + + if (factor <= (decimal)0.5) + { + factor = (decimal)0.5; + } + if (factor >= (decimal)1.5) + { + factor = (decimal)1.5; + } + + string strFactor = factor.ToString("F2").Replace(",", "."); + var processPiper2 = new Process + { + StartInfo = + { + WorkingDirectory = piperPath, + FileName = Configuration.IsRunningOnWindows ? piperExe : "piper", + Arguments = $"-m \"{voice.ModelShort}\" -c \"{voice.ConfigShort}\" -f out.wav --length_scale {strFactor}", // --rate {1.5} --cuda --sentence_silence 0.5// Put the speed as parameter here also + UseShellExecute = false, + CreateNoWindow = true, + RedirectStandardInput = true, + } + }; + + processPiper2.Start(); + streamWriter = new StreamWriter(processPiper2.StandardInput.BaseStream, Encoding.UTF8); + text = Utilities.UnbreakLine(p.Text); + streamWriter.Write(text); + streamWriter.Flush(); + streamWriter.Close(); + + while (!processPiper2.HasExited) + { + Application.DoEvents(); + if (_abort) + { + progressBar1.Visible = false; + labelProgress.Text = string.Empty; + return false; + } + } + + } + + // ********** + + //var inputFile1 = Path.Combine(piperPath, "out2.wav"); + + //if (!File.Exists(inputFile)) + //{ + // int h = 0; + //} File.Move(inputFile, outputFileName); progressBar1.Refresh(); @@ -1137,7 +1251,7 @@ private bool GenerateParagraphAudioElevenLabs(Subtitle subtitle, bool showProgre } } - var stability = Math.Round(Configuration.Settings.Tools.TextToSpeechElevenLabsStability, 1).ToString(CultureInfo.InvariantCulture); + var stability = Math.Round(Configuration.Settings.Tools.TextToSpeechElevenLabsStability, 1).ToString(CultureInfo.InvariantCulture); var similarity = Math.Round(Configuration.Settings.Tools.TextToSpeechElevenLabsSimilarity, 1).ToString(CultureInfo.InvariantCulture); var data = "{ \"text\": \"" + Json.EncodeJsonText(text) + $"\", \"model_id\": \"{model}\"{language}, \"voice_settings\": {{ \"stability\": {stability}, \"similarity_boost\": {similarity} }} }}"; var content = new StringContent(data, Encoding.UTF8); @@ -2132,7 +2246,7 @@ private List GetAllTalkVoices(bool useCache) if (!useCache) { - using(var httpClient = new HttpClient()) + using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json"); httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json"); @@ -2493,7 +2607,7 @@ private void linkLabelCustomAudio_LinkClicked(object sender, LinkLabelLinkClicke { using (var form = new TtsAudioEncoding()) { - form.ShowDialog(this); + form.ShowDialog(this); } } diff --git a/src/ui/Logic/Language.cs b/src/ui/Logic/Language.cs index 9935e99794..93cfc1d1b8 100644 --- a/src/ui/Logic/Language.cs +++ b/src/ui/Logic/Language.cs @@ -3576,7 +3576,7 @@ can edit in same subtitle file (collaboration)", ActorInfo = "Right-click to assign actor to voice", AddAudioToVideo = "Add audio to video file (new file)", GenerateSpeech = "Generate speech from text", - AdjustingSpeedXOfY = "Adjusting speed: {0} / {1}...", + AdjustingSpeedXOfY = "Adjusting speed,: {0} / {1} factor {2:F1}...", MergingAudioTrackXOfY = "Merging audio track: {0} / {1}...", GeneratingSpeechFromTextXOfY = "Generating speech from text: {0} / {1}...", ReviewAudioClips = "Review audio clips", diff --git a/src/ui/Logic/VideoPlayers/QuartsPlayer.cs b/src/ui/Logic/VideoPlayers/QuartsPlayer.cs index 3c80974064..fcb625df5a 100644 --- a/src/ui/Logic/VideoPlayers/QuartsPlayer.cs +++ b/src/ui/Logic/VideoPlayers/QuartsPlayer.cs @@ -232,6 +232,7 @@ public static VideoInfo GetVideoInfo(string videoFileName) } catch { + // ignored } diff --git a/src/ui/Logic/VideoPreviewGenerator.cs b/src/ui/Logic/VideoPreviewGenerator.cs index 1e3916d2b7..fd12062bfe 100644 --- a/src/ui/Logic/VideoPreviewGenerator.cs +++ b/src/ui/Logic/VideoPreviewGenerator.cs @@ -651,6 +651,31 @@ public static Process AddAudioTrack(string inputFileName, string audioFileName, return processMakeVideo; } + // new method for creating a voice over + // + public static Process AddVoiceOver(string inputFileName, string audioFileName, string outputFileName, string audioEncoding, bool? stereo, DataReceivedEventHandler dataReceivedHandler = null) + { + // ffmpeg -i original.mkv -i voiceover1.wav -filter_complex "[1:a]asplit=2[sc][mix];[0:a]apad[bg_padded];[bg_padded][sc]sidechaincompress=threshold=0.02:ratio=4:attack=100:release=500[bg];[bg][mix]amerge=inputs=2,pan=stereo|c0 Component + + True + True + Settings.settings + @@ -84,6 +89,10 @@ + + SettingsSingleFileGenerator + Settings.Designer.cs + Designer From 5ddf4eeff688d8404d4defa34b219e286ab362b5 Mon Sep 17 00:00:00 2001 From: Besterquester Date: Sun, 2 Feb 2025 13:41:41 +0100 Subject: [PATCH 3/3] Update TextToSpeech.cs --- src/ui/Forms/Tts/TextToSpeech.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ui/Forms/Tts/TextToSpeech.cs b/src/ui/Forms/Tts/TextToSpeech.cs index a4716fcd60..69fcdbfa42 100644 --- a/src/ui/Forms/Tts/TextToSpeech.cs +++ b/src/ui/Forms/Tts/TextToSpeech.cs @@ -417,10 +417,9 @@ private void AddAudioToVideoFile(string audioFileName) { stereo = true; } - if (chkVoiceOver.Checked) + if (chkVoiceOver.Checked) // added { addAudioProcess = VideoPreviewGenerator.AddVoiceOver(_videoFileName, audioFileName, outputFileName, audioEncoding, stereo); - } else {