NLP之ASR之moonshine:moonshine的简介、安装和使用方法、案例应用之详细攻略

NLP之ASR之moonshine:moonshine的简介、安装和使用方法、案例应用之详细攻略

目录

moonshine的简介

moonshine的安装和使用方法

1、安装

推荐使用uv管理Python环境

安装Moonshine包

Torch后端

TensorFlow后端

JAX后端

ONNX运行时

2、使用方法

0、测试

1、ONNX独立运行

2、实时字幕

3、翻译

4、 HuggingFace Transformers

moonshine的案例应用


moonshine的简介

2024年10月,Moonshine是一个针对资源受限设备优化的语音转文本 (ASR) 模型家族,旨在提供快速且准确的语音识别能力。它非常适合实时、设备端的应用,例如实时转录语音命令识别。Moonshine在HuggingFace的OpenASR排行榜上,其单词错误率 (WER) 表现优于同等规模的OpenAI Whisper模型(tiny.en 和 base.en)。

Moonshine 的计算需求与输入音频长度成正比,这意味着较短的音频处理速度更快,这与以30秒为块处理音频的Whisper模型不同。例如,Moonshine 处理10秒音频的速度是Whisper的5倍,同时保持相同或更好的WER。Moonshine Base模型大小约为400MB,Tiny模型约为190MB。目前公开发布的模型仅支持英语。

GitHub地址:https://github.com/usefulsensors/moonshine

moonshine的安装和使用方法

1、安装

推荐使用uv管理Python环境

若不使用uv,请跳过第一步。
创建虚拟环境: 首先,安装uv:

pip install uv

然后创建并激活虚拟环境:

uv venv env_moonshine
source env_moonshine/bin/activate

安装Moonshine包

Moonshine推理代码使用Keras编写,支持Torch、TensorFlow和JAX后端。选择后端决定安装哪个版本的Moonshine包。建议从Torch后端开始:

Torch后端

uv pip install useful-moonshine@git+https://github.com/usefulsensors/moonshine.git export KERAS_BACKEND=torch

TensorFlow后端

uv pip install useful-moonshine[tensorflow]@git+https://github.com/usefulsensors/moonshine.git export KERAS_BACKEND=tensorflow

JAX后端

uv pip install useful-moonshine[jax]@git+https://github.com/usefulsensors/moonshine.git export KERAS_BACKEND=jax (使用GPU: useful-moonshine[jax-cuda])

ONNX运行时

uv pip install useful-moonshine[onnx]@git+https://github.com/usefulsensors/moonshine.git

2、使用方法

0、测试

可以使用以下函数转录提供的示例音频文件来测试 Moonshine .transcribe:
使用.transcribe函数测试Moonshine:

>>> import moonshine
>>> moonshine.transcribe(moonshine.ASSETS_DIR / 'beckett.wav', 'moonshine/tiny')

['Ever tried ever failed, no matter try again, fail again, fail better.']

第一个参数是音频文件路径,第二个参数是Moonshine模型名称 (moonshine/tiny 或 moonshine/base)。使用moonshine.transcribe_with_onnx函数使用ONNX运行时进行推理,参数与moonshine.transcribe相同。

Moonshine模型可与多种运行时和应用程序一起使用。

1、ONNX独立运行

最新的ONNX Moonshine模型可在HuggingFace (huggingface.co/UsefulSensors/moonshine/tree/main/onnx) 获取,示例Python脚本和更多信息可在仓库的demo文件夹中找到。

2、实时字幕

可以使用live captions demo在许多平台上使用麦克风的实时输入来测试Moonshine模型。

3、翻译

CTranslate2版本的Moonshine文件可在HuggingFace (huggingface.co/UsefulSensors/moonshine/tree/main/ctranslate2) 获取,但需要合并pull request才能与框架的主线版本一起使用。可以使用项目的特定分支和示例脚本进行尝试。

4、 HuggingFace Transformers

两个模型都可在HuggingFace Hub上使用,并可与transformers库一起使用 (代码示例见GitHub项目)。

from transformers import AutoModelForSpeechSeq2Seq, AutoConfig, PreTrainedTokenizerFast

import torchaudio
import sys

audio, sr = torchaudio.load(sys.argv[1])
if sr != 16000:
  audio = torchaudio.functional.resample(audio, sr, 16000)

# 'usefulsensors/moonshine-base' for the base model
model = AutoModelForSpeechSeq2Seq.from_pretrained('usefulsensors/moonshine-tiny', trust_remote_code=True)
tokenizer = PreTrainedTokenizerFast.from_pretrained('usefulsensors/moonshine-tiny')

tokens = model(audio)
print(tokenizer.decode(tokens[0], skip_special_tokens=True))

moonshine的案例应用

持续更新中……

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一个处女座的程序猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值