From 13c9c4cdbe911a6c3e36d1be44f44fe7305cbf2f Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Fri, 10 May 2024 15:39:55 +0200 Subject: [PATCH] Add force stereo --- src/ui/Forms/Tts/TextToSpeech.Designer.cs | 20 ++++++++++++++++++-- src/ui/Forms/Tts/TextToSpeech.cs | 8 ++++---- src/ui/Logic/VideoPreviewGenerator.cs | 6 ++++-- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/ui/Forms/Tts/TextToSpeech.Designer.cs b/src/ui/Forms/Tts/TextToSpeech.Designer.cs index 937e3227c..449de197a 100644 --- a/src/ui/Forms/Tts/TextToSpeech.Designer.cs +++ b/src/ui/Forms/Tts/TextToSpeech.Designer.cs @@ -35,6 +35,7 @@ this.progressBar1 = new System.Windows.Forms.ProgressBar(); this.labelEngine = new System.Windows.Forms.Label(); this.groupBoxSettings = new System.Windows.Forms.GroupBox(); + this.checkBoxForceStereo = new System.Windows.Forms.CheckBox(); this.labelRegion = new System.Windows.Forms.Label(); this.nikseComboBoxRegion = new Nikse.SubtitleEdit.Controls.NikseComboBox(); this.labelVoiceCount = new System.Windows.Forms.Label(); @@ -117,6 +118,7 @@ // 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.checkBoxForceStereo); this.groupBoxSettings.Controls.Add(this.labelRegion); this.groupBoxSettings.Controls.Add(this.nikseComboBoxRegion); this.groupBoxSettings.Controls.Add(this.labelVoiceCount); @@ -137,6 +139,19 @@ this.groupBoxSettings.TabStop = false; this.groupBoxSettings.Text = "Settings"; // + // checkBoxForceStereo + // + this.checkBoxForceStereo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.checkBoxForceStereo.AutoSize = true; + this.checkBoxForceStereo.Checked = true; + this.checkBoxForceStereo.CheckState = System.Windows.Forms.CheckState.Checked; + this.checkBoxForceStereo.Location = new System.Drawing.Point(34, 382); + this.checkBoxForceStereo.Name = "checkBoxForceStereo"; + this.checkBoxForceStereo.Size = new System.Drawing.Size(85, 17); + this.checkBoxForceStereo.TabIndex = 33; + this.checkBoxForceStereo.Text = "Force stereo"; + this.checkBoxForceStereo.UseVisualStyleBackColor = true; + // // labelRegion // this.labelRegion.AutoSize = true; @@ -188,7 +203,7 @@ this.checkBoxShowPreview.AutoSize = true; this.checkBoxShowPreview.Checked = true; this.checkBoxShowPreview.CheckState = System.Windows.Forms.CheckState.Checked; - this.checkBoxShowPreview.Location = new System.Drawing.Point(17, 350); + this.checkBoxShowPreview.Location = new System.Drawing.Point(17, 335); this.checkBoxShowPreview.Name = "checkBoxShowPreview"; this.checkBoxShowPreview.Size = new System.Drawing.Size(115, 17); this.checkBoxShowPreview.TabIndex = 25; @@ -243,7 +258,7 @@ this.checkBoxAddToVideoFile.AutoSize = true; this.checkBoxAddToVideoFile.Checked = true; this.checkBoxAddToVideoFile.CheckState = System.Windows.Forms.CheckState.Checked; - this.checkBoxAddToVideoFile.Location = new System.Drawing.Point(17, 373); + this.checkBoxAddToVideoFile.Location = new System.Drawing.Point(17, 358); this.checkBoxAddToVideoFile.Name = "checkBoxAddToVideoFile"; this.checkBoxAddToVideoFile.Size = new System.Drawing.Size(176, 17); this.checkBoxAddToVideoFile.TabIndex = 26; @@ -446,5 +461,6 @@ private Controls.NikseComboBox nikseComboBoxRegion; private System.Windows.Forms.ContextMenuStrip contextMenuStripVoices; private System.Windows.Forms.ToolStripMenuItem refreshVoicesToolStripMenuItem; + private System.Windows.Forms.CheckBox checkBoxForceStereo; } } \ No newline at end of file diff --git a/src/ui/Forms/Tts/TextToSpeech.cs b/src/ui/Forms/Tts/TextToSpeech.cs index a2de961f4..d127aa2a9 100644 --- a/src/ui/Forms/Tts/TextToSpeech.cs +++ b/src/ui/Forms/Tts/TextToSpeech.cs @@ -181,6 +181,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts checkBoxShowPreview.Checked = Configuration.Settings.Tools.TextToSpeechPreview; checkBoxAddToVideoFile.Enabled = _videoFileName != null; + checkBoxForceStereo.Enabled = _videoFileName != null; } private void SetActor(ActorAndVoice actor) @@ -215,7 +216,6 @@ namespace Nikse.SubtitleEdit.Forms.Tts private void ButtonGenerateTtsClick(object sender, EventArgs e) { - if (buttonGenerateTTS.Text == LanguageSettings.Current.General.Cancel) { buttonGenerateTTS.Enabled = false; @@ -297,7 +297,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts if (checkBoxAddToVideoFile.Checked && _videoFileName != null) { - AddAudioToVideoFile(resultAudioFileName); + AddAudioToVideoFile(resultAudioFileName, checkBoxForceStereo.Checked); if (_abort) { HandleAbort(); @@ -378,7 +378,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts return false; } - private void AddAudioToVideoFile(string audioFileName) + private void AddAudioToVideoFile(string audioFileName, bool forceStereo) { var videoExt = ".mkv"; if (_videoFileName.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase)) @@ -388,7 +388,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts labelProgress.Text = "Add audio to video file..."; var outputFileName = Path.Combine(_waveFolder, Path.GetFileNameWithoutExtension(audioFileName) + videoExt); - var addAudioProcess = VideoPreviewGenerator.AddAudioTrack(_videoFileName, audioFileName, outputFileName); + var addAudioProcess = VideoPreviewGenerator.AddAudioTrack(_videoFileName, audioFileName, outputFileName, forceStereo); addAudioProcess.Start(); while (!addAudioProcess.HasExited) { diff --git a/src/ui/Logic/VideoPreviewGenerator.cs b/src/ui/Logic/VideoPreviewGenerator.cs index d24160279..4cc82939e 100644 --- a/src/ui/Logic/VideoPreviewGenerator.cs +++ b/src/ui/Logic/VideoPreviewGenerator.cs @@ -626,14 +626,16 @@ namespace Nikse.SubtitleEdit.Logic return processMakeVideo; } - public static Process AddAudioTrack(string inputFileName, string audioFileName, string outputFileName, DataReceivedEventHandler dataReceivedHandler = null) + public static Process AddAudioTrack(string inputFileName, string audioFileName, string outputFileName, bool forceStereo, DataReceivedEventHandler dataReceivedHandler = null) { + var ac2 = forceStereo ? " -ac 2 " : " "; + var processMakeVideo = new Process { StartInfo = { FileName = GetFfmpegLocation(), - Arguments = $"-i \"{inputFileName}\" -i \"{audioFileName}\" -c copy -map 0:v:0 -map 1:a:0 \"{outputFileName}\"", + Arguments = $"-i \"{inputFileName}\" -i \"{audioFileName}\" -c copy -map 0:v:0 -map 1:a:0{ac2}\"{outputFileName}\"", UseShellExecute = false, CreateNoWindow = true }