Skip to content

Commit 114292d

Browse files
authored
docs(site): teach beginners a complete first-transcript workflow
Accept article examples, full site regression, desktop/mobile browser coverage and exact-head CI. Static deployment is a separate operation. Signed-off-by: LauraGPT <zhifu.gzf@alibaba-inc.com>
2 parents c1e3018 + 184deb5 commit 114292d

12 files changed

Lines changed: 470 additions & 179 deletions

‎web-pages/product-site/content/legacy-manifest.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"blog/self-hosted-openai-whisper-api-alternative.html": "f75f4b2fad03f6d1215347fbc98c71de1a59ff3c97cecc4aaf19bbb94e8eb777",
4343
"blog/sensevoice-deployment-guide.html": "61c34fb7626444a0f1b5c93013dd95c10c576333791eaca1ab819baf0a8cdad6",
4444
"blog/sensevoice-emotion-language-detection.html": "2451769a28af67788456aa02dad5201d218ac53fb84764cd7fbc32f991c953f8",
45-
"blog/speech-to-text-python-transcribe-audio.html": "87335710235dfdec9e01288f03a9a294c7bc3f730110e8d06f2b4c9d4906e284",
45+
"blog/speech-to-text-python-transcribe-audio.html": "df01419d4fffe32f867f406d9783568a68e3d12db8e5bdb1bcb68d21cefa1c7e",
4646
"blog/speech-to-text-timestamps-python.html": "78364db117dfbce45b03739679764cec7ab1d0a860f321c67154f33392fc6b8d",
4747
"blog/subtitle-edit-fun-asr-sensevoice-local-subtitles.html": "f8d5870b6cf9dbdfd4e943fdccb7ae8f091472f1dcbd46bd7db90bd36e3e7846",
4848
"blog/transcript-audit.py": "1b77ee66d8e2ef734277a13689aa225598020c23193391a0a3eff598148f43c2",
@@ -85,7 +85,7 @@
8585
"en/blog/self-hosted-openai-whisper-api-alternative.html": "a95bde0e83ebea941144e5a4bd339ea866feee099f047d4b4fb01072c293cb70",
8686
"en/blog/sensevoice-deployment-guide.html": "8882912c6a84ec0a0e025d0eff8fcfa74bf76324bd4c9cae862c43c87c6e10b3",
8787
"en/blog/sensevoice-emotion-language-detection.html": "8f1432a4c07dab895dfda144d4fe1f64a487c72922febb6a379a15b7215e42a3",
88-
"en/blog/speech-to-text-python-transcribe-audio.html": "4fc57aef3c6177e28afa26fa6c41f67280b986e384b32a63a2f79ca67bcfe631",
88+
"en/blog/speech-to-text-python-transcribe-audio.html": "3bb6c61f3263938b44f8638040b985a396a93bd0bcfa24b00b12fb115138ae4a",
8989
"en/blog/speech-to-text-timestamps-python.html": "6a7f8368f757c9ea50e287db6db3191ebcbbfc914f9a869b9515648b2d69790b",
9090
"en/blog/subtitle-edit-fun-asr-sensevoice-local-subtitles.html": "7c65a73bab1ff481d9b398476ea6440926546ba7122cc2cb64f5bda81fc039a2",
9191
"en/blog/voice-activity-detection-python.html": "d12f5d0f4ae07c3434f6188d12f5603b8abb9578413b79133668638d1c5e18a7",

