Moonshine v2 streaming small for RK3588: English speech recognition
Compiled models (.rnpu) for the Rockchip RK3588 / RK3588S NPU, ready to
load: no PyTorch, no ONNX export, no compiler run on your side. Two fp16 graphs
for the own NPU stack of RCDL, a C++17 /
Python library for vision and speech on these boards. RCDL's compiler built them
from ONNX, and its runtime runs them by driving the board's rknpu kernel driver
directly, so librknnrt and rknn-toolkit2 are not needed
(how the stack works).
They need RCDL 0.3.1 or newer.
English speech goes in as raw 16 kHz samples, with no feature front end, and
cased, punctuated text comes out. The encoder runs once over a 10 s window. The
decoder step then runs once a token, greedy from <s> to </s>, with the keys
and values of the tokens so far kept on the CPU between steps.
Upstream: Moonshine v2 streaming small,
exported through transformers' MoonshineStreaming by RCDL's
scripts/moonshine_export.py.
Redistributable, including commercially. Moonshine v2 streaming small is MIT. Moonshine's non-English models are under another licence and are not here. See Licence.
Files
| file | what it is | size |
|---|---|---|
moonshine_s_enc_10s_fp16.rnpu |
encoder: audio [1,160000] (10 s, zero padded) → every decoder layer's cross-attention keys and values [10,8,500,64] |
131.4 MB |
moonshine_s_step_l128_fp16.rnpu |
one decoder step: a token, its position, a 128-token self-attention cache and the cross-attention keys and values → logits [1,32768] and the step's new keys and values |
310.5 MB |
moonshine_s_tokens.json |
the vocabulary: SentencePiece pieces with byte fallback, as a JSON array | 0.3 MB |
A shorter clip is zero padded to the window, and the cross-attention mask hides the padding from the decoder.
Measured on RK3588S and RK3588
| RK3588S | RK3588 | |
|---|---|---|
| a 5.9 s LibriSpeech sentence → text | 818 ms | 759 ms |
| against LibriSpeech's transcript | 0 of 17 words wrong | the same |
English speech from rcdl-kokoro |
0 of 12 words wrong | the same |
RCDL 0.3.0 conda packages, RCDL's own NPU runtime, one NPU core, NPU driver
0.9.8; BSP kernel 6.1.118 on the RK3588S, 6.1.141 on the RK3588. The CPU
governor was performance, with the process pinned to the four A76 cores. Under
the boards' default schedutil, tasks that alternate NPU and CPU work measured
up to about four times slower, with the same results. On an RK3588 the
encoder's window takes 357 ms and each token 17.5 ms, so the time grows with the
length of the text.
On LibriSpeech and on SenseVoice's English test clips, the NPU builds give the float model's transcripts to the character.
Use it
On the board (linux-aarch64):
conda create -n rcdl -c https://mirrors.ruis.ai/conda -c conda-forge rcdl
conda activate rcdl
curl -LO https://huggingface.co/ruisv/rcdl-moonshine/resolve/main/moonshine_s_enc_10s_fp16.rnpu
curl -LO https://huggingface.co/ruisv/rcdl-moonshine/resolve/main/moonshine_s_step_l128_fp16.rnpu
curl -LO https://huggingface.co/ruisv/rcdl-moonshine/resolve/main/moonshine_s_tokens.json
import wave, numpy as np, rcdl
with wave.open("en.wav") as w: # 16 kHz mono PCM16
assert (w.getframerate(), w.getnchannels(), w.getsampwidth()) == (16000, 1, 2)
pcm = np.frombuffer(w.readframes(w.getnframes()), np.int16)
asr = rcdl.MoonshineAsr.from_files(
"moonshine_s_enc_10s_fp16.rnpu", "moonshine_s_step_l128_fp16.rnpu", "moonshine_s_tokens.json")
print(asr.transcribe(pcm))
What to know before deploying
English only, 16 kHz mono. There is no resampler; the samples may be float in [-1, 1] or int16.
One window is 10 s. A longer recording is cut into windows at the quietest
20 ms of each window's last 2 s (rcdl.quiet_cut), and each window is
transcribed on its own. Segments from a VAD
(rcdl-silero-vad) are better
still. A window yields at most 128 tokens, and at most 6.5 tokens a second of
audio.
The text is written as the float model writes it, with capitals and
punctuation. With silence around a sentence it may write "Mr." where it would
otherwise write "Mister". asr.decode_window(pcm) gives one window's token ids
instead of text.
Licence
MIT, on the Moonshine v2 streaming small weights; moonshine_s_tokens.json
is the same checkpoint's vocabulary. Moonshine's non-English models are under
another licence, and none of them is here.
RCDL itself is Apache-2.0 and is unrelated to these terms. It is a
general-purpose runtime that loads any .rnpu or .rknn. The licence above
applies to these weights and these files only.
scripts/moonshine_export.py
writes the two ONNX graphs, and the compiler flags of each build are beside it
in scripts/fetch_models.sh.
The input contract is in
docs/MODELS.md.
中文说明
这是 Moonshine v2 streaming small 面向瑞芯微 RK3588 / RK3588S NPU 的编译模型
(.rnpu),下载即可加载:不需要 PyTorch,不用导出 ONNX,也不用自己跑编译器。两个 fp16
计算图是为 RCDL 的自研 NPU 栈编译的:RCDL 的编译器从 ONNX
生成它们,RCDL 的运行时直接驱动板子上的 rknpu 内核驱动来执行,不需要 librknnrt,也不需要
rknn-toolkit2(自研栈介绍)。
需要 RCDL 0.3.1 或更新版本。
输入 16 kHz 原始采样的英文语音,不需要特征前端,输出带大小写和标点的文字。编码器对一个 10 s
窗口跑一次;之后解码器每个 token 跑一步,从 <s> 贪心解码到 </s>,已生成 token 的 key 和
value 在步与步之间由 CPU 保存。上游是
moonshine-ai/moonshine-streaming-small,
由 RCDL 的 scripts/moonshine_export.py 经 transformers 的 MoonshineStreaming 导出。
可以再分发,包括商用。 Moonshine v2 streaming small 是 MIT 许可。Moonshine 的非英语模型 用的是另一种许可,不在这里。
文件
| 文件 | 内容 | 大小 |
|---|---|---|
moonshine_s_enc_10s_fp16.rnpu |
编码器:音频 [1,160000](10 s,不足补零)→ 每个解码层交叉注意力的 key 和 value [10,8,500,64] |
131.4 MB |
moonshine_s_step_l128_fp16.rnpu |
单步解码器:一个 token、它的位置、128 个 token 的自注意力缓存和交叉注意力的 key / value → logits [1,32768] 以及这一步新的 key / value |
310.5 MB |
moonshine_s_tokens.json |
词表:带字节回退的 SentencePiece 片段,JSON 数组 | 0.3 MB |
较短的音频补零到窗口长度,交叉注意力的掩码让解码器看不到补零的部分。
实测
- 一句 5.9 s 的 LibriSpeech 英文:RK3588S 上 818 ms,RK3588 上 759 ms;与 LibriSpeech 的
标注相比 17 个词错 0 个。
rcdl-kokoro合成的英文 识别回来,12 个词错 0 个。两块板结果相同。 - 测量条件:RCDL 0.3.0 的 conda 包,自研 NPU 运行时,单个 NPU 核,NPU 驱动 0.9.8;
RK3588S 为 BSP 内核 6.1.118,RK3588 为 6.1.141。CPU 调频策略为
performance,进程绑在 四个 A76 核上;在板子默认的schedutil下,NPU 与 CPU 交替工作的任务最多会慢到约四倍, 结果不变。在 RK3588 上,编码器一个窗口 357 ms,每个 token 17.5 ms,所以耗时随文字长度增加。 - 在 LibriSpeech 和 SenseVoice 的英文测试音频上,NPU 构建的转写结果与浮点模型逐字相同。
用法
用法见上面的代码:装好 RCDL、下载三个文件,读入 en.wav 后一次调用 transcribe 得到文字。
部署前须知
- 只支持英文,16 kHz 单声道。 没有重采样;采样可以是 float([-1, 1])或 int16。
- 一个窗口 10 s。 更长的录音在每个窗口最后 2 s 中最安静的 20 ms 处切开(
rcdl.quiet_cut), 每个窗口单独识别;用 VAD(rcdl-silero-vad) 切出的句子效果更好。一个窗口最多 128 个 token,且每秒音频最多 6.5 个。 - 文字的写法与浮点模型一致,有大小写和标点;句子前后有静音时,可能把 "Mister" 写成 "Mr."。
asr.decode_window(pcm)返回一个窗口的 token id,而不是文字。
许可
Moonshine v2 streaming small 的权重为 MIT;moonshine_s_tokens.json 是同一检查点的词表。
Moonshine 的非英语模型用的是另一种许可,这里一个都没有。
RCDL 本身是 Apache-2.0,与上述条款无关。 它是通用运行时,能加载任何 .rnpu 或
.rknn;上述许可只适用于这些权重和这些文件。
Model tree for ruisv/rcdl-moonshine
Base model
moonshine-ai/moonshine-streaming-small