Spaces:
Running
Running
登泰山记:旁白音频分批加载 + 自动重试(防限流),最终版
Browse files- README.md +1 -1
- dengtaishan-src/src/video/audio.ts +29 -7
- dengtaishan-src/tools/r429.py +17 -0
- dengtaishan/assets/App-BhMOC_Pm.js +0 -0
- dengtaishan/assets/index-Dhi7ybs-.js +2 -0
- dengtaishan/index.html +1 -1
README.md
CHANGED
|
@@ -69,7 +69,7 @@ pinned: false
|
|
| 69 |
|
| 70 |
### 验收记录(第 8 步)
|
| 71 |
|
| 72 |
-
- 构建:开发与生产构建均通过;Space 页面、字体(5 款 woff2,含 CORS)、93 段旁白音频均可正常加载,无报错。
|
| 73 |
- 版面:横屏/竖屏逐秒自动排版检测(越界、文字重叠),已修正全部持续性冲突;仅余推镜头时标签移出画面、转场单帧叠化,属正常镜头效果。
|
| 74 |
- 竖屏:手机宽度 390px 下页面无横向溢出,播放器自动切换 9:16。
|
| 75 |
- 导出:实测横屏 720P/24fps、竖屏 1080P/30fps 均生成合法 MP4(H.264 + AAC/Opus,自动回退)。
|
|
|
|
| 69 |
|
| 70 |
### 验收记录(第 8 步)
|
| 71 |
|
| 72 |
+
- 构建:开发与生产构建均通过;旁白音频改为 6 路并发 + 失败退避重试,防止静态托管限流;Space 页面、字体(5 款 woff2,含 CORS)、93 段旁白音频均可正常加载,无报错。
|
| 73 |
- 版面:横屏/竖屏逐秒自动排版检测(越界、文字重叠),已修正全部持续性冲突;仅余推镜头时标签移出画面、转场单帧叠化,属正常镜头效果。
|
| 74 |
- 竖屏:手机宽度 390px 下页面无横向溢出,播放器自动切换 9:16。
|
| 75 |
- 导出:实测横屏 720P/24fps、竖屏 1080P/30fps 均生成合法 MP4(H.264 + AAC/Opus,自动回退)。
|
dengtaishan-src/src/video/audio.ts
CHANGED
|
@@ -19,15 +19,37 @@ export function loadVoices(onProgress?: (p: number) => void) {
|
|
| 19 |
const base = import.meta.env.BASE_URL || './'
|
| 20 |
const dec = new OfflineAudioContext(1, 1, 24000)
|
| 21 |
let done = 0
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
done++
|
| 28 |
onProgress?.(done / ALL_LINES.length)
|
| 29 |
-
}
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
return voiceLoading
|
| 32 |
}
|
| 33 |
|
|
|
|
| 19 |
const base = import.meta.env.BASE_URL || './'
|
| 20 |
const dec = new OfflineAudioContext(1, 1, 24000)
|
| 21 |
let done = 0
|
| 22 |
+
// 分批(最多 6 路并发)+ 失败退避重试,避免静态托管限流(429)导致整段旁白加载失败
|
| 23 |
+
const fetchOne = async (id: string) => {
|
| 24 |
+
let err: unknown
|
| 25 |
+
for (let i = 0; i < 6; i++) {
|
| 26 |
+
try {
|
| 27 |
+
const r = await fetch(`${base}voice/${id}.mp3`)
|
| 28 |
+
if (!r.ok) throw new Error(`HTTP ${r.status}`)
|
| 29 |
+
return await dec.decodeAudioData(await r.arrayBuffer())
|
| 30 |
+
} catch (e) {
|
| 31 |
+
err = e
|
| 32 |
+
await new Promise((res) => setTimeout(res, 400 * 2 ** i + Math.random() * 300))
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
throw err
|
| 36 |
+
}
|
| 37 |
+
const queue = ALL_LINES.filter((l) => !voices[l.id]).map((l) => l.id)
|
| 38 |
+
done = ALL_LINES.length - queue.length
|
| 39 |
+
const worker = async () => {
|
| 40 |
+
while (queue.length) {
|
| 41 |
+
const id = queue.shift()!
|
| 42 |
+
voices[id] = await fetchOne(id)
|
| 43 |
done++
|
| 44 |
onProgress?.(done / ALL_LINES.length)
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
voiceLoading = Promise.all(Array.from({ length: 6 }, worker))
|
| 48 |
+
.then(() => undefined)
|
| 49 |
+
.catch((e) => {
|
| 50 |
+
voiceLoading = null
|
| 51 |
+
throw e
|
| 52 |
+
})
|
| 53 |
return voiceLoading
|
| 54 |
}
|
| 55 |
|
dengtaishan-src/tools/r429.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
from playwright.async_api import async_playwright
|
| 3 |
+
async def main():
|
| 4 |
+
async with async_playwright() as p:
|
| 5 |
+
b = await p.chromium.launch()
|
| 6 |
+
pg = await b.new_page()
|
| 7 |
+
bad=[]; n=[0]
|
| 8 |
+
def on(r):
|
| 9 |
+
n[0]+=1
|
| 10 |
+
if r.status>=400: bad.append((r.status, r.url[:90]))
|
| 11 |
+
pg.on("response", on)
|
| 12 |
+
await pg.goto("https://ethscriptions-mx.static.hf.space/")
|
| 13 |
+
await pg.wait_for_timeout(15000)
|
| 14 |
+
print("responses", n[0]); [print(x) for x in bad[:20]]
|
| 15 |
+
print("voice ok?", await pg.evaluate("document.body.innerText.includes('旁白')"))
|
| 16 |
+
await b.close()
|
| 17 |
+
asyncio.run(main())
|
dengtaishan/assets/App-BhMOC_Pm.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
dengtaishan/assets/index-Dhi7ybs-.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./index-Br42UDbl.js","./index-BlGQAcOD.js","./client-BlQxAbrl.js","./index-tKuM8enU.js","./App-BhMOC_Pm.js","./jsx-dev-runtime-Czb3f8pQ.js","./ErrorBoundary-DwultlP_.js"])))=>i.map(i=>d[i]);
|
| 2 |
+
(function(){const o=document.createElement("link").relList;if(o&&o.supports&&o.supports("modulepreload"))return;for(const e of document.querySelectorAll('link[rel="modulepreload"]'))d(e);new MutationObserver(e=>{for(const t of e)if(t.type==="childList")for(const s of t.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&d(s)}).observe(document,{childList:!0,subtree:!0});function i(e){const t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin==="use-credentials"?t.credentials="include":e.crossOrigin==="anonymous"?t.credentials="omit":t.credentials="same-origin",t}function d(e){if(e.ep)return;e.ep=!0;const t=i(e);fetch(e.href,t)}})();const E="modulepreload",v=function(r,o){return new URL(r,o).href},w={},y=function(o,i,d){let e=Promise.resolve();if(i&&i.length>0){let s=function(n){return Promise.all(n.map(u=>Promise.resolve(u).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};const l=document.getElementsByTagName("link"),f=document.querySelector("meta[property=csp-nonce]"),h=(f==null?void 0:f.nonce)||(f==null?void 0:f.getAttribute("nonce"));e=s(i.map(n=>{if(n=v(n,d),n in w)return;w[n]=!0;const u=n.endsWith(".css"),p=u?'[rel="stylesheet"]':"";if(!!d)for(let m=l.length-1;m>=0;m--){const g=l[m];if(g.href===n&&(!u||g.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${n}"]${p}`))return;const c=document.createElement("link");if(c.rel=u?"stylesheet":E,u||(c.as="script"),c.crossOrigin="",c.href=n,h&&c.setAttribute("nonce",h),document.head.appendChild(c),u)return new Promise((m,g)=>{c.addEventListener("load",m),c.addEventListener("error",()=>g(new Error(`Unable to preload CSS for ${n}`)))})}))}function t(s){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=s,window.dispatchEvent(l),!l.defaultPrevented)throw s}return e.then(s=>{for(const l of s||[])l.status==="rejected"&&t(l.reason);return o().catch(t)})},_="__dep_reload",L=6,O=6e4;function P(){try{return JSON.parse(sessionStorage.getItem(_)||"{}")}catch{return{c:0,t:0}}}async function R(){const r=document.getElementById("root");try{let o=function(){if(!document.querySelector("[data-surf-placeholder]"))try{window.parent.postMessage({type:"surf-app-ready"},"*")}catch{}};const i=await y(()=>import("./index-Br42UDbl.js").then(a=>a.i),__vite__mapDeps([0,1]),import.meta.url);if(typeof i.useState!="function")throw new Error("dep-stub");const{createElement:d}=i,{createRoot:e,hydrateRoot:t}=await y(async()=>{const{createRoot:a,hydrateRoot:c}=await import("./client-BlQxAbrl.js").then(m=>m.c);return{createRoot:a,hydrateRoot:c}},__vite__mapDeps([2,1]),import.meta.url),{QueryClient:s,QueryClientProvider:l}=await y(async()=>{const{QueryClient:a,QueryClientProvider:c}=await import("./index-tKuM8enU.js");return{QueryClient:a,QueryClientProvider:c}},__vite__mapDeps([3,0,1]),import.meta.url),{default:f}=await y(async()=>{const{default:a}=await import("./App-BhMOC_Pm.js");return{default:a}},__vite__mapDeps([4,5,1,0]),import.meta.url),{default:h}=await y(async()=>{const{default:a}=await import("./ErrorBoundary-DwultlP_.js");return{default:a}},__vite__mapDeps([6,5,1,0]),import.meta.url),n=new s({defaultOptions:{queries:{refetchOnWindowFocus:!1,retry:3,retryDelay:a=>Math.min(1e3*2**a,1e4),staleTime:3e4}}}),u=d(h,null,d(l,{client:n},d(f))),p=!!r.querySelector("[data-surf-placeholder]");r.childNodes.length>0&&r.innerHTML!=="<!--ssr-outlet-->"&&!p?t(r,u):(r.innerHTML="",e(r).render(u)),window.__reactOk=!0,sessionStorage.removeItem(_),o(),new MutationObserver(o).observe(r,{childList:!0,subtree:!0})}catch{const o=P(),i=Date.now()-o.t>O?0:o.c;i<L?(r.innerHTML=['<div style="padding:24px;text-align:center;font-family:system-ui,sans-serif">','<p style="color:#3b82f6;font-weight:600;margin:0 0 4px">Loading dependencies...</p>','<p style="color:#3b82f6;opacity:0.7;font-size:12px;margin:0">Reloading automatically</p>',"</div>"].join(""),sessionStorage.setItem(_,JSON.stringify({c:i+1,t:Date.now()})),setTimeout(()=>location.reload(),3e3+i*1e3)):r.innerHTML=['<div style="padding:24px;text-align:center;font-family:system-ui,sans-serif">','<p style="color:#c0392b;font-weight:600;margin:0 0 4px">Failed to load dependencies</p>','<p style="color:#c0392b;opacity:0.8;font-size:12px;margin:0">Please refresh the page</p>',"</div>"].join("")}}R();
|
dengtaishan/index.html
CHANGED
|
@@ -59,7 +59,7 @@
|
|
| 59 |
<script>
|
| 60 |
document.documentElement.classList.add('dark');
|
| 61 |
</script>
|
| 62 |
-
<script type="module" crossorigin src="./assets/index-
|
| 63 |
<link rel="stylesheet" crossorigin href="./assets/index-DLo4v_cJ.css">
|
| 64 |
</head>
|
| 65 |
<body>
|
|
|
|
| 59 |
<script>
|
| 60 |
document.documentElement.classList.add('dark');
|
| 61 |
</script>
|
| 62 |
+
<script type="module" crossorigin src="./assets/index-Dhi7ybs-.js"></script>
|
| 63 |
<link rel="stylesheet" crossorigin href="./assets/index-DLo4v_cJ.css">
|
| 64 |
</head>
|
| 65 |
<body>
|