基于 faster-whisper 的高性能本地语音转文字工具。
执行安装脚本以创建虚拟环境并安装依赖包。脚本会自动检测 NVIDIA GPU 以启用 CUDA 加速。
./setup.sh
系统要求:
使用转换脚本转换音频文件。
export HF_HOME=/config/huggingface
export HF_ENDPOINT=https://hf-mirror.com
.venv/bin/python3 scripts/transcribe.py
.venv/bin/python3 scripts/transcribe.py audio.mp3 --model large-v3-turbo.venv/bin/python3 scripts/transcribe.py audio.mp3 --word-timestamps.venv/bin/python3 scripts/transcribe.py audio.mp3 --json.venv/bin/python3 scripts/transcribe.py audio.mp3 --vad.venv/bin/python3 scripts/transcribe.py audio.mp3 --language zh.venv/bin/python3 scripts/transcribe.py audio.mp3 --device cuda.venv/bin/python3 scripts/transcribe.py audio.mp3 --device cpu --compute-type int8# 中文转录,使用 GPU 加速
.venv/bin/python3 scripts/transcribe.py 会议录音.mp3 --language zh --device cuda --compute-type float16
# 英文转录,包含词级时间戳
.venv/bin/python3 scripts/transcribe.py interview.wav --language en --word-timestamps --json
# 快速 CPU 转录,优化性能
.venv/bin/python3 scripts/transcribe.py audio.m4a --device cpu --compute-type int8 --model distil-large-v3
# 批量处理脚本
.venv/bin/python3 scripts/batch_transcribe.sh /path/to/audio/files/
large-v3-turbo (默认):推荐用于多语言或最高准确度任务large-v3: 原始大模型,准确度最高distil-large-v3: 速度和准确性的最佳平衡medium: 中等大小,平衡性能small: 小型模型,速度快base: 基础模型,资源需求最低tiny: 微型模型,速度最快medium.en, small.en: 仅支持英语的更快版本| 模型 | 大小 | 推荐用途 | 硬件要求 |
|---|---|---|---|
| ------ | ------ | ---------- | ---------- |
large-v3-turbo | 1.5GB | 专业级转录 | 高性能 GPU |
medium | 1.5GB | 平衡性能 | 普通配置 |
distil-large-v3 | 756MB | 通用中文转录 | 中等配置 |
small | 500MB | 快速转录 | 低配置 |
tiny | 150MB | 实时转录 | 最低配置 |
# NVIDIA GPU (CUDA)
.venv/bin/python3 scripts/transcribe.py audio.mp3 --device cuda --compute-type float16
# Apple Silicon (macOS)
.venv/bin/python3 scripts/transcribe.py audio.mp3 --device mps
# 高性能 CPU
.venv/bin/python3 scripts/transcribe.py audio.mp3 --device cpu --compute-type int8 --beam-size 3
# 低资源环境
.venv/bin/python3 scripts/transcribe.py audio.mp3 --device cpu --compute-type int8 --model small --beam-size 1
small 或 base)或使用 --compute-type int8HF_ENDPOINT=https://hf-mirror.com 使用国内镜像ffmpeg -i input.m4a output.wav```bash
# 检查 CUDA 安装
nvidia-smi
# 如果未安装,重新运行安装脚本
./setup.sh
```
```bash
# Ubuntu/Debian
sudo apt install ffmpeg
# macOS
brew install ffmpeg
# CentOS/RHEL
sudo yum install ffmpeg
```
```bash
# 检查 Python 版本
python3 --version
# 需要 Python 3.10+
```
# 设置 HuggingFace 缓存目录(避免重复下载)
export HF_HOME=/config/huggingface
# 使用国内镜像加速下载
export HF_ENDPOINT=https://hf-mirror.com
# 设置 PyTorch CUDA 版本(如有需要)
export CUDA_VISIBLE_DEVICES=0
创建 batch_transcribe.sh 脚本进行批量处理:
#!/bin/bash
# 批量转录脚本
for audio_file in *.mp3 *.wav *.m4a; do
if [ -f "$audio_file" ]; then
echo "处理: $audio_file"
./scripts/transcribe.py "$audio_file" --output "${audio_file%.*}.txt"
fi
done
[00:00:00.000 --> 00:00:05.000] 欢迎使用 faster-whisper 语音转文字工具。
[00:00:05.000 --> 00:00:10.000] 这是一个高性能的本地转录解决方案。
{
"text": "完整的转录文本...",
"segments": [
{
"start": 0.0,
"end": 5.0,
"text": "欢迎使用 faster-whisper 语音转文字工具。",
"words": [
{"word": "欢迎", "start": 0.0, "end": 0.5},
{"word": "使用", "start": 0.5, "end": 1.0}
]
}
]
}
如有问题,请:
提示: 首次运行会下载所选模型(large-v3-turbo 约 1.5GB)。请确保有足够的磁盘空间和稳定的网络连接。
共 1 个版本