-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExport-WhisperCsvToTxt.ps1
52 lines (46 loc) · 2.11 KB
/
Export-WhisperCsvToTxt.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
[CmdletBinding()]
param (
[string]$CsvPath = "Z:\BossmanJack\Kick\Transcripts",
[string]$TextOutput = "Z:\BossmanJack\Kick\TranscriptsTxt",
[switch]$Overwrite = $false
)
# This script exports the CSV files generated by Whispercpp to a nice, legible
# format similar to what's printed to the console while Whisper is running as
# Whispercpp's own txt format excludes timestamps for whatever reason
function Get-TsText([TimeSpan]$TS)
{
# e.g. 01:15:07.100
return "$($TS.Hours.ToString('00')):$($TS.Minutes.ToString('00')):$($TS.Seconds.ToString('00')).$($TS.Milliseconds.ToString('000'))"
}
# The cast to object[] is to ensure it's always an array,
# even if only a single item is returned
[object[]]$CsvFiles = Get-ChildItem -File -Recurse -Include "*.csv" -Path $CsvPath
Write-Host "$($CsvFiles.Count) files to process" -ForegroundColor Magenta
$i = 0
$Count = $CsvFiles.Count
foreach ($CsvFile in $CsvFiles)
{
$i++
Write-Progress -Activity "Processing CSVs" -Status "Processing $($CsvFile.FullName) ($i of $Count)" -PercentComplete ($i / $Count * 100)
#Write-Host "Processing $($CsvFile.Name) ($i of $Count)" -ForegroundColor Cyan
$CsvData = Import-Csv -LiteralPath $CsvFile.FullName
$Lines = @("VOD at https://mines.expert/BossmanJack/Kick/$($CsvFile.BaseName).mp4")
$TsTextPath = Join-Path $TextOutput "$($CsvFile.BaseName).txt"
if (-not $Overwrite -and [System.IO.File]::Exists($TsTextPath))
{
#Write-Host "Skipping $TsTextPath as it already exists" -ForegroundColor Yellow
continue
}
foreach ($Row in $CsvData)
{
$Start = [TimeSpan]::FromMilliseconds($Row.start)
$End = [TimeSpan]::FromMilliseconds($Row.end)
$Lines += "[$(Get-TsText $Start) -> $(Get-TsText $End)]: $($Row.text)"
}
# Out-File will write a BOM to the file, which seemingly serves to make the
# file an unreadable mess 99% of the time.
# Out-File is also buggy when dealing with very weird file names
[System.IO.File]::WriteAllLines($TsTextPath, $Lines)
Write-Host "$($CsvFile.Name) done" -ForegroundColor Green
}
Write-Host "Done" -ForegroundColor Green