Skip to content

Commit

Permalink
Rename output when .wav, no timestamps in txt
Browse files Browse the repository at this point in the history
  • Loading branch information
jacks authored and jacks committed Aug 5, 2023
1 parent 85c39c7 commit 69cd34f
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion whisperer/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ bool outputexists(string filename)
if (!checkBox1.Checked)
return false;
filename = filename.Remove(filename.LastIndexOf('.'));

if (filename.EndsWith(".wav"))
filename = filename.Remove(filename.LastIndexOf('.'));

bool res = true;
if (checkBox4.Checked)
res = File.Exists(filename + ".srt");
Expand Down Expand Up @@ -343,7 +347,7 @@ void qwhisper(string filename)
if (checkBox6.Checked)
outtypes += "--output-vtt ";

proc.StartInfo.Arguments = "--language " + glblang + translate + outtypes + "--max-context 0 --model \"" +
proc.StartInfo.Arguments = "--language " + glblang + translate + outtypes + "--no-timestamps --max-context 0 --model \"" +
glbmodel + "\" \"" + filename + "\"";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
Expand Down Expand Up @@ -413,6 +417,34 @@ void qwhisper(string filename)
}));
}

void tryrename(string filename, string ext)
{
try
{
string oldname = filename + ".wav" + ext;
if (File.Exists(oldname))
{
string newname = filename + ext;
if (File.Exists(newname))
File.Delete(newname);
File.Move(oldname, newname);
}
}
catch { }
}

readonly string[] exts = { ".srt", ".txt", ".vtt" };

void renamewaves(string filename)
{
if (filename.EndsWith(".wav.wav", StringComparison.InvariantCultureIgnoreCase))
{
filename = filename.Remove(filename.LastIndexOf(".wav.wav", StringComparison.InvariantCultureIgnoreCase));
foreach (string ext in exts)
tryrename(filename, ext);
}
}

private void whisper_Exited(object sender, EventArgs e)
{
try
Expand All @@ -422,6 +454,7 @@ private void whisper_Exited(object sender, EventArgs e)
filename = filename.Substring(filename.LastIndexOf('"') + 1);
if (File.Exists(filename))
File.Delete(filename);
renamewaves(filename);
}
catch { }
completed++;
Expand Down

0 comments on commit 69cd34f

Please sign in to comment.