python录音转文字

最近面试,有录音,想把录音快速转文字查漏补缺,但是找了几个小程序要花钱,不如直接写个脚本之际转
(下载FFmpeg 很重要)
访问 FFmpeg 官网:https://ffmpeg.org/download.html

找到 Windows 板块,点击 "Windows builds from gyan.dev"

下载 ffmpeg-release-full.7z

并需要配置环境变量

安装python依赖

复制代码
pip install openai-whisper
pip install ffmpeg-python

脚本

复制代码
import whisper

model = whisper.load_model("base")
result = model.transcribe("面试2.m4a", language="zh")
print(result["text"])
with open("transcript3.txt", "w", encoding="utf-8") as f:
    f.write(result["text"])

模型精度选择(免费)

  • base :最快,普通说话清晰够用

  • small :中文识别明显更好

  • medium :接近付费平台效果

  • large :最强,但需要显卡

另外由于我的电脑是有独显的,但是whisper没有调用到,直接用的cpu,导致转录很慢

修改方式,更新pytorch为可以兼容cuda显卡的

复制代码
pip uninstall -y torch torchvision torchaudio

pip install torch torchvision torchaudio -i https://pypi.tuna.tsinghua.edu.cn/simple --extra-index-url https://download.pytorch.org/whl/cu118

更新代码

复制代码
import whisper

# 加载模型,并手动移动到 GPU (cuda)
model = whisper.load_model("base").to("cuda")

# 转写时,关闭 FP16 可以避免某些兼容性警告
result = model.transcribe("面试2.m4a", language="zh", fp16=False)

print(result["text"])
with open("transcript3.txt", "w", encoding="utf-8") as f:
    f.write(result["text"])
相关推荐
金銀銅鐵15 小时前
[Python] 从《千字文》中随机挑选汉字
后端·python
cup1120 小时前
[技术复盘] Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
python·ai·环境变量·ci·nuitka·skill
aqi001 天前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG
人工智能·python·大模型·ai编程·ai应用
金銀銅鐵1 天前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf1 天前
Agent 流程编排
后端·python·agent
copyer_xyf1 天前
Agent RAG
后端·python·agent
copyer_xyf1 天前
【RAG】向量数据库:milvus
后端·python·agent
copyer_xyf1 天前
Agent 记忆管理
后端·python·agent
星云穿梭2 天前
用Python写一个带图形界面的学生管理系统——完整教程
python