Add "audio to text selected lines" shortcuts

This commit is contained in:
niksedk 2023-01-01 19:03:06 +01:00
parent b5f743740e
commit deae277796
9 changed files with 124 additions and 70 deletions

View File

@ -9,6 +9,7 @@
* Add new subtitle format - thx Christophe
* Add new subtitle format - thx Chris
* Add ASSA style "Replace" - thxMishasama
* Add "audio to text selected lines" shortcuts
* IMPROVED:
* Update Chinese translation - thx nkh0472
* Update Korean translation - thx domddol

View File

@ -2519,7 +2519,8 @@ can edit in same subtitle file (collaboration)</Information>
<VideoResetSpeedAndZoom>Reset play rate (speed) and waveform zoom</VideoResetSpeedAndZoom>
<MainToggleVideoControls>Toggle video controls</MainToggleVideoControls>
<VideoToggleContrast>Toggle contrast (mpv only)</VideoToggleContrast>
<VideoAudioToText>Audio to text</VideoAudioToText>
<AudioToTextX>Audio to text ({0})</AudioToTextX>
<AudioToTextSelectedLinesX>Audio to text selected lines ({0})</AudioToTextSelectedLinesX>
<VideoToggleBrightness>Toggle brightness (mpv only)</VideoToggleBrightness>
<CustomSearch1>Translate, custom search 1</CustomSearch1>
<CustomSearch2>Translate, custom search 2</CustomSearch2>

View File

