webfm eval set: 40 sentences, 8 voice prompts, scoring harness
Browse files- README.md +58 -0
- config/ming_voices.json +101 -0
- eval/score.py +271 -0
- eval/sentences.json +61 -0
- eval/t2s.json +40 -0
- kaggle/bake_voices.py +100 -0
- kaggle/ming_eval.py +318 -0
- refs/wav/v01.wav +3 -0
- refs/wav/v02.wav +3 -0
- refs/wav/v03.wav +3 -0
- refs/wav/v04.wav +3 -0
- refs/wav/v05.wav +3 -0
- refs/wav/v06.wav +3 -0
- refs/wav/v07.wav +3 -0
- refs/wav/v08.wav +3 -0
README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- zh
|
| 5 |
+
tags:
|
| 6 |
+
- text-to-speech
|
| 7 |
+
- evaluation
|
| 8 |
+
- webfm
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# webfm-eval
|
| 12 |
+
|
| 13 |
+
Fixed evaluation set and harness for the WebFM TTS work. Small on purpose: it
|
| 14 |
+
exists so two model tiers can be compared on the same sentences in the same
|
| 15 |
+
run, not to be trained on.
|
| 16 |
+
|
| 17 |
+
## Contents
|
| 18 |
+
|
| 19 |
+
```
|
| 20 |
+
eval/sentences.json 40 sentences, 7 buckets (short / medium / long /
|
| 21 |
+
number / latin / polyphone / narration)
|
| 22 |
+
eval/score.py raw + normalised CER, prefix CER, per-bucket and
|
| 23 |
+
per-voice aggregation, delta against a baseline
|
| 24 |
+
eval/t2s.json traditional -> simplified table, used only when
|
| 25 |
+
opencc is unavailable
|
| 26 |
+
config/ming_voices.json the eight WebFM voices and their prompt transcripts
|
| 27 |
+
refs/wav/v01..v08.wav prompt clips, reconstructed from the shipped F5
|
| 28 |
+
reference mels
|
| 29 |
+
kaggle/bake_voices.py prompt_latent + CAM++ speaker_emb for each voice
|
| 30 |
+
kaggle/ming_eval.py teacher x student matrix, resumable per cell
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
## Why the scoring is fussy
|
| 34 |
+
|
| 35 |
+
Whisper usually transcribes Chinese in traditional characters. Comparing that
|
| 36 |
+
against simplified references and counting character differences adds tens of
|
| 37 |
+
points of fake error. Every score here is reported twice: `cer_raw` (as
|
| 38 |
+
produced) and `cer_norm` (after traditional->simplified, punctuation stripped).
|
| 39 |
+
The gap is measurement, not model quality.
|
| 40 |
+
|
| 41 |
+
`cer_prefix` scores only the first four characters. A garbled opening syllable
|
| 42 |
+
barely moves overall CER but ruins a radio line, and it is the failure mode that
|
| 43 |
+
weight-only int4 quantisation produced on the 3-step student.
|
| 44 |
+
|
| 45 |
+
## Usage
|
| 46 |
+
|
| 47 |
+
```bash
|
| 48 |
+
python3 eval/score.py selftest
|
| 49 |
+
python3 eval/score.py aggregate --results results.jsonl --baseline teacher --by-bucket
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
`results.jsonl` carries one row per generated utterance:
|
| 53 |
+
`{id, model, voice, text, hyp_text, spk_cos?, mel_l1?, dur_ratio?}`.
|
| 54 |
+
|
| 55 |
+
## Licence
|
| 56 |
+
|
| 57 |
+
MIT for the code. The prompt clips derive from a purchased SFW corpus; check the
|
| 58 |
+
source terms before commercial use.
|
config/ming_voices.json
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"version": 1,
|
| 3 |
+
"voices": [
|
| 4 |
+
{
|
| 5 |
+
"id": "v01",
|
| 6 |
+
"name": "声线 01",
|
| 7 |
+
"nameEn": "VOICE 01",
|
| 8 |
+
"promptWav": "refs/wav/v01.wav",
|
| 9 |
+
"promptText": "然后再放松你的嘴唇和下巴,轻轻地摊开你的四周,",
|
| 10 |
+
"sampleRate": 24000,
|
| 11 |
+
"seconds": 6.6,
|
| 12 |
+
"accent": "#ffcf9e",
|
| 13 |
+
"sfw": true,
|
| 14 |
+
"source": "webfm-f5-mel-vocoded"
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"id": "v02",
|
| 18 |
+
"name": "声线 02",
|
| 19 |
+
"nameEn": "VOICE 02",
|
| 20 |
+
"promptWav": "refs/wav/v02.wav",
|
| 21 |
+
"promptText": "我們從這裡 進入了另外一個更廣闊的空間",
|
| 22 |
+
"sampleRate": 24000,
|
| 23 |
+
"seconds": 6.0,
|
| 24 |
+
"accent": "#9ecbff",
|
| 25 |
+
"sfw": true,
|
| 26 |
+
"source": "webfm-f5-mel-vocoded"
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"id": "v03",
|
| 30 |
+
"name": "声线 03",
|
| 31 |
+
"nameEn": "VOICE 03",
|
| 32 |
+
"promptWav": "refs/wav/v03.wav",
|
| 33 |
+
"promptText": "嗯很舒服用一个你觉得舒服",
|
| 34 |
+
"sampleRate": 24000,
|
| 35 |
+
"seconds": 6.0,
|
| 36 |
+
"accent": "#b9a6ff",
|
| 37 |
+
"sfw": true,
|
| 38 |
+
"source": "webfm-f5-mel-vocoded"
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
"id": "v04",
|
| 42 |
+
"name": "声线 04",
|
| 43 |
+
"nameEn": "VOICE 04",
|
| 44 |
+
"promptWav": "refs/wav/v04.wav",
|
| 45 |
+
"promptText": "现在是我的灵魂在说话。",
|
| 46 |
+
"sampleRate": 24000,
|
| 47 |
+
"seconds": 2.8,
|
| 48 |
+
"accent": "#8fe3c8",
|
| 49 |
+
"sfw": true,
|
| 50 |
+
"source": "webfm-f5-mel-vocoded"
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"id": "v05",
|
| 54 |
+
"name": "声线 05",
|
| 55 |
+
"nameEn": "VOICE 05",
|
| 56 |
+
"promptWav": "refs/wav/v05.wav",
|
| 57 |
+
"promptText": "小兔子都睡觉了,那我们小狗要不要睡觉呀?",
|
| 58 |
+
"sampleRate": 24000,
|
| 59 |
+
"seconds": 6.0,
|
| 60 |
+
"accent": "#ffb4c8",
|
| 61 |
+
"sfw": true,
|
| 62 |
+
"source": "webfm-f5-mel-vocoded"
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"id": "v06",
|
| 66 |
+
"name": "声线 06",
|
| 67 |
+
"nameEn": "VOICE 06",
|
| 68 |
+
"promptWav": "refs/wav/v06.wav",
|
| 69 |
+
"promptText": "对于我露瑟瑟念的这个神像你们有什么比较",
|
| 70 |
+
"sampleRate": 24000,
|
| 71 |
+
"seconds": 6.0,
|
| 72 |
+
"accent": "#93d7ff",
|
| 73 |
+
"sfw": true,
|
| 74 |
+
"source": "webfm-f5-mel-vocoded"
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"id": "v07",
|
| 78 |
+
"name": "声线 07",
|
| 79 |
+
"nameEn": "VOICE 07",
|
| 80 |
+
"promptWav": "refs/wav/v07.wav",
|
| 81 |
+
"promptText": "好,睡吧,睡吧,睡吧吧,给你一个睡,睡吧。",
|
| 82 |
+
"sampleRate": 24000,
|
| 83 |
+
"seconds": 6.0,
|
| 84 |
+
"accent": "#ffd59e",
|
| 85 |
+
"sfw": true,
|
| 86 |
+
"source": "webfm-f5-mel-vocoded"
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
"id": "v08",
|
| 90 |
+
"name": "声线 08",
|
| 91 |
+
"nameEn": "VOICE 08",
|
| 92 |
+
"promptWav": "refs/wav/v08.wav",
|
| 93 |
+
"promptText": "那么请仰躺在床上深呼吸之后",
|
| 94 |
+
"sampleRate": 24000,
|
| 95 |
+
"seconds": 6.0,
|
| 96 |
+
"accent": "#f5a6ff",
|
| 97 |
+
"sfw": true,
|
| 98 |
+
"source": "webfm-f5-mel-vocoded"
|
| 99 |
+
}
|
| 100 |
+
]
|
| 101 |
+
}
|
eval/score.py
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Score Ming TTS candidates on the fixed eval set in eval/sentences.json.
|
| 3 |
+
|
| 4 |
+
Two numbers are always reported:
|
| 5 |
+
|
| 6 |
+
- `cer_raw` — character error rate on the ASR transcript exactly as produced.
|
| 7 |
+
- `cer_norm` — same, after traditional->simplified, full-width folding and
|
| 8 |
+
punctuation stripping.
|
| 9 |
+
|
| 10 |
+
The gap between them is a measurement artefact, not model quality. Whisper
|
| 11 |
+
usually emits Chinese in traditional characters; comparing that to simplified
|
| 12 |
+
references can add 30-50 points of fake error. Always report both, and always
|
| 13 |
+
compare a candidate against a baseline measured in the same run.
|
| 14 |
+
|
| 15 |
+
Input is JSONL, one row per generated utterance:
|
| 16 |
+
|
| 17 |
+
{"id": "s01", "model": "3step", "voice": "v01", "text": "...",
|
| 18 |
+
"hyp_text": "...", "spk_cos": 0.91, "mel_l1": 3.2, "dur_ratio": 1.00}
|
| 19 |
+
|
| 20 |
+
`text` and `hyp_text` are required; audio metrics are optional and only
|
| 21 |
+
aggregated when present.
|
| 22 |
+
|
| 23 |
+
Usage:
|
| 24 |
+
python3 eval/score.py aggregate --results runs/eval.jsonl --baseline teacher
|
| 25 |
+
python3 eval/score.py selftest
|
| 26 |
+
"""
|
| 27 |
+
from __future__ import annotations
|
| 28 |
+
|
| 29 |
+
import argparse
|
| 30 |
+
import json
|
| 31 |
+
import sys
|
| 32 |
+
import unicodedata
|
| 33 |
+
from pathlib import Path
|
| 34 |
+
|
| 35 |
+
HERE = Path(__file__).resolve().parent
|
| 36 |
+
PUNCT = set(",。、;:?!“”‘’()《》〈〉【】…—·「」『』,.;:?!!()[]<>\"'`~-_/\\|@#$%^&*+= \t\n\r")
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def load_t2s() -> dict[str, str]:
|
| 40 |
+
try:
|
| 41 |
+
import opencc # type: ignore
|
| 42 |
+
|
| 43 |
+
conv = opencc.OpenCC("t2s")
|
| 44 |
+
|
| 45 |
+
return {"__opencc__": conv} # type: ignore[dict-item]
|
| 46 |
+
except Exception:
|
| 47 |
+
pass
|
| 48 |
+
path = HERE / "t2s.json"
|
| 49 |
+
if not path.exists():
|
| 50 |
+
return {}
|
| 51 |
+
return json.loads(path.read_text())["map"]
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def to_simplified(text: str, table: dict) -> str:
|
| 55 |
+
conv = table.get("__opencc__")
|
| 56 |
+
if conv is not None:
|
| 57 |
+
return conv.convert(text)
|
| 58 |
+
return "".join(table.get(ch, ch) for ch in text)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def strip_text(text: str) -> str:
|
| 62 |
+
text = unicodedata.normalize("NFKC", text or "")
|
| 63 |
+
out = []
|
| 64 |
+
for ch in text:
|
| 65 |
+
if ch in PUNCT or ch.isspace():
|
| 66 |
+
continue
|
| 67 |
+
if "\u4e00" <= ch <= "\u9fff" or ch.isalnum():
|
| 68 |
+
out.append(ch.lower())
|
| 69 |
+
return "".join(out)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def normalize(text: str, table: dict, simplify: bool) -> str:
|
| 73 |
+
if simplify:
|
| 74 |
+
text = to_simplified(text, table)
|
| 75 |
+
return strip_text(text)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def edit_distance(a: str, b: str) -> int:
|
| 79 |
+
if a == b:
|
| 80 |
+
return 0
|
| 81 |
+
if not a:
|
| 82 |
+
return len(b)
|
| 83 |
+
if not b:
|
| 84 |
+
return len(a)
|
| 85 |
+
prev = list(range(len(b) + 1))
|
| 86 |
+
for i, ca in enumerate(a, 1):
|
| 87 |
+
cur = [i]
|
| 88 |
+
for j, cb in enumerate(b, 1):
|
| 89 |
+
cur.append(min(cur[-1] + 1, prev[j] + 1, prev[j - 1] + (ca != cb)))
|
| 90 |
+
prev = cur
|
| 91 |
+
return prev[-1]
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def cer(ref: str, hyp: str) -> float:
|
| 95 |
+
if not ref:
|
| 96 |
+
return 0.0 if not hyp else 1.0
|
| 97 |
+
return edit_distance(ref, hyp) / len(ref)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def score_row(row: dict, table: dict) -> dict:
|
| 101 |
+
ref_raw = strip_text(row["text"])
|
| 102 |
+
hyp_raw = strip_text(row["hyp_text"])
|
| 103 |
+
ref_norm = normalize(row["text"], table, True)
|
| 104 |
+
hyp_norm = normalize(row["hyp_text"], table, True)
|
| 105 |
+
head = min(4, len(ref_norm))
|
| 106 |
+
return {
|
| 107 |
+
"cer_raw": cer(ref_raw, hyp_raw),
|
| 108 |
+
"cer_norm": cer(ref_norm, hyp_norm),
|
| 109 |
+
"cer_prefix": cer(ref_norm[:head], hyp_norm[:head]) if head else 0.0,
|
| 110 |
+
"ref_norm": ref_norm,
|
| 111 |
+
"hyp_norm": hyp_norm,
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def mean(values: list[float]) -> float | None:
|
| 116 |
+
values = [v for v in values if v is not None]
|
| 117 |
+
return sum(values) / len(values) if values else None
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def aggregate(rows: list[dict], table: dict, baseline: str | None) -> dict:
|
| 121 |
+
sentences = {i["id"]: i for i in json.loads((HERE / "sentences.json").read_text())["items"]}
|
| 122 |
+
scored: list[dict] = []
|
| 123 |
+
for row in rows:
|
| 124 |
+
entry = dict(row)
|
| 125 |
+
entry.update(score_row(row, table))
|
| 126 |
+
bucket = sentences.get(row.get("id", ""), {}).get("bucket", "unknown")
|
| 127 |
+
entry["bucket"] = bucket
|
| 128 |
+
scored.append(entry)
|
| 129 |
+
|
| 130 |
+
models: dict[str, dict] = {}
|
| 131 |
+
for entry in scored:
|
| 132 |
+
m = models.setdefault(entry["model"], {"rows": [], "by_bucket": {}, "voices": {}})
|
| 133 |
+
m["rows"].append(entry)
|
| 134 |
+
m["by_bucket"].setdefault(entry["bucket"], []).append(entry)
|
| 135 |
+
m["voices"].setdefault(entry.get("voice", "-"), []).append(entry)
|
| 136 |
+
|
| 137 |
+
summary: dict[str, dict] = {}
|
| 138 |
+
for name, m in models.items():
|
| 139 |
+
rows_m = m["rows"]
|
| 140 |
+
summary[name] = {
|
| 141 |
+
"n": len(rows_m),
|
| 142 |
+
"cer_raw": mean([r["cer_raw"] for r in rows_m]),
|
| 143 |
+
"cer_norm": mean([r["cer_norm"] for r in rows_m]),
|
| 144 |
+
"cer_prefix": mean([r["cer_prefix"] for r in rows_m]),
|
| 145 |
+
"spk_cos": mean([r.get("spk_cos") for r in rows_m]),
|
| 146 |
+
"mel_l1": mean([r.get("mel_l1") for r in rows_m]),
|
| 147 |
+
"dur_ratio": mean([r.get("dur_ratio") for r in rows_m]),
|
| 148 |
+
"by_bucket": {
|
| 149 |
+
b: {
|
| 150 |
+
"n": len(rs),
|
| 151 |
+
"cer_norm": mean([r["cer_norm"] for r in rs]),
|
| 152 |
+
}
|
| 153 |
+
for b, rs in m["by_bucket"].items()
|
| 154 |
+
},
|
| 155 |
+
"by_voice": {
|
| 156 |
+
v: {
|
| 157 |
+
"n": len(rs),
|
| 158 |
+
"cer_norm": mean([r["cer_norm"] for r in rs]),
|
| 159 |
+
"spk_cos": mean([r.get("spk_cos") for r in rs]),
|
| 160 |
+
}
|
| 161 |
+
for v, rs in m["voices"].items()
|
| 162 |
+
},
|
| 163 |
+
"worst": sorted(rows_m, key=lambda r: -r["cer_norm"])[:5],
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
if baseline and baseline in summary:
|
| 167 |
+
base = summary[baseline]
|
| 168 |
+
for name, s in summary.items():
|
| 169 |
+
if name == baseline:
|
| 170 |
+
continue
|
| 171 |
+
s["delta_vs_baseline"] = {
|
| 172 |
+
"cer_norm_pp": None
|
| 173 |
+
if s["cer_norm"] is None or base["cer_norm"] is None
|
| 174 |
+
else (s["cer_norm"] - base["cer_norm"]) * 100,
|
| 175 |
+
"spk_cos": None
|
| 176 |
+
if s["spk_cos"] is None or base["spk_cos"] is None
|
| 177 |
+
else s["spk_cos"] - base["spk_cos"],
|
| 178 |
+
}
|
| 179 |
+
return {"models": summary, "scored": scored}
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def print_table(summary: dict) -> None:
|
| 183 |
+
print(f"{'model':<14}{'n':>5}{'cer_raw':>10}{'cer_norm':>10}{'cer_head':>10}{'spk_cos':>10}{'dur':>8}")
|
| 184 |
+
for name, s in sorted(summary.items(), key=lambda kv: (kv[1]["cer_norm"] or 0)):
|
| 185 |
+
def fmt(v, p=4):
|
| 186 |
+
return "-" if v is None else f"{v:.{p}f}"
|
| 187 |
+
|
| 188 |
+
print(f"{name:<14}{s['n']:>5}{fmt(s['cer_raw']):>10}{fmt(s['cer_norm']):>10}"
|
| 189 |
+
f"{fmt(s['cer_prefix'], 3):>10}{fmt(s['spk_cos'], 3):>10}{fmt(s['dur_ratio'], 3):>8}")
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
def cmd_aggregate(args) -> int:
|
| 193 |
+
table = load_t2s()
|
| 194 |
+
rows = []
|
| 195 |
+
with open(args.results) as f:
|
| 196 |
+
for line in f:
|
| 197 |
+
line = line.strip()
|
| 198 |
+
if line:
|
| 199 |
+
rows.append(json.loads(line))
|
| 200 |
+
if not rows:
|
| 201 |
+
print("no rows", file=sys.stderr)
|
| 202 |
+
return 1
|
| 203 |
+
result = aggregate(rows, table, args.baseline)
|
| 204 |
+
print_table(result["models"])
|
| 205 |
+
if args.baseline and any("delta_vs_baseline" in s for s in result["models"].values()):
|
| 206 |
+
print(f"\ndelta vs {args.baseline} (negative CER delta is better):")
|
| 207 |
+
for name, s in result["models"].items():
|
| 208 |
+
d = s.get("delta_vs_baseline")
|
| 209 |
+
if d:
|
| 210 |
+
print(f" {name:<12} cer {'%+.2f' % d['cer_norm_pp']} pp "
|
| 211 |
+
f"spk {'%+.3f' % d['spk_cos'] if d['spk_cos'] is not None else '-'}")
|
| 212 |
+
if args.by_bucket:
|
| 213 |
+
print("\ncer_norm by bucket:")
|
| 214 |
+
buckets = sorted({b for s in result["models"].values() for b in s["by_bucket"]})
|
| 215 |
+
print(f"{'model':<14}" + "".join(f"{b:>12}" for b in buckets))
|
| 216 |
+
for name, s in result["models"].items():
|
| 217 |
+
cells = []
|
| 218 |
+
for b in buckets:
|
| 219 |
+
v = s["by_bucket"].get(b, {}).get("cer_norm")
|
| 220 |
+
cells.append(f"{v:.3f}" if v is not None else "-")
|
| 221 |
+
print(f"{name:<14}" + "".join(f"{c:>12}" for c in cells))
|
| 222 |
+
if args.out:
|
| 223 |
+
Path(args.out).parent.mkdir(parents=True, exist_ok=True)
|
| 224 |
+
Path(args.out).write_text(json.dumps(result, ensure_ascii=False, indent=2))
|
| 225 |
+
print(f"\nwrote {args.out}")
|
| 226 |
+
return 0
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
SELFTEST = [
|
| 230 |
+
("雨落在窗台上,远处的灯一盏一盏亮起来。", "雨落在窗台上遠處的燈一盞一盞亮起來", 0.0),
|
| 231 |
+
("风从门缝里进来,带着一点潮湿的木头气味。", "風從門縫裡進來帶著一點潮濕的木頭氣味", 0.0),
|
| 232 |
+
("她把杯子放在桌边,屋里的光慢慢暗下去。", "他把杯子放在桌邊屋裡的光慢慢按下去", 2 / 17),
|
| 233 |
+
]
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def cmd_selftest(_args) -> int:
|
| 237 |
+
table = load_t2s()
|
| 238 |
+
backend = "opencc" if "__opencc__" in table else "bundled table"
|
| 239 |
+
print(f"t2s backend: {backend}\n")
|
| 240 |
+
ok = True
|
| 241 |
+
for ref, hyp, expect in SELFTEST:
|
| 242 |
+
s = score_row({"text": ref, "hyp_text": hyp}, table)
|
| 243 |
+
flag = "ok" if abs(s["cer_norm"] - expect) < 0.02 else "MISMATCH"
|
| 244 |
+
if flag != "ok":
|
| 245 |
+
ok = False
|
| 246 |
+
print(f"raw {s['cer_raw']:.3f} -> norm {s['cer_norm']:.3f} "
|
| 247 |
+
f"(expect {expect:.3f}) {flag}\n {s['hyp_norm']}")
|
| 248 |
+
if not ok:
|
| 249 |
+
print("\nselftest failed", file=sys.stderr)
|
| 250 |
+
return 1
|
| 251 |
+
print("\nselftest ok")
|
| 252 |
+
return 0
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
def main() -> int:
|
| 256 |
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
|
| 257 |
+
sub = ap.add_subparsers(dest="cmd", required=True)
|
| 258 |
+
a = sub.add_parser("aggregate")
|
| 259 |
+
a.add_argument("--results", required=True)
|
| 260 |
+
a.add_argument("--baseline", default=None)
|
| 261 |
+
a.add_argument("--out", default=None)
|
| 262 |
+
a.add_argument("--by-bucket", action="store_true")
|
| 263 |
+
a.set_defaults(func=cmd_aggregate)
|
| 264 |
+
s = sub.add_parser("selftest")
|
| 265 |
+
s.set_defaults(func=cmd_selftest)
|
| 266 |
+
args = ap.parse_args()
|
| 267 |
+
return args.func(args)
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
if __name__ == "__main__":
|
| 271 |
+
raise SystemExit(main())
|
eval/sentences.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"version": 1,
|
| 3 |
+
"note": "Fixed evaluation set for the Ming TTS migration. Every model tier is scored on exactly these ids. Do not tune anything against this set; it exists to be compared, not improved.",
|
| 4 |
+
"buckets": {
|
| 5 |
+
"short": "8-14 characters, the shape most spoken lines take",
|
| 6 |
+
"medium": "15-25 characters, a normal multi-clause line",
|
| 7 |
+
"long": "26-45 characters, where a 3-step student tends to drift or repeat",
|
| 8 |
+
"number": "digits, dates, percentages, ordinals",
|
| 9 |
+
"latin": "Latin words and acronyms inside Chinese",
|
| 10 |
+
"polyphone": "调/着/得 traps that the F5 pinyin table used to patch by hand",
|
| 11 |
+
"narration": "book-page style, close to the verbatim reading path"
|
| 12 |
+
},
|
| 13 |
+
"items": [
|
| 14 |
+
{ "id": "s01", "bucket": "short", "text": "灯关小一点,我们慢慢来。" },
|
| 15 |
+
{ "id": "s02", "bucket": "short", "text": "外面在下雨。" },
|
| 16 |
+
{ "id": "s03", "bucket": "short", "text": "别急,先呼吸。" },
|
| 17 |
+
{ "id": "s04", "bucket": "short", "text": "今天有点冷。" },
|
| 18 |
+
{ "id": "s05", "bucket": "short", "text": "你醒着吗?" },
|
| 19 |
+
{ "id": "s06", "bucket": "short", "text": "声音轻一点。" },
|
| 20 |
+
|
| 21 |
+
{ "id": "m01", "bucket": "medium", "text": "窗外的雨一直没有停,楼下的车声也少了。" },
|
| 22 |
+
{ "id": "m02", "bucket": "medium", "text": "他把外套挂在门后,然后坐回了那把旧椅子上。" },
|
| 23 |
+
{ "id": "m03", "bucket": "medium", "text": "如果你还不想睡,我们可以再聊一会儿。" },
|
| 24 |
+
{ "id": "m04", "bucket": "medium", "text": "这条街以前有两家书店,现在只剩一家。" },
|
| 25 |
+
{ "id": "m05", "bucket": "medium", "text": "火车的灯从远处过来,又慢慢开走了。" },
|
| 26 |
+
{ "id": "m06", "bucket": "medium", "text": "杯子里的水已经凉了,屋顶上还有一点风。" },
|
| 27 |
+
{ "id": "m07", "bucket": "medium", "text": "她把窗帘拉开一条缝,看了看外面的天。" },
|
| 28 |
+
{ "id": "m08", "bucket": "medium", "text": "睡不着的夜里,时间会走得特别慢。" },
|
| 29 |
+
|
| 30 |
+
{ "id": "l01", "bucket": "long", "text": "雨从傍晚开始下,一直没停,窗户上蒙了一层薄薄的水汽,把外面的灯都晕开了。" },
|
| 31 |
+
{ "id": "l02", "bucket": "long", "text": "很多年以后,他还是记得那个下午,教室里很安静,只有粉笔在黑板上划过的声音。" },
|
| 32 |
+
{ "id": "l03", "bucket": "long", "text": "她在站台上等了很久,风把围巾吹起来,广播里重复着那趟已经晚点的列车。" },
|
| 33 |
+
{ "id": "l04", "bucket": "long", "text": "那条河从城西一直流到城东,夏天的时候孩子们会在浅水处玩水,冬天就结了很厚的冰。" },
|
| 34 |
+
{ "id": "l05", "bucket": "long", "text": "他慢慢走到窗前,把杯子放在窗台上,看着外面的雨一点一点变密,觉得今天可以早点睡了。" },
|
| 35 |
+
{ "id": "l06", "bucket": "long", "text": "老屋的房梁上还挂着一盏灯,光很暗,照不亮墙角,只够看见桌上那本翻旧了的书。" },
|
| 36 |
+
{ "id": "l07", "bucket": "long", "text": "夜班的护士推着车走过走廊,鞋底和地面摩擦出很轻的声音,病房里的人大多已经睡下了。" },
|
| 37 |
+
{ "id": "l08", "bucket": "long", "text": "她把那封信读了第三遍,然后折好放回抽屉,窗外的天已经开始亮了,鸟叫得很轻。" },
|
| 38 |
+
|
| 39 |
+
{ "id": "n01", "bucket": "number", "text": "现在还差五分十二点。" },
|
| 40 |
+
{ "id": "n02", "bucket": "number", "text": "从一九九八年到二零零六年,这条街变了三次。" },
|
| 41 |
+
{ "id": "n03", "bucket": "number", "text": "这趟车晚点三十分钟,站台上有一百多人。" },
|
| 42 |
+
{ "id": "n04", "bucket": "number", "text": "第三病房在二楼,走廊尽头右转。" },
|
| 43 |
+
{ "id": "n05", "bucket": "number", "text": "他数到第两百下的时候,终于听见了雨声。" },
|
| 44 |
+
{ "id": "n06", "bucket": "number", "text": "房租涨了百分之二十,她决定搬到城北去。" },
|
| 45 |
+
|
| 46 |
+
{ "id": "x01", "bucket": "latin", "text": "我把 Wi-Fi 密码写在便签上了。" },
|
| 47 |
+
{ "id": "x02", "bucket": "latin", "text": "这首歌的名字是 Blue Hour。" },
|
| 48 |
+
{ "id": "x03", "bucket": "latin", "text": "他的 MP3 里只有十几首歌。" },
|
| 49 |
+
{ "id": "x04", "bucket": "latin", "text": "会议改到周五下午三点,线上,用 Teams。" },
|
| 50 |
+
|
| 51 |
+
{ "id": "p01", "bucket": "polyphone", "text": "她把收音机调到那个熟悉的频率。" },
|
| 52 |
+
{ "id": "p02", "bucket": "polyphone", "text": "走廊里有人在低声调整音量的旋钮。" },
|
| 53 |
+
{ "id": "p03", "bucket": "polyphone", "text": "他睡不着,就起身把灯重新调暗了一点。" },
|
| 54 |
+
{ "id": "p04", "bucket": "polyphone", "text": "这段旋律单调得让人想睡,声调也压得很低。" },
|
| 55 |
+
|
| 56 |
+
{ "id": "b01", "bucket": "narration", "text": "那时他常说,夜里最安静的时候,能听见自己在想什么。" },
|
| 57 |
+
{ "id": "b02", "bucket": "narration", "text": "书里写着:雨停之后,城里会亮起很多很细的灯。" },
|
| 58 |
+
{ "id": "b03", "bucket": "narration", "text": "「你还记得吗?」她问,声音很轻,像怕吵醒什么。" },
|
| 59 |
+
{ "id": "b04", "bucket": "narration", "text": "后来那家店关了门,招牌被拆下来,靠在墙边放了很久。" }
|
| 60 |
+
]
|
| 61 |
+
}
|
eval/t2s.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"version": 1,
|
| 3 |
+
"note": "High-frequency traditional -> simplified map, used only when opencc is unavailable. Whisper often transcribes Chinese in traditional characters; comparing that against simplified references inflates CER by tens of points. Prefer opencc when installed. Extend by adding confident pairs only: a wrong pair silently corrupts the score.",
|
| 4 |
+
"map": {
|
| 5 |
+
"這": "这", "個": "个", "們": "们", "來": "来", "時": "时", "會": "会",
|
| 6 |
+
"對": "对", "開": "开", "關": "关", "麼": "么", "樣": "样", "過": "过",
|
| 7 |
+
"還": "还", "進": "进", "遠": "远", "燈": "灯", "盞": "盏", "風": "风",
|
| 8 |
+
"從": "从", "門": "门", "縫": "缝", "裡": "里", "帶": "带", "著": "着",
|
| 9 |
+
"點": "点", "濕": "湿", "頭": "头", "氣": "气", "聲": "声", "語": "语",
|
| 10 |
+
"話": "话", "誰": "谁", "覺": "觉", "兒": "儿", "見": "见", "現": "现",
|
| 11 |
+
"實": "实", "聽": "听", "寫": "写", "讀": "读", "書": "书", "頁": "页",
|
| 12 |
+
"紙": "纸", "錢": "钱", "鐘": "钟", "長": "长", "間": "间", "陽": "阳",
|
| 13 |
+
"陰": "阴", "雲": "云", "電": "电", "車": "车", "馬": "马", "鳥": "鸟",
|
| 14 |
+
"魚": "鱼", "龍": "龙", "華": "华", "國": "国", "際": "际", "學": "学",
|
| 15 |
+
"習": "习", "練": "练", "體": "体", "溫": "温", "熱": "热", "東": "东",
|
| 16 |
+
"場": "场", "處": "处", "應": "应", "該": "该", "讓": "让", "給": "给",
|
| 17 |
+
"沒": "没", "無": "无", "為": "为", "與": "与", "將": "将", "軍": "军",
|
| 18 |
+
"醫": "医", "藥": "药", "夢": "梦", "鄉": "乡", "憶": "忆", "舊": "旧",
|
| 19 |
+
"靜": "静", "動": "动", "淚": "泪", "願": "愿", "歲": "岁", "幾": "几",
|
| 20 |
+
"隨": "随", "邊": "边", "變": "变", "別": "别", "認": "认", "識": "识",
|
| 21 |
+
"記": "记", "謝": "谢", "請": "请", "問": "问", "題": "题", "說": "说",
|
| 22 |
+
"講": "讲", "談": "谈", "親": "亲", "愛": "爱", "歡": "欢", "樂": "乐",
|
| 23 |
+
"憂": "忧", "傷": "伤", "涼": "凉", "潤": "润", "軟": "软", "輕": "轻",
|
| 24 |
+
"內": "内", "麵": "面", "髮": "发", "隻": "只", "條": "条", "顆": "颗",
|
| 25 |
+
"張": "张", "塊": "块", "陣": "阵", "麗": "丽", "豐": "丰", "滿": "满",
|
| 26 |
+
"於": "于", "並": "并", "卻": "却", "據": "据", "錯": "错", "誤": "误",
|
| 27 |
+
"舉": "举", "頓": "顿", "轉": "转", "嗎": "吗", "畫": "画", "買": "买",
|
| 28 |
+
"賣": "卖", "貴": "贵", "價": "价", "貨": "货", "資": "资", "費": "费",
|
| 29 |
+
"單": "单", "雙": "双", "慶": "庆", "農": "农", "業": "业", "產": "产",
|
| 30 |
+
"團": "团", "隊": "队", "員": "员", "機": "机", "閉": "闭", "傳": "传",
|
| 31 |
+
"統": "统", "網": "网", "線": "线", "級": "级", "優": "优", "總": "总",
|
| 32 |
+
"結": "结", "續": "续", "斷": "断", "環": "环", "節": "节", "塵": "尘",
|
| 33 |
+
"霧": "雾", "燭": "烛", "爐": "炉", "鏡": "镜", "盤": "盘", "碗": "碗",
|
| 34 |
+
"簾": "帘", "牆": "墙", "磚": "砖", "階": "阶", "櫃": "柜", "飯": "饭",
|
| 35 |
+
"餅": "饼", "煙": "烟", "鬧": "闹", "響": "响", "濃": "浓", "鹹": "咸",
|
| 36 |
+
"鮮": "鲜", "澀": "涩", "細": "细", "寬": "宽", "淺": "浅", "後": "后",
|
| 37 |
+
"側": "侧", "頂": "顶", "臟": "脏", "腸": "肠", "膚": "肤", "齒": "齿",
|
| 38 |
+
"頸": "颈", "齡": "龄", "灣": "湾", "濕": "湿", "衛": "卫", "準": "准"
|
| 39 |
+
}
|
| 40 |
+
}
|
kaggle/bake_voices.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Bake the two offline assets Ming needs per built-in voice.
|
| 2 |
+
|
| 3 |
+
For every entry in config/ming_voices.json this writes:
|
| 4 |
+
|
| 5 |
+
prompt_latent - VAE posterior latent of the 6 s prompt wav (the flow head's
|
| 6 |
+
conditioning, replacing the F5 reference mel)
|
| 7 |
+
speaker_emb - 192-d CAM++ embedding of the same clip at 16 kHz
|
| 8 |
+
|
| 9 |
+
Both are tiny and ship with the site. The browser only needs the audio encoder
|
| 10 |
+
when a user uploads their own clip, so this bake is what keeps the main bundle
|
| 11 |
+
small.
|
| 12 |
+
|
| 13 |
+
Writes voices_baked.npz plus voices_baked.json (shapes, dtypes, source hashes).
|
| 14 |
+
|
| 15 |
+
Run inside the Kaggle notebook after the model is downloaded:
|
| 16 |
+
EVAL_DATA=/kaggle/working/webfm-eval python3 bake_voices.py
|
| 17 |
+
"""
|
| 18 |
+
from __future__ import annotations
|
| 19 |
+
|
| 20 |
+
import hashlib
|
| 21 |
+
import json
|
| 22 |
+
import os
|
| 23 |
+
import sys
|
| 24 |
+
import traceback
|
| 25 |
+
from pathlib import Path
|
| 26 |
+
|
| 27 |
+
import numpy as np
|
| 28 |
+
import torch
|
| 29 |
+
|
| 30 |
+
ROOT = Path("/kaggle/working")
|
| 31 |
+
REPO = ROOT / "Ming-3.0-tts"
|
| 32 |
+
MODEL_DIR = ROOT / "Ming-3.0-tts-0.5b"
|
| 33 |
+
DATA = Path(os.environ.get("EVAL_DATA", str(ROOT / "webfm-eval")))
|
| 34 |
+
OUT = ROOT / "baked"
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def patch_fp32() -> None:
|
| 38 |
+
for name in ("ming_tts.py", "modeling_bailingmm.py"):
|
| 39 |
+
path = REPO / name
|
| 40 |
+
s = path.read_text()
|
| 41 |
+
s = s.replace("torch_dtype=torch.bfloat16", "torch_dtype=torch.float32")
|
| 42 |
+
s = s.replace(".eval().to(torch.bfloat16).to(device)", ".eval().to(torch.float32).to(device)")
|
| 43 |
+
s = s.replace("dtype=torch.bfloat16", "dtype=torch.float32")
|
| 44 |
+
path.write_text(s)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def sha8(path: Path) -> str:
|
| 48 |
+
return hashlib.sha256(path.read_bytes()).hexdigest()[:8]
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def main() -> None:
|
| 52 |
+
OUT.mkdir(parents=True, exist_ok=True)
|
| 53 |
+
sys.path.insert(0, str(REPO))
|
| 54 |
+
patch_fp32()
|
| 55 |
+
from ming_tts import MingTTS
|
| 56 |
+
|
| 57 |
+
tts = MingTTS(str(MODEL_DIR), device="cuda", text_normalization=False)
|
| 58 |
+
voices = json.loads((DATA / "config/ming_voices.json").read_text())["voices"]
|
| 59 |
+
|
| 60 |
+
arrays: dict[str, np.ndarray] = {}
|
| 61 |
+
meta: dict[str, dict] = {}
|
| 62 |
+
for v in voices:
|
| 63 |
+
vid = v["id"]
|
| 64 |
+
wav = DATA / v["promptWav"]
|
| 65 |
+
if not wav.exists():
|
| 66 |
+
print(f"skip {vid}: {wav} missing")
|
| 67 |
+
continue
|
| 68 |
+
try:
|
| 69 |
+
with torch.no_grad():
|
| 70 |
+
latent, spk = tts.prepare_prompt(str(wav), use_spk_emb=True)
|
| 71 |
+
latent = latent.detach().float().cpu().numpy()
|
| 72 |
+
emb = (spk[0] if isinstance(spk, (list, tuple)) else spk).detach().float().cpu()
|
| 73 |
+
emb = emb.reshape(-1).numpy()
|
| 74 |
+
arrays[f"{vid}_latent"] = latent
|
| 75 |
+
arrays[f"{vid}_spk"] = emb
|
| 76 |
+
meta[vid] = {
|
| 77 |
+
"promptWav": v["promptWav"],
|
| 78 |
+
"promptText": v["promptText"],
|
| 79 |
+
"wav_sha8": sha8(wav),
|
| 80 |
+
"latent_shape": list(latent.shape),
|
| 81 |
+
"spk_dim": int(emb.size),
|
| 82 |
+
}
|
| 83 |
+
print(f"{vid}: latent {latent.shape} spk {emb.size} from {wav.name} ({v['seconds']}s)")
|
| 84 |
+
except Exception:
|
| 85 |
+
print(f"{vid} failed\n{traceback.format_exc()}")
|
| 86 |
+
|
| 87 |
+
if not arrays:
|
| 88 |
+
raise SystemExit("nothing baked")
|
| 89 |
+
|
| 90 |
+
np.savez_compressed(OUT / "voices_baked.npz", **arrays)
|
| 91 |
+
(OUT / "voices_baked.json").write_text(json.dumps(
|
| 92 |
+
{"model": "inclusionAI/Ming-3.0-tts-0.5B", "voices": meta,
|
| 93 |
+
"note": "latent is the VAE posterior used as flow conditioning; spk is CAM++ 192-d"},
|
| 94 |
+
ensure_ascii=False, indent=2))
|
| 95 |
+
size = (OUT / "voices_baked.npz").stat().st_size
|
| 96 |
+
print(f"wrote {OUT/'voices_baked.npz'} ({size/1024:.0f} KB) for {len(meta)} voices")
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
if __name__ == "__main__":
|
| 100 |
+
main()
|
kaggle/ming_eval.py
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Evaluate every Ming TTS tier on the fixed WebFM eval set (eval/sentences.json).
|
| 2 |
+
|
| 3 |
+
Runs the teacher and the distilled students over the same voice x sentence
|
| 4 |
+
matrix, writes one wav per cell and one JSONL row per cell, then leaves the
|
| 5 |
+
scoring to `eval/score.py`.
|
| 6 |
+
|
| 7 |
+
The teacher is generated in the same run and on the same sentences: a candidate
|
| 8 |
+
is only meaningful as a delta against it.
|
| 9 |
+
|
| 10 |
+
Expected Kaggle inputs:
|
| 11 |
+
/kaggle/input/webfm-eval/eval/sentences.json (this repo's eval/)
|
| 12 |
+
/kaggle/input/webfm-eval/config/ming_voices.json
|
| 13 |
+
/kaggle/input/webfm-eval/refs/wav/v01.wav .. v08.wav
|
| 14 |
+
/kaggle/working/Ming-3.0-tts + Ming-3.0-tts-0.5b (as in ming_multistep.py)
|
| 15 |
+
|
| 16 |
+
Env:
|
| 17 |
+
VOICES=v01,v02,... subset of voices, for splitting across two GPUs
|
| 18 |
+
MODELS=teacher,3step,4step
|
| 19 |
+
LIMIT=40 sentences to run
|
| 20 |
+
SEED=20261021
|
| 21 |
+
|
| 22 |
+
Resumable: a cell whose wav exists is not regenerated; the JSONL is appended
|
| 23 |
+
and flushed per row, so a killed session keeps what it finished.
|
| 24 |
+
"""
|
| 25 |
+
from __future__ import annotations
|
| 26 |
+
|
| 27 |
+
import json
|
| 28 |
+
import os
|
| 29 |
+
import re
|
| 30 |
+
import sys
|
| 31 |
+
import time
|
| 32 |
+
import traceback
|
| 33 |
+
from pathlib import Path
|
| 34 |
+
|
| 35 |
+
import numpy as np
|
| 36 |
+
import torch
|
| 37 |
+
import torchaudio
|
| 38 |
+
|
| 39 |
+
ROOT = Path("/kaggle/working")
|
| 40 |
+
REPO = ROOT / "Ming-3.0-tts"
|
| 41 |
+
MODEL_DIR = ROOT / "Ming-3.0-tts-0.5b"
|
| 42 |
+
DATA = Path(os.environ.get("EVAL_DATA", "/kaggle/input/webfm-eval"))
|
| 43 |
+
OUT = ROOT / "ming_eval"
|
| 44 |
+
WAV = OUT / "wav"
|
| 45 |
+
ROWS = OUT / "results.jsonl"
|
| 46 |
+
LOG = OUT / "eval.log"
|
| 47 |
+
|
| 48 |
+
SEED = int(os.environ.get("SEED", "20261021"))
|
| 49 |
+
LIMIT = int(os.environ.get("LIMIT", "40"))
|
| 50 |
+
VOICE_FILTER = [v for v in os.environ.get("VOICES", "").split(",") if v]
|
| 51 |
+
MODELS = [m for m in os.environ.get("MODELS", "teacher,3step,4step").split(",") if m]
|
| 52 |
+
TEACHER_STEPS = 10
|
| 53 |
+
TEACHER_CFG = 2.0
|
| 54 |
+
|
| 55 |
+
STUDENT_REPOS = {
|
| 56 |
+
"1step": ("idefinity/ming-3.0-tts-1step-distill-int4", 1),
|
| 57 |
+
"2step": ("idefinity/ming-3.0-tts-2step-distill-int4", 2),
|
| 58 |
+
"3step": ("idefinity/ming-3.0-tts-3step-distill-int4", 3),
|
| 59 |
+
"4step": ("idefinity/ming-3.0-tts-4step-distill-int4", 4),
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
for p in (OUT, WAV):
|
| 63 |
+
p.mkdir(parents=True, exist_ok=True)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def log(msg: str) -> None:
|
| 67 |
+
line = f"[{time.strftime('%H:%M:%S')}] {msg}"
|
| 68 |
+
print(line, flush=True)
|
| 69 |
+
with open(LOG, "a") as f:
|
| 70 |
+
f.write(line + "\n")
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def patch_fp32() -> None:
|
| 74 |
+
"""T4 has no bf16; the repo defaults to bf16 and NaNs out under fp16."""
|
| 75 |
+
for name in ("ming_tts.py", "modeling_bailingmm.py"):
|
| 76 |
+
path = REPO / name
|
| 77 |
+
s = path.read_text()
|
| 78 |
+
s = s.replace("torch_dtype=torch.bfloat16", "torch_dtype=torch.float32")
|
| 79 |
+
s = s.replace(".eval().to(torch.bfloat16).to(device)", ".eval().to(torch.float32).to(device)")
|
| 80 |
+
s = s.replace("dtype=torch.bfloat16", "dtype=torch.float32")
|
| 81 |
+
path.write_text(s)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def done_cells() -> set[tuple[str, str, str]]:
|
| 85 |
+
seen = set()
|
| 86 |
+
if ROWS.exists():
|
| 87 |
+
for line in ROWS.read_text().splitlines():
|
| 88 |
+
if not line.strip():
|
| 89 |
+
continue
|
| 90 |
+
try:
|
| 91 |
+
r = json.loads(line)
|
| 92 |
+
seen.add((r["model"], r["voice"], r["id"]))
|
| 93 |
+
except Exception:
|
| 94 |
+
continue
|
| 95 |
+
return seen
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def sample_latent(student, z, history, noise, n_steps):
|
| 99 |
+
y = noise
|
| 100 |
+
for i in range(n_steps):
|
| 101 |
+
dt = 1.0 / n_steps
|
| 102 |
+
v = student(
|
| 103 |
+
x=y, t=torch.full((y.shape[0],), i / n_steps, device=y.device),
|
| 104 |
+
c=z, latent_history=history, mask=None,
|
| 105 |
+
)[:, -1:, :]
|
| 106 |
+
y = y + v * dt
|
| 107 |
+
return y
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def ar_generate(mm, dit, n_steps, prompt, text, prompt_latent, prompt_text, spk_emb, frames):
|
| 111 |
+
"""Autoregressive rollout with a chosen flow head. Length is forced to the
|
| 112 |
+
teacher's frame count, so this measures content and timbre, not stopping."""
|
| 113 |
+
device = next(mm.parameters()).device
|
| 114 |
+
dtype = next(mm.parameters()).dtype
|
| 115 |
+
with torch.no_grad():
|
| 116 |
+
input_ids, inputs_embeds = mm.prepare_input_embed(
|
| 117 |
+
prompt=prompt, text=text, spk_emb=spk_emb,
|
| 118 |
+
prompt_latent=prompt_latent, prompt_text=prompt_text,
|
| 119 |
+
)
|
| 120 |
+
attention_mask = torch.ones(input_ids.shape, device=device)
|
| 121 |
+
position_ids = (attention_mask.cumsum(-1) - 1).masked_fill_(attention_mask == 0, 1)
|
| 122 |
+
past = None
|
| 123 |
+
history = torch.zeros(1, mm.history_patch_size, mm.latent_dim, device=device, dtype=dtype)
|
| 124 |
+
if prompt_latent is not None:
|
| 125 |
+
start = mm.history_patch_size - prompt_latent.size(1)
|
| 126 |
+
if start < 0:
|
| 127 |
+
history[:] = prompt_latent[:, -start:, :]
|
| 128 |
+
else:
|
| 129 |
+
history[:, start:, :] = prompt_latent
|
| 130 |
+
out = []
|
| 131 |
+
for _ in range(frames):
|
| 132 |
+
with torch.no_grad():
|
| 133 |
+
hidden = mm.model(
|
| 134 |
+
attention_mask=attention_mask, position_ids=position_ids,
|
| 135 |
+
inputs_embeds=inputs_embeds, audio_mask=None, image_mask=None,
|
| 136 |
+
output_hidden_states=True, return_dict=True, use_cache=True,
|
| 137 |
+
past_key_values=past,
|
| 138 |
+
)
|
| 139 |
+
past = hidden.past_key_values
|
| 140 |
+
z = hidden.hidden_states[-1][:, -1:, :]
|
| 141 |
+
noise = torch.randn(1, 1, mm.latent_dim, device=device, dtype=dtype)
|
| 142 |
+
latent = sample_latent(dit, z, history, noise, n_steps).to(device=device, dtype=dtype)
|
| 143 |
+
out.append(latent)
|
| 144 |
+
inputs_embeds = mm.linear_proj_audio(latent)
|
| 145 |
+
position_ids = position_ids[:, -1:] + 1
|
| 146 |
+
attention_mask = torch.ones(inputs_embeds.shape[0], 1, device=device)
|
| 147 |
+
history[:, :-mm.patch_size, :] = history[:, mm.patch_size:, :].clone()
|
| 148 |
+
history[:, -mm.patch_size:, :] = latent
|
| 149 |
+
with torch.no_grad():
|
| 150 |
+
speech = mm.audio.decode(torch.cat(out, dim=1), past_key_values=None,
|
| 151 |
+
use_cache=False, last_chunk=True)[0]
|
| 152 |
+
return speech.cpu().float().reshape(-1).numpy()
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def load_student(name: str, teacher_dit, device):
|
| 156 |
+
from huggingface_hub import hf_hub_download
|
| 157 |
+
|
| 158 |
+
repo, steps = STUDENT_REPOS[name]
|
| 159 |
+
path = hf_hub_download(repo_id=repo, filename=f"distill/student_{steps}step.pt")
|
| 160 |
+
state = torch.load(path, map_location="cpu")
|
| 161 |
+
state = {k: v.float() for k, v in state.items()}
|
| 162 |
+
import copy
|
| 163 |
+
|
| 164 |
+
dit = copy.deepcopy(teacher_dit)
|
| 165 |
+
dit.load_state_dict(state)
|
| 166 |
+
return dit.to(device).eval(), steps
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def build_asr():
|
| 170 |
+
from transformers import pipeline
|
| 171 |
+
|
| 172 |
+
kwargs = {"model": "openai/whisper-small", "device": 0}
|
| 173 |
+
try:
|
| 174 |
+
pipe = pipeline("automatic-speech-recognition", torch_dtype=torch.float16, **kwargs)
|
| 175 |
+
except Exception:
|
| 176 |
+
pipe = pipeline("automatic-speech-recognition", **kwargs)
|
| 177 |
+
prompt = "以下是普通话的句子,请使用简体中文转写。" # pushes Whisper off traditional output
|
| 178 |
+
|
| 179 |
+
def asr(wav: np.ndarray, sr: int = 44100) -> str:
|
| 180 |
+
out = pipe(
|
| 181 |
+
{"array": wav.astype(np.float32), "sampling_rate": sr},
|
| 182 |
+
generate_kwargs={"language": "zh", "task": "transcribe", "initial_prompt": prompt},
|
| 183 |
+
)
|
| 184 |
+
return out.get("text", "") if isinstance(out, dict) else str(out)
|
| 185 |
+
|
| 186 |
+
return asr
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def main() -> None:
|
| 190 |
+
torch.manual_seed(SEED)
|
| 191 |
+
if torch.cuda.is_available():
|
| 192 |
+
torch.cuda.manual_seed_all(SEED)
|
| 193 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 194 |
+
log(f"device={device} limit={LIMIT} models={MODELS} voices={VOICE_FILTER or 'all'}")
|
| 195 |
+
|
| 196 |
+
sys.path.insert(0, str(REPO))
|
| 197 |
+
patch_fp32()
|
| 198 |
+
from ming_tts import MingTTS
|
| 199 |
+
import tts_tasks
|
| 200 |
+
|
| 201 |
+
sentences = json.loads((DATA / "eval/sentences.json").read_text())["items"][:LIMIT]
|
| 202 |
+
voices = json.loads((DATA / "config/ming_voices.json").read_text())["voices"]
|
| 203 |
+
if VOICE_FILTER:
|
| 204 |
+
voices = [v for v in voices if v["id"] in VOICE_FILTER]
|
| 205 |
+
log(f"sentences={len(sentences)} voices={[v['id'] for v in voices]}")
|
| 206 |
+
|
| 207 |
+
tts = MingTTS(str(MODEL_DIR), device=str(device), text_normalization=False)
|
| 208 |
+
mm = tts.model
|
| 209 |
+
dtype = next(mm.parameters()).dtype
|
| 210 |
+
prompt = tts_tasks.build_tts_prompt("Chinese")
|
| 211 |
+
teacher_dit = mm.flowloss.cfm.model.float().eval()
|
| 212 |
+
for p in teacher_dit.parameters():
|
| 213 |
+
p.requires_grad_(False)
|
| 214 |
+
|
| 215 |
+
students = {}
|
| 216 |
+
for name in MODELS:
|
| 217 |
+
if name in STUDENT_REPOS:
|
| 218 |
+
students[name], steps = load_student(name, teacher_dit, device)
|
| 219 |
+
log(f"loaded student {name} ({steps} steps)")
|
| 220 |
+
|
| 221 |
+
asr = build_asr()
|
| 222 |
+
spk = tts.spkemb_extractor
|
| 223 |
+
mel = torchaudio.transforms.MelSpectrogram(
|
| 224 |
+
sample_rate=44100, n_fft=1024, hop_length=256, n_mels=80, power=2.0
|
| 225 |
+
)
|
| 226 |
+
|
| 227 |
+
def speaker_cos(ref: np.ndarray, hyp: np.ndarray) -> float:
|
| 228 |
+
a = torchaudio.functional.resample(torch.from_numpy(ref).float(), 44100, 16000).unsqueeze(0)
|
| 229 |
+
b = torchaudio.functional.resample(torch.from_numpy(hyp).float(), 44100, 16000).unsqueeze(0)
|
| 230 |
+
ea, eb = spk(a).reshape(-1).float(), spk(b).reshape(-1).float()
|
| 231 |
+
return float(torch.dot(ea, eb) / (ea.norm() * eb.norm() + 1e-9))
|
| 232 |
+
|
| 233 |
+
def mel_l1(ref: np.ndarray, hyp: np.ndarray) -> float:
|
| 234 |
+
mr = torch.log(mel(torch.from_numpy(ref).float().unsqueeze(0)) + 1e-6).squeeze(0)
|
| 235 |
+
mh = torch.log(mel(torch.from_numpy(hyp).float().unsqueeze(0)) + 1e-6).squeeze(0)
|
| 236 |
+
n = min(mr.shape[-1], mh.shape[-1])
|
| 237 |
+
return float((mr[..., :n] - mh[..., :n]).abs().mean())
|
| 238 |
+
|
| 239 |
+
seen = done_cells()
|
| 240 |
+
log(f"resume: {len(seen)} cells already done")
|
| 241 |
+
|
| 242 |
+
for voice in voices:
|
| 243 |
+
vid = voice["id"]
|
| 244 |
+
wav_path = DATA / voice["promptWav"]
|
| 245 |
+
prompt_text = voice["promptText"]
|
| 246 |
+
prompt_latent, spk_emb = tts.prepare_prompt(str(wav_path), use_spk_emb=True)
|
| 247 |
+
prompt_latent = prompt_latent.to(device=device, dtype=dtype)
|
| 248 |
+
spk_emb = [x.to(device=device, dtype=dtype) for x in spk_emb]
|
| 249 |
+
|
| 250 |
+
for item in sentences:
|
| 251 |
+
sid, text = item["id"], item["text"]
|
| 252 |
+
ref_wav_path = WAV / "teacher" / vid / f"{sid}.wav"
|
| 253 |
+
|
| 254 |
+
if ("teacher", vid, sid) not in seen:
|
| 255 |
+
try:
|
| 256 |
+
t0 = time.time()
|
| 257 |
+
wav = tts.synthesize(
|
| 258 |
+
task="TTS", text=text, language_id="Chinese",
|
| 259 |
+
prompt_wav_path=str(wav_path), prompt_text=prompt_text,
|
| 260 |
+
use_spk_emb=True, raw_text=True,
|
| 261 |
+
max_decode_steps=max(16, min(400, int(len(text) * 3.0))),
|
| 262 |
+
)
|
| 263 |
+
arr = wav.cpu().numpy().reshape(-1)
|
| 264 |
+
ref_wav_path.parent.mkdir(parents=True, exist_ok=True)
|
| 265 |
+
torchaudio.save(str(ref_wav_path), torch.from_numpy(arr).unsqueeze(0), 44100)
|
| 266 |
+
frames = max(16, int(round(arr.size / 3528)))
|
| 267 |
+
with open(ROWS, "a") as f:
|
| 268 |
+
f.write(json.dumps({
|
| 269 |
+
"model": "teacher", "voice": vid, "id": sid, "bucket": item["bucket"],
|
| 270 |
+
"text": text, "hyp_text": asr(arr), "frames": frames,
|
| 271 |
+
"seconds": arr.size / 44100, "wall": time.time() - t0,
|
| 272 |
+
}, ensure_ascii=False) + "\n")
|
| 273 |
+
seen.add(("teacher", vid, sid))
|
| 274 |
+
log(f"teacher {vid} {sid} {arr.size/44100:.2f}s in {time.time()-t0:.1f}s")
|
| 275 |
+
except Exception:
|
| 276 |
+
log(f"teacher {vid} {sid} failed\n{traceback.format_exc()}")
|
| 277 |
+
continue
|
| 278 |
+
|
| 279 |
+
if not ref_wav_path.exists():
|
| 280 |
+
continue
|
| 281 |
+
ref_audio, _ = torchaudio.load(str(ref_wav_path))
|
| 282 |
+
ref_audio = ref_audio.reshape(-1).numpy()
|
| 283 |
+
frames = max(16, int(round(ref_audio.size / 3528)))
|
| 284 |
+
|
| 285 |
+
for name, dit in students.items():
|
| 286 |
+
if (name, vid, sid) in seen:
|
| 287 |
+
continue
|
| 288 |
+
try:
|
| 289 |
+
t0 = time.time()
|
| 290 |
+
torch.manual_seed(SEED)
|
| 291 |
+
arr = ar_generate(mm, dit, STUDENT_REPOS[name][1], prompt, text,
|
| 292 |
+
prompt_latent, prompt_text, spk_emb, frames)
|
| 293 |
+
path = WAV / name / vid / f"{sid}.wav"
|
| 294 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 295 |
+
torchaudio.save(str(path), torch.from_numpy(arr).unsqueeze(0), 44100)
|
| 296 |
+
with open(ROWS, "a") as f:
|
| 297 |
+
f.write(json.dumps({
|
| 298 |
+
"model": name, "voice": vid, "id": sid, "bucket": item["bucket"],
|
| 299 |
+
"text": text, "hyp_text": asr(arr),
|
| 300 |
+
"spk_cos": speaker_cos(ref_audio, arr),
|
| 301 |
+
"mel_l1": mel_l1(ref_audio, arr),
|
| 302 |
+
"dur_ratio": arr.size / max(1, ref_audio.size),
|
| 303 |
+
"wall": time.time() - t0,
|
| 304 |
+
}, ensure_ascii=False) + "\n")
|
| 305 |
+
seen.add((name, vid, sid))
|
| 306 |
+
log(f"{name} {vid} {sid} in {time.time()-t0:.1f}s")
|
| 307 |
+
except Exception:
|
| 308 |
+
log(f"{name} {vid} {sid} failed\n{traceback.format_exc()}")
|
| 309 |
+
|
| 310 |
+
log("DONE")
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
if __name__ == "__main__":
|
| 314 |
+
try:
|
| 315 |
+
main()
|
| 316 |
+
except Exception:
|
| 317 |
+
log(traceback.format_exc())
|
| 318 |
+
raise
|
refs/wav/v01.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9403f42449c585268b93990e0c3e6a1f3821be80763f72b2023510f99514f7cd
|
| 3 |
+
size 287276
|
refs/wav/v02.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:34da9be3dadd01a5eb5806f6f69d9e6183bebccb77f44da8e7604e3c73da7013
|
| 3 |
+
size 287276
|
refs/wav/v03.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bbe102ec68fe264cb5eb165afda3237fdcd5e3083c1cfc1eeef1c30632f3684c
|
| 3 |
+
size 287276
|
refs/wav/v04.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:47aa8198a3faf5eb9bd68520933e639af3db97d013ab6025385555220121ac53
|
| 3 |
+
size 287276
|
refs/wav/v05.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:38adeaa6dc2e787c25e5642fbf277351636aa7f0363900cdc36f24bf9bcc1d77
|
| 3 |
+
size 287276
|
refs/wav/v06.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f613ab783cc876239a93bd46251524f683a37d240ae16be30018679f11d4242e
|
| 3 |
+
size 287276
|
refs/wav/v07.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4b8e94303381eb65f268029644c7cdf0f99c16d4e7f138a0dfaa8c9048744a0d
|
| 3 |
+
size 287276
|
refs/wav/v08.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fd0f430f24b895679ee4f8c77af5f04d0505ca60f2a7ad8b897e98778d192580
|
| 3 |
+
size 287276
|