mx / dengtaishan-src /tools /pagetest.py
Ethscriptions's picture
登泰山记:渲染引擎、九个篇章场景、程序化配乐音效、MP4 导出、发布文案与封面(初版)
6fff8e3 verified
Raw History Blame Contribute Delete
1.93 kB
import asyncio, sys, json, time
from playwright.async_api import async_playwright
BASE = "http://localhost:5173/preview/production/1b822e06-b78d-4352-884d-1f8fddabf546/"
async def main():
async with async_playwright() as p:
b = await p.chromium.launch(args=["--autoplay-policy=no-user-gesture-required"])
pg = await b.new_page(viewport={"width": 1400, "height": 900})
errs = []
pg.on("pageerror", lambda e: errs.append("PAGEERROR " + str(e)))
pg.on("console", lambda m: errs.append(m.type + ": " + m.text) if m.type in ("error", "warning") else None)
await pg.goto(BASE)
await pg.wait_for_timeout(5000)
txt = await pg.evaluate("document.body.innerText.slice(0, 600)")
print(txt)
# audio segment test
r = await pg.evaluate("""async () => {
const m = await import('./src/video/audio.ts');
const t0 = performance.now();
await m.loadVoices();
const t1 = performance.now();
const out = {};
for (const k of [0, 7, 9, 13]) {
const s = performance.now();
const b = await m.renderSegment(k, true);
const d = b.getChannelData(0);
let sum = 0, peak = 0;
for (let i = 0; i < d.length; i++) { sum += d[i]*d[i]; peak = Math.max(peak, Math.abs(d[i])); }
out[k] = { ms: Math.round(performance.now() - s), len: b.length, rms: Math.sqrt(sum / d.length).toFixed(4), peak: peak.toFixed(3) };
}
const nb = await m.renderSegment(9, false);
const d2 = nb.getChannelData(0); let s2=0; for (let i=0;i<d2.length;i++) s2+=d2[i]*d2[i];
out.nomusic9 = Math.sqrt(s2/d2.length).toFixed(4);
return { voiceMs: Math.round(t1 - t0), segs: m.SEG_COUNT, out };
}""")
print(json.dumps(r, indent=1))
for e in errs[:20]: print(e)
await b.close()
asyncio.run(main())