CAM++ zh-en for RK3588: speaker embedding

Compiled model (.rnpu) for the Rockchip RK3588 / RK3588S NPU, ready to load: no ONNX export, no compiler run on your side. One fp16 graph for the own NPU stack of RCDL, a C++17 / Python library for vision and speech on these boards. RCDL's compiler built it from ONNX, and its runtime runs it by driving the board's rknpu kernel driver directly, so librknnrt and rknn-toolkit2 are not needed (how the stack works). It needs RCDL 0.3.1 or newer.

Who is speaking: 16 kHz audio goes in, and a unit-length 192-d voice embedding comes out. Two embeddings are compared by their dot product, which is their cosine: high for one speaker, low for two.

Upstream: CAM++ zh-en from 3D-Speaker, compiled from sherpa-onnx's ONNX export of it.

Redistributable, including commercially. CAM++ zh-en (3D-Speaker) is Apache-2.0. See Licence.

Files

file what it is size
campplus_zh_en_300_fp16.rnpu [1,300,80] fbank, a 3 s window → [1,192] embedding 14.8 MB

The front end runs on the CPU in RCDL: Kaldi fbank (Povey window, samples in [-1, 1]) minus the recording's mean in each bin. The window is 3.015 s. A shorter recording is repeated to fill it; a longer one is embedded in windows half a window apart, and the unit embeddings are averaged.

Measured on RK3588S and RK3588

RK3588S RK3588
one AISHELL-1 clip → embedding 45.5 ms 41.2 ms
of which one model run (one window) 41.7 ms 37.6 ms
one voice, two sentences cosine ≥ 0.869 the same
a voice against any other voice cosine ≤ 0.272 the same

The voices: two of Kokoro's (zf_001, zm_010), two Mandarin sentences each, and two AISHELL-1 speakers. 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 AISHELL-1 clips, the embeddings are the float model's to a cosine of 0.99997.

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-campplus/resolve/main/campplus_zh_en_300_fp16.rnpu
import wave, numpy as np, rcdl

def read(path):                                      # 16 kHz mono PCM16
    with wave.open(path) as w:
        assert (w.getframerate(), w.getnchannels(), w.getsampwidth()) == (16000, 1, 2)
        return np.frombuffer(w.readframes(w.getnframes()), np.int16)

spk = rcdl.SpeakerEmbedder.from_file("campplus_zh_en_300_fp16.rnpu")
zh, zh2, en = (spk.embed(read(f)) for f in ("zh.wav", "zh2.wav", "en.wav"))
THRESHOLD = 0.4                                      # calibrate on your own audio
for name, score in (("zh / zh2", zh @ zh2), ("zh / en", zh @ en), ("zh2 / en", zh2 @ en)):
    print(f"{name}: {score:+.3f}", "same speaker" if score > THRESHOLD else "different speakers")
print(f"{spk.dim}-d embeddings, {spk.window_seconds:.3f} s window")

What to know before deploying

Set the threshold on your own audio. The score is a cosine. For CAM++ on clean speech the line between one speaker and two lies at about 0.3 to 0.5; the example's 0.4 is a starting point, not a calibrated value.

16 kHz mono, no resampler. The samples may be float in [-1, 1] or int16. An empty recording gives an all-zero vector. spk.features(pcm) gives the front end's (frames, 80) features on their own.

Licence

Apache-2.0, on 3D-Speaker's CAM++ zh-en model, which this build was compiled from through sherpa-onnx's ONNX export.

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 this compiled file only.

The compiler flags of the build are in RCDL's scripts/fetch_models.sh, and its input contract in docs/MODELS.md.

中文说明

这是 CAM++ zh-en 面向瑞芯微 RK3588 / RK3588S NPU 的编译模型(.rnpu),下载即可加载: 不用导出 ONNX,也不用自己跑编译器。这一个 fp16 计算图是为 RCDL 的自研 NPU 栈编译的:RCDL 的编译器从 ONNX 生成它,RCDL 的运行时直接驱动板子上的 rknpu 内核驱动来执行,不需要 librknnrt,也不需要 rknn-toolkit2 (自研栈介绍)。需要 RCDL 0.3.1 或更新版本。

用来判断谁在说话:输入 16 kHz 音频,输出一个单位长度的 192 维声纹向量。两个向量的点积就是 余弦相似度,同一个人高,不同的人低。上游是 3D-Speaker 的 CAM++ zh-en,由 sherpa-onnx 的 ONNX 导出编译而来。

可以再分发,包括商用。 CAM++ zh-en(3D-Speaker)是 Apache-2.0 许可。

文件

文件 内容 大小
campplus_zh_en_300_fp16.rnpu [1,300,80] fbank(3 s 窗口)→ [1,192] 声纹向量 14.8 MB

前端在 RCDL 里由 CPU 完成:Kaldi fbank(Povey 窗,采样取 [-1, 1]),每个频带减去整段录音的 均值。窗口长 3.015 s;更短的录音重复填满窗口,更长的按半个窗口的间隔分窗,各窗的单位向量 取平均。

实测

  • 一段 AISHELL-1 音频 → 声纹向量:RK3588S 上 45.5 ms(其中模型跑一个窗口 41.7 ms), RK3588 上 41.2 ms(37.6 ms)。
  • 同一个音色的两句话,余弦 ≥ 0.869;一个音色与其他任何音色,余弦 ≤ 0.272。音色包括 Kokoro 的 zf_001 和 zm_010(各两句普通话) 以及两位 AISHELL-1 说话人。两块板结果相同。
  • 测量条件: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 交替工作的任务最多会慢到约四倍, 结果不变。
  • 在 AISHELL-1 音频上,声纹向量与浮点模型的余弦相似度为 0.99997。

用法

用法见上面的代码:装好 RCDL、下载模型,为 zh.wav、zh2.wav、en.wav 各算一个声纹向量, 两两打分,并按阈值判断是否同一个人。

部署前须知

  • 阈值要用自己的音频来定。 分数是余弦相似度;CAM++ 在干净语音上,同一人与不同人的分界 大约在 0.3 到 0.5 之间。示例里的 0.4 只是起点,不是标定过的值。
  • 16 kHz 单声道,没有重采样。 采样可以是 float([-1, 1])或 int16。空录音返回全零向量。 spk.features(pcm) 单独给出前端的 (帧数, 80) 特征。

许可

3D-Speaker 的 CAM++ zh-en 模型为 Apache-2.0,这个构建由 sherpa-onnx 的 ONNX 导出编译而来。

RCDL 本身是 Apache-2.0,与上述条款无关。 它是通用运行时,能加载任何 .rnpu 或 .rknn;上述许可只适用于这些权重和这个编译文件。

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support