当前位置: 首页 > news >正文

使用openai-whisper实现语音转文字

使用openai-whisper实现语音转文字

1 安装依赖

1.1 Windows下安装ffmpeg

FFmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。采用LGPL或GPL许可证。它提供了录制、转换以及流化音视频的完整解决方案。

# ffmpeg官网
https://ffmpeg.org/# ffmpeg下载地址
https://ffmpeg.org/download.html# 点击下载后会进入github,地址如下
https://github.com/BtbN/FFmpeg-Builds/releases

在官网上选择windows版本

在这里插入图片描述

推荐使用ffmpeg-n5.1.4-win64-gpl-5.1.zipffmpeg-n6.0.1-win64-gpl-6.0.zip这两个版本,因为ffmpeg 5.1.4 和 ffmpeg 6.0.1版本是最新稳定版。

#  Auto-Build 2023-11-30的地址
https://github.com/BtbN/FFmpeg-Builds/releases/tag/autobuild-2023-11-30-12-55# ffmpeg-n5.1.4-win64-gpl-5.1.zip的地址
https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2023-11-30-12-55/ffmpeg-n5.1.4-win64-gpl-5.1.zip# ffmpeg-n6.0.1-win64-gpl-6.0.zip的地址
https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2023-11-30-12-55/ffmpeg-n6.0.1-win64-gpl-6.0.zip

在GitHub上可以选择最新版本,选择ffmpeg-master-latest-win64-gpl.zip

⚠️​ 如果python程序出现“FileNotFoundError: [WinError 2] 系统找不到指定的文件。”错误时,可能是ffmpeg版本的问题。

在这里插入图片描述

ffmpeg-master-latest-win64-gpl.zip 解压到D盘,名字修改为ffmpeg, 将目录 D:\ffmpeg\bin 添加到环境变量中。

在这里插入图片描述

在dos页面查看版本号中输入:ffmpeg.exe -version,出现下面的信息表示安装成功。

在这里插入图片描述

1.2 安装openai-whispe

# whispe地址
https://github.com/openai/whisper# 安装openai-whisper
pip install openai-whisper -i https://pypi.tuna.tsinghua.edu.cn/simple# 安装pydub切割音频,防止音频太长
pip install pydub -i https://pypi.tuna.tsinghua.edu.cn/simple

下载语音,可以直接在浏览器中打开,再下载

wget -c https://paddlespeech.bj.bcebos.com/PaddleAudio/zh.wav
wget -c https://paddlespeech.bj.bcebos.com/PaddleAudio/en.wav

2 使用openai-whispe

2.1 工程目录

在这里插入图片描述

2.2 main.py

import whisper
model = whisper.load_model(name="tiny", download_root="./model")# load audio and pad/trim it to fit 30 seconds
audio = whisper.load_audio(".//data//zh.wav")
audio = whisper.pad_or_trim(audio)# make log-Mel spectrogram and move to the same device as the model
mel = whisper.log_mel_spectrogram(audio).to(model.device)# detect the spoken language
_, probs = model.detect_language(mel)
print(f"Detected language: {max(probs, key=probs.get)}")# decode the audio
options = whisper.DecodingOptions()
result = whisper.decode(model, mel, options)# print the recognized text
print(result.text)

输出结果:

Detected language: zh
我認為跑步最重要的就是給我帶來了身體健康
http://www.lryc.cn/news/304811.html

相关文章:

  • C++模板为什么不能声明和定义分离
  • 啊丢的刷题记录手册
  • 用nginx正向代理https网站
  • 面向对象设计模式
  • 人工智能_CPU微调ChatGLM大模型_使用P-Tuning v2进行大模型微调_007_微调_002---人工智能工作笔记0102
  • Android自编译Pixel3内核加入KernelSU
  • Go 数据库编程精粹:database/sql 实用技巧解析
  • AI-Gateway:一款整合了OpenAI、Anthropic、LLama2等大语言模型的统一API接口
  • Android 广播的基本概念
  • 【Docker实操】部署php项目
  • 多线程-初阶
  • Object和Function是函数,函数都有一个prototype属性
  • stm32利用CubeMX按键控制数码管加减数
  • 前端页面生成条形码,借助layui打印标签
  • 第1~8章 综合复习
  • 转运机器人,AGV底盘小车:打造高效、精准的汽车电子生产线
  • Spring Boot 的参数校验方案
  • 第N3周:Pytorch文本分类入门
  • 宝塔面板安装了mysql5.7和phpMyadmin,但是访问phpMyadmin时提示502 Bad Gateway
  • K8S—Pod详解
  • 深度学习中数据的转换
  • 如何系统地自学 Python?
  • 【软考】传输层协议之UDP
  • 微服务-微服务链路追踪组件Skywalking实战
  • Stream、Collections、Collectors用法
  • Jetson Xavier NX 与笔记本网线连接 ,网络共享,ssh连接到vscode
  • 利用netty手写rpc框架
  • js+views 压缩上传的图片
  • 【安卓基础5】中级控件
  • Arthas—【学习篇】