Spaces:
Running
Running
Download scripts/bake_audio.py from Ethscriptions/mx: direct link, hf CLI and curl.
- Browser
- Download file 976 Bytes
-
https://huggingface.co/spaces/Ethscriptions/mx/resolve/main/scripts/bake_audio.py
- Command line
-
hf download hf://spaces/Ethscriptions/mx/scripts/bake_audio.py
-
curl -L -o bake_audio.py https://huggingface.co/spaces/Ethscriptions/mx/resolve/main/scripts/bake_audio.py
976 Bytes
| """Render the procedural soundtrack in headless Chromium and bake it to frontend/public/audio/soundtrack.mp3""" | |
| import asyncio, base64, lameenc | |
| from playwright.async_api import async_playwright | |
| URL = "http://localhost:5173/preview/production/ed5ba841-ed53-4eec-a8c5-93237d26b7ab/?adebug=1" | |
| async def main(): | |
| async with async_playwright() as p: | |
| b = await p.chromium.launch() | |
| pg = await b.new_page() | |
| pg.on("console", lambda m: print(m.text[:300]) if "INFO" in m.text else None) | |
| await pg.goto(URL) | |
| await pg.wait_for_function("window.__done === true", timeout=300000) | |
| pcm = base64.b64decode(await pg.evaluate("window.__pcm")) | |
| await b.close() | |
| enc = lameenc.Encoder(); enc.set_bit_rate(192); enc.set_in_sample_rate(48000); enc.set_channels(2); enc.set_quality(2) | |
| mp3 = enc.encode(pcm) + enc.flush() | |
| open("frontend/public/audio/soundtrack.mp3", "wb").write(mp3) | |
| print("bytes", len(mp3)) | |
| asyncio.run(main()) | |