python离线语音识别库whisper
本帖最后由 bob666zxj 于 2024-8-1 14:43 编辑推荐一个python离线语音识别库`whisper`
这是由openai发布的离线语音识别库,在github上有超过 65K 的Star
github:(https://github.com/openai/whisper)
下面是模型列表:
| 尺寸 | 参数数量 | 纯英语模式 | 多语言模型 | 所需 VRAM | 相对速度 |
| -------- | -------- | -------- |
| tiny | 39 M | tiny.en | tiny | ~1 GB | ~32x |
| base | 74 M | base.en | base | ~1 GB | ~16x |
| small | 244 M | small.en | small | ~2 GB | ~6x |
| medium | 769 M | medium.en | medium | ~5 GB | ~2x |
| large | 1550 M | N/A | large | ~10 GB | 1x |
### 运行环境:
需要ffmpeg,关于ffmpeg的下载请看这篇帖子(https://www.52pojie.cn/thread-1950306-1-1.html)
### python代码:
```python
import whisper
import zhconv
# 加载 whisper 模型,这里使用的是"tiny"版本
model = whisper.load_model("tiny")
'''
tiny 39 M tiny.en tiny ~1 GB ~32x
base 74 M base.en base ~1 GB ~16x
small 244 M small.en small ~2 GB ~6x
medium 769 M medium.en medium ~5 GB ~2x
large 1550 M N/A large ~10 GB 1x
'''
# 使用加载的模型对"1.wav"文件进行语音转文字处理
result = model.transcribe("1.wav")
print(result)
# 将转录结果中的文本转换为简体中文
result=zhconv.convert(result["text"], 'zh-cn')
print(result)
```
如果没有下载模型会自动下载模型,无需科学。 pipinstall whisper -i https://mirrors.aliyun.com/pypi/simple
DEPRECATION: Loading egg at /home/q9/miniforge3/lib/python3.12/site-packages/muggle_ocr-1.0.3-py3.12.egg is deprecated. pip 24.3 will enforce this behaviour change. A possible replacement is to use pip for package installation.. Discussion can be found at https://github.com/pypa/pip/issues/12330
Looking in indexes: https://mirrors.aliyun.com/pypi/simple
Collecting whisper
Downloading https://mirrors.aliyun.com/pypi/packages/b4/c3/913cdd13ef3d882fa483981378a08cd0f018fd8dd95b6bf006b9bf1cfbc9/whisper-1.1.10.tar.gz (42 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 42.8/42.8 kB 171.9 kB/s eta 0:00:00
Preparing metadata (setup.py) ... done
Requirement already satisfied: six in /home/q9/miniforge3/lib/python3.12/site-packages (from whisper) (1.16.0)
Building wheels for collected packages: whisper
Building wheel for whisper (setup.py) ... done
Created wheel for whisper: filename=whisper-1.1.10-py3-none-any.whl size=41120 sha256=b3be1aa7fe52541a79c44c072264887502d90bbe79ed11d253a027e18cbbfe94
Stored in directory: /home/q9/.cache/pip/wheels/a4/25/9e/80873926d30e583ee8e318c6beda99127842c9f6a8302bd25f
Successfully built whisper
Installing collected packages: whisper
Successfully installed whisper-1.1.10
(base) q9@q9-pc:~/Sounds$ pipinstall zhconv -i https://mirrors.aliyun.com/pypi/simple
DEPRECATION: Loading egg at /home/q9/miniforge3/lib/python3.12/site-packages/muggle_ocr-1.0.3-py3.12.egg is deprecated. pip 24.3 will enforce this behaviour change. A possible replacement is to use pip for package installation.. Discussion can be found at https://github.com/pypa/pip/issues/12330
Looking in indexes: https://mirrors.aliyun.com/pypi/simple
Collecting zhconv
Downloading https://mirrors.aliyun.com/pypi/packages/25/47/c8ae2d5d4025e253211ff3d8c163f457db1da94976cb582337a5ab76cb87/zhconv-1.4.3.tar.gz (211 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 211.6/211.6 kB 162.7 kB/s eta 0:00:00
Preparing metadata (setup.py) ... done
Building wheels for collected packages: zhconv
Building wheel for zhconv (setup.py) ... done
Created wheel for zhconv: filename=zhconv-1.4.3-py2.py3-none-any.whl size=208851 sha256=7328296dda4c1abed280c7ec3d706e54b15e232f183c0d9995ee2ab53212021e
Stored in directory: /home/q9/.cache/pip/wheels/36/d7/70/203f9ffe67d4d69c7b46c31984013ced8046ef4c298294fca0
Successfully built zhconv
Installing collected packages: zhconv
Successfully installed zhconv-1.4.3
(base) q9@q9-pc:~/Sounds$ python sound.py
Traceback (most recent call last):
File "/home/q9/Sounds/sound.py", line 5, in <module>
model = whisper.load_model("tiny")
^^^^^^^^^^^^^^^^^^
AttributeError: module 'whisper' has no attribute 'load_model'
1e3e 发表于 2024-8-1 17:00
pipinstall whisper -i https://mirrors.aliyun.com/pypi/simple
DEPRECATION: Loading egg at /home/q ...
这个问题我也不太清楚,我这里重装了whisper,也没能复现。你可以试一下卸载重新安装whisper。 封装成DLL其他语言可以实时调用就给力了 代码看上去好简洁,简单粗暴解决问题... 代码看上去有种简洁美,不过我刚入门学,部署什么的还很生疏{:301_999:} 蹲一个实测效果 大大,帮忙看看哈,不能运行的,安装库都是正常的。另外模型可以离线下载吗? 太难了,才入门呢,就挑战这个了
蹲一个实测效果
页:
[1]
2