whisper语音转文字配置

whisper语音转文字配置 Whisper CUDA (RTX 5060) 环境配置笔记1. 环境安装指令第一步卸载旧版 Torch (确保无冲突)Bashpip uninstall torch torchvision torchaudio -y第二步安装支持 RTX 5060 (Blackwell 架构) 的 CUDA 12.8 版本Bashpip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128第三步安装核心组件Bashpip install faster-whisper whisper-ctranslate22. 实际使用指令推荐转录命令 (生成带标点、无时间戳的连贯文本)Bashwhisper-ctranslate2 输入文件.m4a --model large-v3 --language zh --output_format txt --initial_prompt 以下是转录内容请确保语句连贯并正确使用中文标点符号。whisper-ctranslate2 “lesson 0415 32h.m4a” --model large-v3 --language zh --output_format txt --initial_prompt “以下是转录内容请确保语句连贯并正确使用中文标点符号。”whisper “lesson 0415 32h.m4a” --model large-v3 --language zh --output_format txt --initial_prompt “以下是转录内容请确保语句连贯并正确使用中文标点符号。”参数说明--model large-v3: 使用精度最高的模型。--language zh: 强制识别为中文。--output_format txt: 仅输出纯文本文件不含时间戳。--initial_prompt: 通过引导语强制模型生成标点符号。--beam_size 1将束搜索宽度设为1与原版 whisper 默认值一致减少重复幻觉。--vad_filter True启用语音活动检测自动跳过静音片段避免无语音段产生幻觉。--condition_on_previous_text False禁止用前一段输出作为下一段的上下文防止错误内容向后传播。--word_timestamps True启用词级时间戳改善分句断点的准确性。3. 脚本transcribe.py 快速语音转文字工具 (whisper-ctranslate2) 用法: python transcribe.py importosimportsubprocess# ── 配置 ──MODELlarge-v3OUTPUT_FORMATtxtLANG_OPTIONS{1:{code:zh,label:中文,extra_args:[--beam_size,1,--vad_filter,True,--initial_prompt,大家好这是一段录音。我现在开始讲话了请注意听。今天我们来讨论一下这个问题。如果内容中有一些English比如app或者数字10等保持原词不需要翻译。,],},2:{code:en,label:English,extra_args:[--beam_size,1,--vad_filter,True,],},}AUDIO_EXTS{.mp3,.m4a,.wav,.flac,.ogg,.wma,.aac,.mp4,.mkv,.webm}deflist_files():returnsorted(fforfinos.listdir(.)ifos.path.isfile(f)andos.path.splitext(f)[1].lower()inAUDIO_EXTS)defchoose_language():print(f\n{─*50})print( 选择语言 / Select language)print(f{─*50}\n)forkey,optinLANG_OPTIONS.items():print(f [{key}]{opt[label]})print(f\n [0] 退出\n)try:choiceinput(输入编号: ).strip()except(KeyboardInterrupt,EOFError):print()returnNoneifchoice0orchoice:returnNoneifchoicenotinLANG_OPTIONS:print(编号无效。)returnNonereturnLANG_OPTIONS[choice]defchoose_file(files,lang):print(f\n{─*50})print(f 模型:{MODEL}| 语言:{lang[label]}| 格式:{OUTPUT_FORMAT})print(f{─*50}\n)fori,finenumerate(files,1):size_mbos.path.getsize(f)/(1024*1024)print(f [{i}]{f}({size_mb:.1f}MB))print(f\n [0] 返回\n)try:choiceinput(输入编号开始转录: ).strip()except(KeyboardInterrupt,EOFError):print()returnNoneifchoice0orchoice:returnNonetry:idxint(choice)-1ifidx0oridxlen(files):print(编号无效。)returnNoneexceptValueError:print(请输入数字。)returnNonereturnfiles[idx]defmain():langchoose_language()ifnotlang:returnfileslist_files()ifnotfiles:print(当前目录没有找到音视频文件。)returnselectedchoose_file(files,lang)ifnotselected:returnprint(f\n开始转录:{selected}\n)cmd[whisper-ctranslate2,selected,--model,MODEL,--language,lang[code],--task,transcribe,--output_format,OUTPUT_FORMAT,*lang[extra_args],]subprocess.run(cmd)if__name____main__:main()