Open interactive version of the notebook
import io
import math
import struct
import wave

import marimo as mo
from here import PATH_ASSETS

image = (PATH_ASSETS / "dress.png").read_bytes()

audio = io.BytesIO()
sample_rate = 16_000
with wave.open(audio, "wb") as wav:
    wav.setnchannels(1)
    wav.setsampwidth(2)
    wav.setframerate(sample_rate)
    wav.writeframes(
        b"".join(
            struct.pack(
                "<h", int(8_000 * math.sin(2 * math.pi * 440 * i / sample_rate))
            )
            for i in range(sample_rate // 2)
        )
    )
mo.vstack(
    [
        mo.md(
            "# Static media test\n\nBoth controls should work without a server-side kernel."
        ),
        mo.image(
            image, alt="A dress sketch", width=320, caption="Local image bytes"
        ),
        mo.audio(audio),
    ],
    gap=1,
)

Static media test

Both controls should work without a server-side kernel.
A dress sketch
Local image bytes