whisper v3语音转文字

原文github地址:openai/whisper: Robust Speech Recognition via Large-Scale Weak Supervision (github.com)

一、配置环境

建议python3.8-3.11以及基础的gpu版torch等等,可以pip直接下载库whisper

pip install -U openai-whisper

也可以从github上拉取并安装最新的提交及其 Python 依赖项:(推荐)

pip install git+https://github.com/openai/whisper.git 

如果后期github上又重新更新了某些内容,可以拉取更新。

pip install --upgrade --no-deps --force-reinstall git+https://github.com/openai/whisper.git

还要在系统上安装ffmpeg工具(加载音频要用到)

# on Ubuntu or Debian
sudo apt update && sudo apt install ffmpeg

# on Arch Linux
sudo pacman -S ffmpeg

# on MacOS using Homebrew (https://brew.sh/)
brew install ffmpeg

# on Windows using Chocolatey (https://chocolatey.org/)
choco install ffmpeg

# on Windows using Scoop (https://scoop.sh/)
scoop install ffmpeg

 linux用命令就可以下载了,如果是windows的话需要进入官网

https://chocolatey.org/ 或 https://scoop.sh/

 以scoop为例:

运行这两行命令就行了,然后就能用scoop 下载ffmpeg 

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression

模型可用的型号如下:建议直接用 23年11月发布的large v3模型

SizeParametersEnglish-only modelMultilingual modelRequired VRAMRelative speed
tiny39 Mtiny.entiny~1 GB~32x
base74 Mbase.enbase~1 GB~16x
small244 Msmall.ensmall~2 GB~6x
medium769 Mmedium.enmedium~5 GB~2x
large1550 MN/Alarge~10 GB1x

快速开始:

import whisper

model = whisper.load_model("base")
result = model.transcribe("audio.mp3")
print(result["text"])

其他用法可以看github原地址。

模型选择:

_MODELS = {
    "tiny.en": "https://openaipublic.azureedge.net/main/whisper/models/d3dd57d32accea0b295c96e26691aa14d8822fac7d9d27d5dc00b4ca2826dd03/tiny.en.pt",
    "tiny": "https://openaipublic.azureedge.net/main/whisper/models/65147644a518d12f04e32d6f3b26facc3f8dd46e5390956a9424a650c0ce22b9/tiny.pt",
    "base.en": "https://openaipublic.azureedge.net/main/whisper/models/25a8566e1d0c1e2231d1c762132cd20e0f96a85d16145c3a00adf5d1ac670ead/base.en.pt",
    "base": "https://openaipublic.azureedge.net/main/whisper/models/ed3a0b6b1c0edf879ad9b11b1af5a0e6ab5db9205f891f668f8b0e6c6326e34e/base.pt",
    "small.en": "https://openaipublic.azureedge.net/main/whisper/models/f953ad0fd29cacd07d5a9eda5624af0f6bcf2258be67c92b79389873d91e0872/small.en.pt",
    "small": "https://openaipublic.azureedge.net/main/whisper/models/9ecf779972d90ba49c06d968637d720dd632c55bbf19d441fb42bf17a411e794/small.pt",
    "medium.en": "https://openaipublic.azureedge.net/main/whisper/models/d7440d1dc186f76616474e0ff0b3b6b879abc9d1a4926b7adfa41db2d497ab4f/medium.en.pt",
    "medium": "https://openaipublic.azureedge.net/main/whisper/models/345ae4da62f9b3d59415adc60127b97c714f32e89e936602e85993674d08dcb1/medium.pt",
    "large-v1": "https://openaipublic.azureedge.net/main/whisper/models/e4b87e7e0bf463eb8e6956e646f1e277e901512310def2c24bf0e11bd3c28e9a/large-v1.pt",
    "large-v2": "https://openaipublic.azureedge.net/main/whisper/models/81f7c96c852ee8fc832187b0132e569d6c3065a3252ed18e56effd0b6a73e524/large-v2.pt",
    "large-v3": "https://openaipublic.azureedge.net/main/whisper/models/e5b1a55b89c1367dacf97e3e19bfd829a01529dbfdeefa8caeb59b3f1b81dadb/large-v3.pt",
    "large": "https://openaipublic.azureedge.net/main/whisper/models/e5b1a55b89c1367dacf97e3e19bfd829a01529dbfdeefa8caeb59b3f1b81dadb/large-v3.pt",
}

如果要用large-v3就在load_model("large-v3"),模型会自动下载到.cache里的whisper,

我的电脑是C:\Users\lxf\.cache\whisper

 

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Whisper是一个开源的语音文字系统,它可以将语音信号换为对应的文本。在使用Whisper进行语音文字时,可以设置一些参数来优化换的效果。以下是一些常用的Whisper语音文字参数的介绍: 1. `sample_rate`:采样率,表示每秒钟采集的样本数。常见的采样率有8000、16000、44100等。 2. `frame_length`:帧长度,表示每一帧的音频信号的长度。通常使用的帧长度为20ms到40ms之间。 3. `hop_length`:帧移,表示相邻两帧之间的间隔。通常使用的帧移为10ms到20ms之间。 4. `n_fft`:傅里叶变换的窗口大小,用于将时域信号换为频域信号。通常使用的窗口大小为20ms到40ms之间。 5. `preemphasis_coefficient`:预加重系数,用于增强高频信号的能量。通常使用的预加重系数为0.95。 6. `min_level_db`和`ref_level_db`:用于控制音频信号的动态范围。`min_level_db`表示最小分贝数,`ref_level_db`表示参考分贝数。 7. `num_mels`:梅尔频率倒谱系数(Mel-frequency cepstral coefficients, MFCCs)的数量。通常使用的数量为80。 8. `fmin`和`fmax`:用于控制梅尔滤波器的频率范围。`fmin`表示最低频率,`fmax`表示最高频率。 9. `griffin_lim_iters`:Griffin-Lim算法的迭代次数,用于将梅尔频谱恢复为音频信号。 以上是一些常用的Whisper语音文字参数的介绍。根据具体的需求和场景,可以调整这些参数来获得更好的语音文字效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值