25acf9db6e
横向对比云端 gummy 与本地开源模型(faster-whisper/SenseVoice/Paraformer), 重点覆盖中英混说,产出准确率(CER/WER/MER)/速度(延迟/RTF)/资源(cpu/mem/模型大小) 对比报告。公共集(ASCEND/AISHELL/LibriSpeech)统一走 HF 适配器 + 自定义 JSONL manifest。 gummy 引擎对照 server/internal/asr/gummy.go 协议移植。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
35 lines
920 B
Python
35 lines
920 B
Python
"""数据集适配器基类与音频物料化工具。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from collections.abc import Iterator
|
|
|
|
import numpy as np
|
|
import soundfile as sf
|
|
|
|
from ..manifest import Sample
|
|
|
|
TARGET_SR = 16000
|
|
|
|
|
|
class Dataset:
|
|
name: str = "base"
|
|
|
|
def samples(self, limit: int | None = None) -> Iterator[Sample]:
|
|
raise NotImplementedError
|
|
|
|
|
|
def write_wav_16k(array: np.ndarray, sr: int, out_path: str) -> None:
|
|
"""把(可能任意采样率的)单/多声道数组写成 16k/mono/16bit wav。"""
|
|
os.makedirs(os.path.dirname(out_path), exist_ok=True)
|
|
data = np.asarray(array, dtype=np.float32)
|
|
if data.ndim > 1:
|
|
data = data.mean(axis=1)
|
|
if sr != TARGET_SR:
|
|
import soxr
|
|
|
|
data = soxr.resample(data, sr, TARGET_SR)
|
|
data = np.clip(data, -1.0, 1.0)
|
|
sf.write(out_path, (data * 32767.0).astype(np.int16), TARGET_SR, subtype="PCM_16")
|