-
Notifications
You must be signed in to change notification settings - Fork 0
/
whisper_with_VAD.ps1
63 lines (52 loc) · 2.02 KB
/
whisper_with_VAD.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
53
54
55
56
57
58
59
60
61
62
63
param (
[string]$file_name,
[string]$model_path
)
function usage {
Write-Host "Usage: $((Get-Command $MyInvocation.InvocationName).Name) -f FILE_NAME -m MODEL_PATH"
}
$ErrorActionPreference = "Stop"
if (-not $file_name -or -not $model_path) {
usage
exit 1
}
$folder_path = "vad_chunks"
# Check if the chunks folder already exists
if (-not (Test-Path $folder_path)) {
New-Item -ItemType Directory -Path $folder_path | Out-Null
Write-Host "Chunks directory created."
} else {
# Check if the folder is empty
if (-not (Get-ChildItem $folder_path)) {
Write-Host "Chunks directory is empty."
} else {
# Clear the folder
Remove-Item "$folder_path\*" -Force
Write-Host "Chunks directory cleared."
}
}
# Run Silero-VAD and produce chunk files
python VAD_Whisper-cpp/runVAD.py -re -uo -f $file_name
# Passing all chunk files into whisper
$files = Get-ChildItem -Path $folder_path -Filter *.wav | Sort-Object { [int]$_.BaseName }
if ($files.Count -gt 0) {
$files = $files | ForEach-Object { "vad_chunks\$($_.Name)" }
.\Whisperer\main.exe -m $model_path -mc 0 -l ja -tr -osrt -f $files
} else {
Write-Host "No files found in the folder. Exiting."
exit 1
}
# Extract the directory, filename, and extension of the input file
$input_dir = Split-Path $file_name -Parent
$input_base = [System.IO.Path]::GetFileNameWithoutExtension($file_name)
$input_name = [System.IO.Path]::GetFileName($file_name)
$input_ext = [System.IO.Path]::GetExtension($file_name)
# Determine the output directory based on the input file
$output_dir = (Get-Item $file_name).Directory.FullName
$output_path = Join-Path $output_dir "output.srt"
# Create final subtitle
$output_name = [System.IO.Path]::GetFileNameWithoutExtension($file_name)
$output_path = Join-Path $output_dir "${output_name}_output.srt"
python VAD_Whisper-cpp/composeSub.py -o $output_path
Remove-Item -Path $folder_path -Recurse -Force
Write-Host "Output subtitle: $output_path"