使用本地模型获取字幕

windows下环境安装

1
2
3
4
5
6
python -m venv venv
venv\Scripts\activate.ps1


pip install -U openai-whisper
pip install torch toryyuyurchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

将mp4视频文件存放到目录下,接着打开 powershell 运行以下命令

 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
$start = Get-Date
$files = Get-ChildItem *.mp4
$i = 0

foreach ($file in $files) {
    $i++
    $fileStart = Get-Date
    Write-Host "[$i/$($files.Count)] 开始: $($file.Name)" -ForegroundColor Cyan

    whisper $file.Name --model large-v3-turbo --language English --output_dir Course_output_en --output_format srt

    $fileElapsed = (Get-Date) - $fileStart
    $totalSoFar  = (Get-Date) - $start
    $avg         = $totalSoFar.TotalSeconds / $i
    $eta         = [TimeSpan]::FromSeconds($avg * ($files.Count - $i))

    Write-Host ("  完成: {0}  本文件: {1}  已用: {2}  预计剩余: {3}" -f `
        $file.Name, `
        $fileElapsed.ToString('hh\:mm\:ss'), `
        $totalSoFar.ToString('hh\:mm\:ss'), `
        $eta.ToString('hh\:mm\:ss')) -ForegroundColor Green
}

$total = (Get-Date) - $start
Write-Host "`n===== 全部完成 =====" -ForegroundColor Yellow
Write-Host "总耗时: $($total.ToString('hh\:mm\:ss'))"
Write-Host "文件数: $($files.Count)"
Write-Host "平均每个: $([TimeSpan]::FromSeconds($total.TotalSeconds / $files.Count).ToString('hh\:mm\:ss'))"
Licensed under CC BY-NC-SA 4.0
Built with Hugo
Theme Stack designed by Jimmy