当前位置:   article > 正文

【xinference】(3):在autodl上,使用xinference部署whisper-tiny音频模型,并成功将语音转换成文本,测试成功,还支持音频直接翻译成英文_faster-whisper centos autodl

faster-whisper centos autodl

1,视频地址

https://www.bilibili.com/video/BV1Z7421K7vL/

【xinference】(3):在autodl上,使用xinference部署whisper-tiny音频模型,并成功将语音转换成文本

2,项目地址

https://inference.readthedocs.io/zh-cn/latest/user_guide/model_abilities/audio.html

在这里插入图片描述

模型需要执行脚本启动:

pip3 install "xinference[all]"

apt update && apt install -y ffmpeg

# 设置学术加速,不再区分不同地区
# https://www.autodl.com/docs/network_turbo/
source /etc/network_turbo


export XINFERENCE_MODEL_SRC=modelscope
export XINFERENCE_HOME=/root/autodl-tmp

# 首先启动 xinference-local :
xinference-local --host 0.0.0.0 --port 9997 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

3,下载模型

执行命令:


# 大模型
xinference launch --model-uid whisper-1 --model-name whisper-large-v3 --model-type audio
# 小模型
xinference launch --model-uid whisper-1 --model-name whisper-tiny --model-type audio
  • 1
  • 2
  • 3
  • 4
  • 5

如果大模型下载异常,可以使用小模型下载。
启动成功,占用显存 3G

nvidia-smi 
Wed Jan 31 23:54:27 2024       
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.146.02             Driver Version: 535.146.02   CUDA Version: 12.2     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 3080        On  | 00000000:86:00.0 Off |                  N/A |
|  0%   25C    P8              15W / 320W |   3405MiB / 20480MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                         
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
+---------------------------------------------------------------------------------------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

4,测试代码

from xinference.client import Client

client = Client("http://localhost:9997")

# xinference launch --model-uid whisper-1 --model-name whisper-tiny --model-type audio
# model_uid = client.launch_model(model_uid="whisper-1",model_name="whisper-tiny", model_type="audio")
# whisper-tiny

model = client.get_model("whisper-1")

input_text = "an apple"
with open("voice-test.mp3", "rb") as audio_file:
    out = model.transcriptions(audio_file.read())
    print(out['text'])
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

执行结果:
本列表列出香港航空的航点,正确。

音频文件在这里:
https://github.com/xorbitsai/inference/tree/main/xinference/model/audio/tests

5,总结

确实可以运行音频大模型。可以将音频文件转换成文本。
可以做啥呢?可以直接录用转文字,或者做字幕。

transcriptions 是音频转文本
translations 可以直接将音频翻译成英文。

使用large 模型就可以翻译:

本列表列出香港航空的航点 > 翻译成:
This list lists the airlines in Hong Kong.
还集成了翻译模块。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/351414
推荐阅读
相关标签
  

闽ICP备14008679号