@ -2362,7 +2362,8 @@ $HorzAlign = Center
public string MainVideoReset { get; set; }
public string MainVideoToggleBrightness { get; set; }
public string MainVideoToggleContrast { get; set; }
public string MainVideoAudioToText { get; set; }
public string MainVideoAudioToTextVosk { get; set; }
public string MainVideoAudioToTextWhisper { get; set; }
// spell check
public string MainSpellCheck { get; set; }
@ -2538,6 +2539,8 @@ $HorzAlign = Center
public string Waveform100MsRight { get; set; }
public string Waveform1000MsLeft { get; set; }
public string Waveform1000MsRight { get; set; }
public string WaveformAudioToTextVosk { get; set; }
public string WaveformAudioToTextWhisper { get; set; }
public string MainCheckFixTimingViaShotChanges { get; set; }
public string MainTranslateGoogleIt { get; set; }
public string MainTranslateGoogleTranslateIt { get; set; }
@ -8787,10 +8790,16 @@ $HorzAlign = Center
shortcuts.MainVideoToggleContrast = subNode.InnerText;
}
subNode = node.SelectSingleNode("MainVideoAudioToText");
subNode = node.SelectSingleNode("MainVideoAudioToTextVosk");
if (subNode != null)
{
shortcuts.MainVideoAudioToText = subNode.InnerText;
shortcuts.MainVideoAudioToTextVosk = subNode.InnerText;
}
subNode = node.SelectSingleNode("MainVideoAudioToTextWhisper");
if (subNode != null)
{
shortcuts.MainVideoAudioToTextWhisper = subNode.InnerText;
}
subNode = node.SelectSingleNode("MainSpellCheck");
@ -9861,6 +9870,18 @@ $HorzAlign = Center
shortcuts.Waveform1000MsRight = subNode.InnerText;
}
subNode = node.SelectSingleNode("WaveformAudioToTextVosk");
if (subNode != null)
{
shortcuts.WaveformAudioToTextVosk = subNode.InnerText;
}
subNode = node.SelectSingleNode("WaveformAudioToTextWhisper");
if (subNode != null)
{
shortcuts.WaveformAudioToTextWhisper = subNode.InnerText;
}
subNode = node.SelectSingleNode("MainCheckFixTimingViaShotChanges");
if (subNode != null)
{
@ -11107,7 +11128,8 @@ $HorzAlign = Center
textWriter.WriteElementString("MainVideoReset", shortcuts.MainVideoReset);
textWriter.WriteElementString("MainVideoToggleBrightness", shortcuts.MainVideoToggleBrightness);
textWriter.WriteElementString("MainVideoToggleContrast", shortcuts.MainVideoToggleContrast);
textWriter.WriteElementString("MainVideoAudioToText", shortcuts.MainVideoAudioToText);
textWriter.WriteElementString("MainVideoAudioToTextVosk", shortcuts.MainVideoAudioToTextVosk);
textWriter.WriteElementString("MainVideoAudioToTextWhisper", shortcuts.MainVideoAudioToTextWhisper);
textWriter.WriteElementString("MainSpellCheck", shortcuts.MainSpellCheck);
textWriter.WriteElementString("MainSpellCheckFindDoubleWords", shortcuts.MainSpellCheckFindDoubleWords);
textWriter.WriteElementString("MainSpellCheckAddWordToNames", shortcuts.MainSpellCheckAddWordToNames);
@ -11285,6 +11307,8 @@ $HorzAlign = Center
textWriter.WriteElementString("Waveform100MsRight", shortcuts.Waveform100MsRight);
textWriter.WriteElementString("Waveform1000MsLeft", shortcuts.Waveform1000MsLeft);
textWriter.WriteElementString("Waveform1000MsRight", shortcuts.Waveform1000MsRight);
textWriter.WriteElementString("WaveformAudioToTextVosk", shortcuts.WaveformAudioToTextVosk);
textWriter.WriteElementString("WaveformAudioToTextWhisper", shortcuts.WaveformAudioToTextWhisper);
textWriter.WriteElementString("MainCheckFixTimingViaShotChanges", shortcuts.MainCheckFixTimingViaShotChanges);
textWriter.WriteElementString("MainTranslateGoogleIt", shortcuts.MainTranslateGoogleIt);
textWriter.WriteElementString("MainTranslateGoogleTranslateIt", shortcuts.MainTranslateGoogleTranslateIt);

View File

@ -8883,66 +8883,9 @@ namespace Nikse.SubtitleEdit.Forms
UiUtil.OpenFolder(Path.GetDirectoryName(audioClips[0].AudioFileName));
};
audioToTextWhisper.Click += (senderNew, eNew) =>
{
if (!RequireFfmpegOk())
{
return;
}
audioToTextWhisper.Click += (senderNew, eNew) => { AudioToTextWhisperSelectedLines(); };
var audioClips = GetAudioClips();
using (var form = new WhisperAudioToTextSelectedLines(audioClips, this))
{
CheckWhisperCpp();
if (form.ShowDialog(this) == DialogResult.OK)
{
MakeHistoryForUndo(string.Format(_language.BeforeX, string.Format(LanguageSettings.Current.Main.Menu.Video.VideoAudioToTextX, "Whisper")));
SubtitleListview1.BeginUpdate();
foreach (var ac in audioClips)
{
var p = _subtitle.Paragraphs.FirstOrDefault(pa => pa.Id == ac.Paragraph.Id);
if (p != null)
{
p.Text = ac.Paragraph.Text;
var idx = _subtitle.Paragraphs.IndexOf(p);
SubtitleListview1.SetText(idx, p.Text);
}
}
SubtitleListview1.EndUpdate();
RefreshSelectedParagraph();
}
}
};
audioToTextVosk.Click += (senderNew, eNew) =>
{
if (!RequireFfmpegOk())
{
return;
}
var audioClips = GetAudioClips();
using (var form = new VoskAudioToTextSelectedLines(audioClips, this))
{
if (form.ShowDialog(this) == DialogResult.OK)
{
MakeHistoryForUndo(string.Format(_language.BeforeX, string.Format(LanguageSettings.Current.Main.Menu.Video.VideoAudioToTextX, "Vosk/Kaldi")));
SubtitleListview1.BeginUpdate();
foreach (var ac in audioClips)
{
var p = _subtitle.Paragraphs.FirstOrDefault(pa => pa.Id == ac.Paragraph.Id);
if (p != null)
{
p.Text = ac.Paragraph.Text;
var idx = _subtitle.Paragraphs.IndexOf(p);
SubtitleListview1.SetText(idx, p.Text);
}
}
SubtitleListview1.EndUpdate();
RefreshSelectedParagraph();
}
}
};
audioToTextVosk.Click += (senderNew, eNew) => { AudioToTextVoskSelectedLines(); };
}
toolStripMenuItemSetRegion.Visible = false;
@ -9400,6 +9343,69 @@ namespace Nikse.SubtitleEdit.Forms
}
}
private void AudioToTextVoskSelectedLines()
{
if (!RequireFfmpegOk())
{
return;
}
var audioClips = GetAudioClips();
using (var form = new VoskAudioToTextSelectedLines(audioClips, this))
{
if (form.ShowDialog(this) == DialogResult.OK)
{
MakeHistoryForUndo(string.Format(_language.BeforeX, string.Format(LanguageSettings.Current.Main.Menu.Video.VideoAudioToTextX, "Vosk/Kaldi")));
SubtitleListview1.BeginUpdate();
foreach (var ac in audioClips)
{
var p = _subtitle.Paragraphs.FirstOrDefault(pa => pa.Id == ac.Paragraph.Id);
if (p != null)
{
p.Text = ac.Paragraph.Text;
var idx = _subtitle.Paragraphs.IndexOf(p);
SubtitleListview1.SetText(idx, p.Text);
}
}
SubtitleListview1.EndUpdate();
RefreshSelectedParagraph();
}
}
}
private void AudioToTextWhisperSelectedLines()
{
if (!RequireFfmpegOk())
{
return;
}
var audioClips = GetAudioClips();
using (var form = new WhisperAudioToTextSelectedLines(audioClips, this))
{
CheckWhisperCpp();
if (form.ShowDialog(this) == DialogResult.OK)
{
MakeHistoryForUndo(string.Format(_language.BeforeX, string.Format(LanguageSettings.Current.Main.Menu.Video.VideoAudioToTextX, "Whisper")));
SubtitleListview1.BeginUpdate();
foreach (var ac in audioClips)
{
var p = _subtitle.Paragraphs.FirstOrDefault(pa => pa.Id == ac.Paragraph.Id);
if (p != null)
{
p.Text = ac.Paragraph.Text;
var idx = _subtitle.Paragraphs.IndexOf(p);
SubtitleListview1.SetText(idx, p.Text);
}
}
SubtitleListview1.EndUpdate();
RefreshSelectedParagraph();
}
}
}
private List<AudioClipsGet.AudioClip> GetAudioClips()
{
var selectedParagraphs = new List<Paragraph>();
@ -17629,6 +17635,16 @@ namespace Nikse.SubtitleEdit.Forms
AutoGuessStartTime(_subtitleListViewIndex);
e.SuppressKeyPress = true;
}
else if (!string.IsNullOrEmpty(_videoFileName) && mediaPlayer.IsPaused && e.KeyData == _shortcuts.WaveformAudioToTextVosk)
{
e.SuppressKeyPress = true;
AudioToTextVoskSelectedLines();
}
else if (!string.IsNullOrEmpty(_videoFileName) && mediaPlayer.IsPaused && e.KeyData == _shortcuts.WaveformAudioToTextWhisper)
{
e.SuppressKeyPress = true;
AudioToTextWhisperSelectedLines();
}
else if (audioVisualizer.Focused && e.KeyCode == Keys.Delete)
{
ToolStripMenuItemDeleteClick(null, null);

View File

@ -1423,7 +1423,8 @@ namespace Nikse.SubtitleEdit.Forms.Options
AddNode(videoNode, language.PlayRateToggle, nameof(Configuration.Settings.Shortcuts.MainVideoSpeedToggle));
AddNode(videoNode, language.VideoResetSpeedAndZoom, nameof(Configuration.Settings.Shortcuts.MainVideoReset));
AddNode(videoNode, language.MainToggleVideoControls, nameof(Configuration.Settings.Shortcuts.MainVideoToggleControls));
AddNode(videoNode, language.VideoAudioToText, nameof(Configuration.Settings.Shortcuts.MainVideoAudioToText));
AddNode(videoNode, string.Format(language.AudioToTextX, "Vosk"), nameof(Configuration.Settings.Shortcuts.MainVideoAudioToTextVosk));
AddNode(videoNode, string.Format(language.AudioToTextX, "Whisper"), nameof(Configuration.Settings.Shortcuts.MainVideoAudioToTextWhisper));
AddNode(videoNode, language.VideoToggleContrast, nameof(Configuration.Settings.Shortcuts.MainVideoToggleContrast));
AddNode(videoNode, language.VideoToggleBrightness, nameof(Configuration.Settings.Shortcuts.MainVideoToggleBrightness));
_shortcuts.Nodes.Add(videoNode);
@ -1627,6 +1628,8 @@ namespace Nikse.SubtitleEdit.Forms.Options
AddNode(audioVisualizerNode, language.GoForward100Milliseconds, nameof(Configuration.Settings.Shortcuts.Waveform100MsRight));
AddNode(audioVisualizerNode, language.GoBack1Second, nameof(Configuration.Settings.Shortcuts.Waveform1000MsLeft));
AddNode(audioVisualizerNode, language.GoForward1Second, nameof(Configuration.Settings.Shortcuts.Waveform1000MsRight));
AddNode(audioVisualizerNode, string.Format(language.AudioToTextSelectedLinesX, "Vosk"), nameof(Configuration.Settings.Shortcuts.WaveformAudioToTextVosk));
AddNode(audioVisualizerNode, string.Format(language.AudioToTextSelectedLinesX, "Whisper"), nameof(Configuration.Settings.Shortcuts.WaveformAudioToTextWhisper));
_shortcuts.Nodes.Add(audioVisualizerNode);
LoadPluginsShortcuts();

View File

@ -2851,7 +2851,8 @@ can edit in same subtitle file (collaboration)",
VideoResetSpeedAndZoom = "Reset play rate (speed) and waveform zoom",
MainToggleVideoControls = "Toggle video controls",
VideoToggleContrast = "Toggle contrast (mpv only)",
VideoAudioToText = "Audio to text",
AudioToTextX = "Audio to text ({0})",
AudioToTextSelectedLinesX = "Audio to text selected lines ({0})",
VideoToggleBrightness = "Toggle brightness (mpv only)",
CustomSearch1 = "Translate, custom search 1",
CustomSearch2 = "Translate, custom search 2",

View File

@ -6904,8 +6904,11 @@ namespace Nikse.SubtitleEdit.Logic
case "Settings/VideoToggleContrast":
language.Settings.VideoToggleContrast = reader.Value;
break;
case "Settings/VideoAudioToText":
language.Settings.VideoAudioToText = reader.Value;
case "Settings/AudioToTextX":
language.Settings.AudioToTextX = reader.Value;
break;
case "Settings/AudioToTextSelectedLinesX":
language.Settings.AudioToTextSelectedLinesX = reader.Value;
break;
case "Settings/VideoToggleBrightness":
language.Settings.VideoToggleBrightness = reader.Value;

View File

@ -2705,7 +2705,8 @@ namespace Nikse.SubtitleEdit.Logic
public string VideoResetSpeedAndZoom { get; set; }
public string MainToggleVideoControls { get; set; }
public string VideoToggleContrast { get; set; }
public string VideoAudioToText { get; set; }
public string AudioToTextX { get; set; }
public string AudioToTextSelectedLinesX { get; set; }
public string VideoToggleBrightness { get; set; }
public string CustomSearch1 { get; set; }
public string CustomSearch2 { get; set; }

View File

@ -231,6 +231,8 @@ namespace Nikse.SubtitleEdit.Logic
public Keys WaveformToggleShotChange { get; set; }
public Keys WaveformListShotChanges { get; set; }
public Keys WaveformGuessStart { get; set; }
public Keys WaveformAudioToTextVosk { get; set; }
public Keys WaveformAudioToTextWhisper { get; set; }
public Keys MainTranslateGoogleIt { get; set; }
public Keys MainCheckFixTimingViaShotChanges { get; set; }
public Keys MainTranslateGoogleTranslateIt { get; set; }
@ -335,7 +337,7 @@ namespace Nikse.SubtitleEdit.Logic
MainVideoFaster = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoFaster);
MainVideoSpeedToggle = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoSpeedToggle);
MainVideoReset = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoReset);
MainVideoAudioToText = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoAudioToText);
MainVideoAudioToText = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoAudioToTextVosk);
MainVideoToggleBrightness = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoToggleBrightness);
MainVideoToggleContrast = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainVideoToggleContrast);
MainToolsAutoDuration = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainToolsAutoDuration);
@ -467,6 +469,8 @@ namespace Nikse.SubtitleEdit.Logic
WaveformToggleShotChange = UiUtil.GetKeys(Configuration.Settings.Shortcuts.WaveformToggleShotChange);
WaveformListShotChanges = UiUtil.GetKeys(Configuration.Settings.Shortcuts.WaveformListShotChanges);
WaveformGuessStart = UiUtil.GetKeys(Configuration.Settings.Shortcuts.WaveformGuessStart);
WaveformAudioToTextVosk = UiUtil.GetKeys(Configuration.Settings.Shortcuts.WaveformAudioToTextVosk);
WaveformAudioToTextWhisper = UiUtil.GetKeys(Configuration.Settings.Shortcuts.WaveformAudioToTextWhisper);
MainTranslateGoogleIt = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTranslateGoogleIt);
MainCheckFixTimingViaShotChanges = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainCheckFixTimingViaShotChanges);
MainTranslateGoogleTranslateIt = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTranslateGoogleTranslateIt);