| name | openai-whisper |
| description | 本地语音转文字工具,基于OpenAI Whisper模型。无需API密钥,支持多种音频格式和语言识别。 |
| triggers | ["语音转文字","whisper","语音识别","转文字","音频转文字","语音转文本","字幕生成"] |
| homepage | https://openai.com/research/whisper |
| metadata | {"clawdbot":{"emoji":"🎙️","requires":{"bins":["whisper"]},"install":[{"id":"brew","kind":"brew","formula":"openai-whisper","bins":["whisper"],"label":"Install OpenAI Whisper (brew)"}]}} |
Whisper - 本地语音转文字工具
使用 whisper 命令行工具在本地进行语音转文字,基于OpenAI Whisper模型。无需API密钥,支持多种音频格式和语言识别。
🚀 快速开始
基本转录
whisper audio.mp3 --model medium --output_format txt
whisper audio.m4a --model small --output_format srt
whisper audio.wav --model large --output_format vtt
指定输出目录
whisper audio.mp3 --output_dir .
whisper audio.mp3 --output_dir ./transcripts/
whisper audio.mp3 --output_format txt,srt,vtt --output_dir ./output/
📝 功能详解
模型选择
whisper audio.mp3 --model tiny
whisper audio.mp3 --model base
whisper audio.mp3 --model small
whisper audio.mp3 --model medium
whisper audio.mp3 --model large
whisper audio.mp3 --model large-v1
whisper audio.mp3 --model large-v2
whisper audio.mp3 --model large-v3
whisper audio.mp3 --model turbo
输出格式
whisper audio.mp3 --output_format txt
whisper audio.mp3 --output_format srt
whisper audio.mp3 --output_format vtt
whisper audio.mp3 --output_format tsv
whisper audio.mp3 --output_format json
whisper audio.mp3 --output_format all
语言处理
whisper audio.mp3
whisper audio.mp3 --language Chinese
whisper audio.mp3 --language English
whisper audio.mp3 --language Japanese
whisper audio.mp3 --language Korean
whisper audio.mp3 --language Spanish
whisper audio.mp3 --task translate
whisper audio.mp3 --language Chinese --task translate
🎯 实用示例
示例1:会议录音转录
whisper meeting_recording.mp3 \
--model large \
--language Chinese \
--output_format txt,srt \
--output_dir ./meeting_transcripts/
whisper meeting.mp3 --output_format txt --word_timestamps True
示例2:播客节目处理
for podcast in podcasts/*.mp3; do
basename=$(basename "$podcast" .mp3)
whisper "$podcast" \
--model medium \
--language English \
--output_format txt,srt \
--output_dir "transcripts/${basename}/"
done
示例3:视频字幕生成
ffmpeg -i video.mp4 -vn -acodec pcm_s16le -ar 16000 -ac 1 audio.wav
whisper audio.wav --model medium --output_format srt
whisper video.mp4 --model small --output_format srt
示例4:多语言内容处理
#!/bin/bash
AUDIO_FILE="$1"
echo "检测音频语言..."
LANG_INFO=$(whisper "$AUDIO_FILE" --model tiny --output_format json | jq -r '.language')
echo "检测到的语言: $LANG_INFO"
case "$LANG_INFO" in
"zh"|"zh-cn"|"zh-tw")
echo "中文内容,使用大模型..."
whisper "$AUDIO_FILE" --model large --language Chinese --output_format txt,srt
;;
"en")
echo "英文内容,使用中模型并翻译..."
whisper "$AUDIO_FILE" --model medium --language English --output_format txt,srt
whisper "$AUDIO_FILE" --model medium --language English --task translate --output_format txt
;;
*)
echo "其他语言,使用自动检测..."
whisper "$AUDIO_FILE" --model medium --output_format txt,srt
;;
esac
示例5:批量处理工作流
#!/bin/bash
INPUT_DIR="./raw_audio"
OUTPUT_DIR="./transcripts"
LOG_FILE="./transcription.log"
mkdir -p "$OUTPUT_DIR"
echo "=== 批量转录开始 $(date) ===" > "$LOG_FILE"
find "$INPUT_DIR" -type f \( -name "*.mp3" -o -name "*.wav" -o -name "*.m4a" -o -name "*.flac" \) | while read audio_file; do
BASENAME=$(basename "$audio_file")
FILENAME="${BASENAME%.*}"
echo "处理: $BASENAME" | tee -a "$LOG_FILE"
mkdir -p "$OUTPUT_DIR/$FILENAME"
whisper "$audio_file" \
--model medium \
--output_format txt,srt,json \
--output_dir "$OUTPUT_DIR/$FILENAME" \
--verbose 2>&1 | tee -a "$LOG_FILE"
echo "完成: $BASENAME" | tee -a "$LOG_FILE"
echo "---" | tee -a "$LOG_FILE"
done
echo "=== 批量转录结束 $(date) ===" >> "$LOG_FILE"
echo "所有音频处理完成!结果保存在: $OUTPUT_DIR"
⚙️ 高级选项
性能优化
whisper audio.mp3 --device cuda
whisper audio.mp3 --device cpu
whisper audio.mp3 --threads 4
whisper audio.mp3 --batch_size 16
处理控制
whisper audio.mp3 --start_at 60 --stop_at 300
whisper audio.mp3 --temperature 0.0
whisper audio.mp3 --temperature 0.2
whisper audio.mp3 --temperature 1.0
whisper audio.mp3 --word_timestamps True
whisper audio.mp3 --suppress_repetitions True
输出控制
whisper audio.mp3 --output_name "transcript"
whisper audio.mp3 --verbose True
whisper audio.mp3 --progress True
whisper audio.mp3 --progress False
🔧 故障排除
常见问题
1. 模型下载失败
export WHISPER_CACHE_DIR="/path/to/cache"
2. 内存不足
whisper audio.mp3 --model tiny
whisper audio.mp3 --chunk_length 30
3. 音频格式不支持
ffmpeg -i input.avi -vn -acodec pcm_s16le -ar 16000 -ac 1 output.wav
for file in *.m4a; do
ffmpeg -i "$file" -vn -acodec pcm_s16le -ar 16000 -ac 1 "${file%.m4a}.wav"
done
4. 识别准确度低
whisper audio.mp3 --language Chinese
whisper audio.mp3 --model large
调试技巧
whisper --version
whisper --list_models
whisper --test_models
whisper audio.mp3 --verbose True --debug True
📚 学习资源
命令参考
whisper --help
whisper --model_info medium
whisper --check_system
相关技能
- summarize: 文本摘要工具(可用于转录后摘要)
- openai-whisper-api: OpenAI Whisper API版本
- ffmpeg: 音频视频处理工具
- audio-processing: 音频处理相关工具
最佳实践
- 选择合适的模型: 根据需求平衡速度和准确度
- 指定语言: 明确指定语言可提高准确度
- 预处理音频: 确保音频质量良好
- 批量处理优化: 使用脚本自动化处理流程
- 结果验证: 重要内容需要人工检查
性能优化
parallel whisper {} --model small ::: *.mp3
whisper audio.mp3 --device cuda --model medium
for audio in *.mp3; do
ffmpeg -i "$audio" -ar 16000 -ac 1 "${audio%.mp3}_16k.wav"
done
提示: Whisper是非常强大的本地语音识别工具,但对于专业用途或极高准确度要求,建议结合人工校对或使用专业语音识别服务。