‎web-pages/product-site/data/blog.json‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"lead": "funclip-v2-2-0-moss-speaker-clipping",
44
"selected": [
55
"meeting-transcript-acceptance",
6-
"fun-asr-nano-transformers",
6+
"speech-to-text-python-transcribe-audio",
77
"self-hosted-openai-whisper-api-alternative",
88
"funasr-transcribe-long-audio"
99
],
@@ -480,14 +480,14 @@
480480
{
481481
"slug": "speech-to-text-python-transcribe-audio",
482482
"category": "applications",
483-
"reviewed": false,
483+
"reviewed": true,
484484
"zh": {
485-
"title": "用 Python 转写一份录音",
486-
"summary": ""
485+
"title": "用 Python 把第一段录音转成文字",
486+
"summary": "从认识工具包和模型开始,在独立 Python 环境中把一段普通话 WAV 转成 JSON 文本,附下载边界、排错步骤和 Agent 执行约定。"
487487
},
488488
"en": {
489-
"title": "Transcribe a recording with Python",
490-
"summary": ""
489+
"title": "Transcribe your first recording with Python",
490+
"summary": "Understand the toolkit and model, then turn a short Mandarin WAV into a JSON transcript in an isolated Python environment, with troubleshooting and an explicit Agent contract."
491491
}
492492
},
493493
{

‎web-pages/product-site/legacy/blog/speech-to-text-python-transcribe-audio.html‎

Lines changed: 138 additions & 82 deletions
Large diffs are not rendered by default.

‎web-pages/product-site/legacy/en/blog/speech-to-text-python-transcribe-audio.html‎

Lines changed: 138 additions & 82 deletions
Large diffs are not rendered by default.

‎web-pages/product-site/tests/browser/blog-editorial.spec.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ for (const prefix of ['', 'en/']) {
99
test(`selected article text contrast ${prefix || 'zh'} at ${width}px`, async ({ page }, testInfo) => {
1010
await page.setViewportSize({ width, height: 900 });
1111
for (const slug of ['funclip-v2-2-0-moss-speaker-clipping', 'meeting-transcript-acceptance',
12-
'fun-asr-nano-transformers', 'self-hosted-openai-whisper-api-alternative', 'funasr-transcribe-long-audio']) {
12+
'fun-asr-nano-transformers', 'speech-to-text-python-transcribe-audio',
13+
'self-hosted-openai-whisper-api-alternative', 'funasr-transcribe-long-audio']) {
1314
await page.goto(`/${prefix}blog/${slug}.html`);
1415
const ratios = await page.locator('article p, article li').evaluateAll(nodes => {
1516
const luminance = (color: string) => {

‎web-pages/product-site/tests/browser/native-transformers.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ for (const prefix of ['', 'en/']) {
55
test(`native Transformers article and guide ${prefix || 'zh'} ${width}`, async ({ page }, testInfo) => {
66
await page.setViewportSize({ width, height: 900 });
77
const route = `/${prefix}blog/fun-asr-nano-transformers.html`;
8-
await page.goto(`/${prefix}blog/`);
8+
await page.goto(`/${prefix}blog/archive/`);
99
await page.locator(`a.post-card[href="${route}"]`).click();
1010
await expect(page).toHaveURL(new RegExp(route.replaceAll('.', '\\.')));
1111
const layout = await page.evaluate(() => ({
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
"""Executable tutorial contracts, not pretrained speech-quality tests."""
2+
import copy
3+
import hashlib
4+
import json
5+
from pathlib import Path
6+
import sys
7+
import types
8+
import wave
9+
10+
from bs4 import BeautifulSoup
11+
import pytest
12+
13+
SITE = Path(__file__).resolve().parents[1]
14+
sys.path.insert(0, str(SITE))
15+
from build import build
16+
17+
SLUG = "speech-to-text-python-transcribe-audio"
18+
MODEL = "iic/speech_seaco_paraformer_large_asr_nat-zh-cn-16k-common-vocab8404-pytorch"
19+
TITLES = ("用 Python 把第一段录音转成文字", "Transcribe your first recording with Python")
20+
21+
22+
@pytest.fixture(scope="module", params=["source", "built"])
23+
def root(request, tmp_path_factory):
24+
if request.param == "source":
25+
return SITE / "legacy"
26+
dest = tmp_path_factory.mktemp("first-transcript-build")
27+
build(dest)
28+
return dest
29+
30+
31+
@pytest.fixture(params=["", "en/"])
32+
def article(root, request):
33+
prefix = request.param
34+
return prefix, BeautifulSoup((root / prefix / "blog" / (SLUG + ".html")).read_text(), "html.parser")
35+
36+
37+
def test_catalogue():
38+
data = json.loads((SITE / "data/blog.json").read_text())
39+
row = next(x for x in data["articles"] if x["slug"] == SLUG)
40+
assert row["reviewed"] is True
41+
assert row["category"] == "applications"
42+
assert (row["zh"]["title"], row["en"]["title"]) == TITLES
43+
assert SLUG in [data["lead"], *data["selected"]]
44+
45+
46+
def test_reader_and_agent_contract(article):
47+
prefix, soup = article
48+
assert soup.h1.get_text() == TITLES[bool(prefix)]
49+
metadata = json.loads(soup.select_one('script[type="application/ld+json"]').get_text())
50+
assert metadata["datePublished"] == "2026-06-18"
51+
assert metadata["dateModified"] == "2026-11-17"
52+
assert metadata["headline"] == soup.h1.get_text()
53+
assert soup.select_one('link[rel="canonical"]')["href"] == f"https://www.funasr.com/{prefix}blog/{SLUG}.html"
54+
for section in ("ecosystem", "requirements", "installation", "audio", "transcribe", "result", "troubleshooting", "agent-contract", "verification"):
55+
assert soup.select_one(f"article #{section}"), section
56+
text = soup.select_one("article").get_text()
57+
for claim in ("代码全部实测", "每段代码都已实测", "换模型只改", "CPU 也能实时", "All code tested", "just change model="):
58+
assert claim not in text
59+
assert "1.4.26" in text and "30" in text and "16000" in text
60+
assert soup.select_one('article [data-editorial="next-step"] a[href]')
61+
assert not soup.select("article .post-list")
62+
assert "pretrained" in soup.select_one("#verification").parent.get_text().lower() if prefix else "预训练" in soup.select_one("#verification").parent.get_text()
63+
64+
65+
@pytest.fixture
66+
def recipe(article):
67+
_, soup = article
68+
node = soup.select_one('code[data-example="transcribe-first"]')
69+
assert node is not None
70+
ns = {"__name__": "tutorial_example"}
71+
exec(compile(node.get_text(), "article/transcribe_first.py", "exec"), ns)
72+
return ns["main"]
73+
74+
75+
def wav_file(tmp_path, rate=16000, channels=1, seconds=1, width=2):
76+
p = tmp_path / "sample.wav"
77+
with wave.open(str(p), "wb") as audio:
78+
audio.setnchannels(channels)
79+
audio.setsampwidth(width)
80+
audio.setframerate(rate)
81+
audio.writeframes(b"\x00" * int(rate * seconds) * channels * width)
82+
return p
83+
84+
85+
@pytest.fixture
86+
def fake_model(monkeypatch):
87+
calls = []
88+
result = [{"text": "测试结果"}]
89+
class Model:
90+
model_path = "/reviewed/model"
91+
def __init__(self, **kwargs):
92+
calls.append(("construct", kwargs))
93+
def generate(self, **kwargs):
94+
calls.append(("generate", kwargs))
95+
return copy.deepcopy(result)
96+
module = types.ModuleType("funasr")
97+
module.AutoModel = Model
98+
module.__version__ = "1.4.26"
99+
monkeypatch.setitem(sys.modules, "funasr", module)
100+
return calls, result
101+
102+
103+
def args_for(tmp_path, audio):
104+
model = tmp_path / "model"
105+
model.mkdir(exist_ok=True)
106+
return ["--audio", str(audio), "--model-dir", str(model), "--output", str(tmp_path / "transcript.json")]
107+
108+
109+
def test_local_model_output_and_immutable_input(recipe, tmp_path, fake_model):
110+
audio = wav_file(tmp_path)
111+
before = hashlib.sha256(audio.read_bytes()).hexdigest()
112+
args = args_for(tmp_path, audio)
113+
recipe(args)
114+
calls, _ = fake_model
115+
assert calls == [
116+
("construct", dict(model=str(tmp_path / "model"), hub="ms", device="cpu", ncpu=4, disable_update=True, trust_remote_code=False)),
117+
("generate", dict(input=str(audio), batch_size=1)),
118+
]
119+
out = json.loads((tmp_path / "transcript.json").read_text())
120+
assert out["text"] == "测试结果" and out["funasr_version"] == "1.4.26"
121+
assert out["audio"] == str(audio) and out["model_dir"] == "/reviewed/model"
122+
assert out["duration_seconds"] == 1.0
123+
assert hashlib.sha256(audio.read_bytes()).hexdigest() == before
124+
125+
126+
def test_download_requires_explicit_opt_in(recipe, tmp_path, fake_model):
127+
audio = wav_file(tmp_path)
128+
with pytest.raises(SystemExit) as e:
129+
recipe(["--audio", str(audio), "--output", str(tmp_path / "out.json")])
130+
assert e.value.code == 2 and fake_model[0] == []
131+
recipe(["--audio", str(audio), "--allow-download", "--output", str(tmp_path / "out.json")])
132+
assert fake_model[0][0][1]["model"] == MODEL
133+
134+
135+
@pytest.mark.parametrize("case", ["missing", "not-wav", "stereo", "rate", "empty", "long", "width", "truncated", "model-missing", "output-exists", "output-parent"])
136+
def test_invalid_inputs_stop_before_model_load(recipe, tmp_path, fake_model, case):
137+
options = {"stereo": {"channels": 2}, "rate": {"rate": 8000}, "empty": {"seconds": 0}, "long": {"seconds": 31}, "width": {"width": 1}}
138+
audio = wav_file(tmp_path, **options.get(case, {}))
139+
args = args_for(tmp_path, audio)
140+
if case == "missing":
141+
audio.unlink()
142+
elif case == "not-wav":
143+
audio.write_bytes(b"not a wav")
144+
elif case == "truncated":
145+
audio.write_bytes(audio.read_bytes()[:-4])
146+
elif case == "model-missing":
147+
(tmp_path / "model").rmdir()
148+
elif case == "output-exists":
149+
(tmp_path / "transcript.json").write_text("KEEP")
150+
elif case == "output-parent":
151+
args[-1] = str(tmp_path / "absent" / "out.json")
152+
with pytest.raises((SystemExit, OSError, ValueError, EOFError, wave.Error)):
153+
recipe(args)
154+
assert fake_model[0] == []
155+
if case == "output-exists":
156+
assert (tmp_path / "transcript.json").read_text() == "KEEP"
157+
else:
158+
assert not (tmp_path / "transcript.json").exists()
159+
160+
161+
@pytest.mark.parametrize("response", [[], [{}], [{"text": ""}], [{"text": 12}], [{"text": " "}], [{"text": "one"}, {"text": "two"}]])
162+
def test_invalid_results_do_not_create_success_file(recipe, tmp_path, fake_model, response):
163+
audio = wav_file(tmp_path)
164+
fake_model[1][:] = response
165+
with pytest.raises((SystemExit, ValueError, RuntimeError)):
166+
recipe(args_for(tmp_path, audio))
167+
assert not (tmp_path / "transcript.json").exists()
168+
169+
170+
def test_bilingual_code_is_identical(root):
171+
codes = []
172+
for prefix in ("", "en/"):
173+
soup = BeautifulSoup((root / prefix / "blog" / (SLUG + ".html")).read_text(), "html.parser")
174+
codes.append(soup.select_one('code[data-example="transcribe-first"]').get_text())
175+
assert codes[0] == codes[1]

‎web-pages/product-site/tests/test_hotword_release_article.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_catalogue_contains_daily_article_once():
2121
assert len(entries) == 1
2222
assert entries[0]["reviewed"] and entries[0]["category"] == "explanations"
2323
assert data["selected"] == [
24-
"meeting-transcript-acceptance", "fun-asr-nano-transformers",
24+
"meeting-transcript-acceptance", "speech-to-text-python-transcribe-audio",
2525
"self-hosted-openai-whisper-api-alternative", "funasr-transcribe-long-audio",
2626
]
2727

‎web-pages/product-site/tests/test_native_transformers_docs.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ def test_rendered_blog_models_guide_and_pages_are_connected(rendered, prefix, su
158158
for term in ["Transformers", "-hf", "vLLM", "GGUF", "2026-09-09"]:
159159
assert term in body
160160
index = BeautifulSoup((output / prefix / "blog/index.html").read_text(), "html.parser")
161-
assert len(index.select(f'a.post-card[href="/{prefix}blog/{BLOG}"]')) == 1
161+
assert not index.select(f'a.post-card[href="/{prefix}blog/{BLOG}"]')
162+
assert len(index.select(f'a.post-card[href="/{prefix}blog/speech-to-text-python-transcribe-audio.html"]')) == 1
163+
archive = BeautifulSoup((output / prefix / "blog/archive/index.html").read_text(), "html.parser")
164+
assert len(archive.select(f'a[href="/{prefix}blog/{BLOG}"]')) == 1
162165
models = BeautifulSoup((output / prefix / "models.html").read_text(), "html.parser")
163166
assert models.select_one(f'a[href="{route}"]')
164167
native = BeautifulSoup((output / prefix / "docs" / f"{SLUG}.html").read_text(), "html.parser")

‎web-pages/product-site/tests/test_punctuation_article.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,6 @@ def test_bilingual_examples_match_and_homepage_is_not_expanded():
9393
assert row["reviewed"] and row["category"] == "explanations"
9494
assert data["lead"] == "funclip-v2-2-0-moss-speaker-clipping"
9595
assert data["selected"] == [
96-
"meeting-transcript-acceptance", "fun-asr-nano-transformers",
96+
"meeting-transcript-acceptance", "speech-to-text-python-transcribe-audio",
9797
"self-hosted-openai-whisper-api-alternative", "funasr-transcribe-long-audio",
9898
]

0 commit comments

Comments
 (0)