This content originally appeared on DEV Community and was authored by drake
GPU 型号
NVIDIA GeForce GTX 750 Ti
依赖
- python
- 三方包
pip uninstall torch torchvision torchaudio -y
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
pip install -U openai-whisper
echo "智能批量转录:自动选择最大可用 Whisper 模型"
# 方法1:尝试用 nvidia-smi 获取显存(兼容 Git Bash)
TOTAL_MEM=0
if command -v nvidia-smi > /dev/null 2>&1; then
MEM_LINE=$(nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits | head -1)
if [[ $MEM_LINE =~ ^[0-9]+$ ]]; then
TOTAL_MEM=$MEM_LINE
fi
fi
# 方法2:如果 nvidia-smi 失败,fallback 到 PyTorch 检测(推荐!)
if [ $TOTAL_MEM -eq 0 ] && command -v python > /dev/null 2>&1; then
MEM_PY=$(python -c "
import torch
if torch.cuda.is_available():
print(torch.cuda.get_device_properties(0).total_memory // 1024 // 1024)
else:
print(0)
" 2>/dev/null || echo 0)
TOTAL_MEM=$((MEM_PY))
fi
echo "检测到显存: ${TOTAL_MEM} MiB"
# 正确模型选择逻辑(显存越大,模型越大)
if [ $TOTAL_MEM -ge 20000 ]; then
MODEL="large-v3"
elif [ $TOTAL_MEM -ge 14000 ]; then
MODEL="medium"
elif [ $TOTAL_MEM -ge 8000 ]; then
MODEL="small"
elif [ $TOTAL_MEM -ge 4000 ]; then
MODEL="base"
else
MODEL="tiny"
fi
echo "自动选择模型: $MODEL"
echo "=================================================="
# 检查 whisper 命令是否存在
if ! command -v whisper > /dev/null 2>&1; then
echo "错误:whisper 命令未找到!请先 pip install openai-whisper"
exit 1
fi
# 批量转录
count=0
for mp3 in *.mp3; do
[[ -f "$mp3" ]] || continue
txt="${mp3%.mp3}.txt"
if [ ! -f "$txt" ]; then
echo "转录: $mp3 → $txt (模型: $MODEL)"
whisper "$mp3" \
--model "$MODEL" \
--device cuda \
--output_format txt \
--verbose False \
--output_dir .
((count++))
else
echo "跳过: $txt 已存在"
fi
done
echo "=================================================="
echo "全部完成!本次新增转录 $count 个文件。"
This content originally appeared on DEV Community and was authored by drake
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.
APA
MLA
drake | Sciencx (2025-11-12T23:41:03+00:00) openai-whisper从多媒体抽取文本(windows GPU 版本). Retrieved from https://www.scien.cx/2025/11/12/openai-whisper%e4%bb%8e%e5%a4%9a%e5%aa%92%e4%bd%93%e6%8a%bd%e5%8f%96%e6%96%87%e6%9c%ac%ef%bc%88windows-gpu-%e7%89%88%e6%9c%ac%ef%bc%89/
" » openai-whisper从多媒体抽取文本(windows GPU 版本)." drake | Sciencx - Wednesday November 12, 2025, https://www.scien.cx/2025/11/12/openai-whisper%e4%bb%8e%e5%a4%9a%e5%aa%92%e4%bd%93%e6%8a%bd%e5%8f%96%e6%96%87%e6%9c%ac%ef%bc%88windows-gpu-%e7%89%88%e6%9c%ac%ef%bc%89/
HARVARDdrake | Sciencx Wednesday November 12, 2025 » openai-whisper从多媒体抽取文本(windows GPU 版本)., viewed ,<https://www.scien.cx/2025/11/12/openai-whisper%e4%bb%8e%e5%a4%9a%e5%aa%92%e4%bd%93%e6%8a%bd%e5%8f%96%e6%96%87%e6%9c%ac%ef%bc%88windows-gpu-%e7%89%88%e6%9c%ac%ef%bc%89/>
VANCOUVERdrake | Sciencx - » openai-whisper从多媒体抽取文本(windows GPU 版本). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/11/12/openai-whisper%e4%bb%8e%e5%a4%9a%e5%aa%92%e4%bd%93%e6%8a%bd%e5%8f%96%e6%96%87%e6%9c%ac%ef%bc%88windows-gpu-%e7%89%88%e6%9c%ac%ef%bc%89/
CHICAGO" » openai-whisper从多媒体抽取文本(windows GPU 版本)." drake | Sciencx - Accessed . https://www.scien.cx/2025/11/12/openai-whisper%e4%bb%8e%e5%a4%9a%e5%aa%92%e4%bd%93%e6%8a%bd%e5%8f%96%e6%96%87%e6%9c%ac%ef%bc%88windows-gpu-%e7%89%88%e6%9c%ac%ef%bc%89/
IEEE" » openai-whisper从多媒体抽取文本(windows GPU 版本)." drake | Sciencx [Online]. Available: https://www.scien.cx/2025/11/12/openai-whisper%e4%bb%8e%e5%a4%9a%e5%aa%92%e4%bd%93%e6%8a%bd%e5%8f%96%e6%96%87%e6%9c%ac%ef%bc%88windows-gpu-%e7%89%88%e6%9c%ac%ef%bc%89/. [Accessed: ]
rf:citation » openai-whisper从多媒体抽取文本(windows GPU 版本) | drake | Sciencx | https://www.scien.cx/2025/11/12/openai-whisper%e4%bb%8e%e5%a4%9a%e5%aa%92%e4%bd%93%e6%8a%bd%e5%8f%96%e6%96%87%e6%9c%ac%ef%bc%88windows-gpu-%e7%89%88%e6%9c%ac%ef%bc%89/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.