Skip to content

Instantly share code, notes, and snippets.

@dimapaloskin
Last active May 14, 2024 18:45
Show Gist options
  • Save dimapaloskin/78be62f2216620cf5b80dc94306357e2 to your computer and use it in GitHub Desktop.
Save dimapaloskin/78be62f2216620cf5b80dc94306357e2 to your computer and use it in GitHub Desktop.
julia. play audio in pluto
begin
import WAV
import MIMEs
import URIs
function load_audio(audio, sr, html_attributes::Pair...)
buf = IOBuffer()
WAV.wavwrite(Int.(trunc.(0.99999999999 * audio * 2^23)), buf, Fs=sr, nbits=24)
mime = MIME("audio/wav")
src = "data:$(
string(something(mime,""))
);base64,$(
base64encode(take!(buf))
)"
PlutoUI.Resource(src, mime, html_attributes)
end
end
# usage
begin
sr = 48000.0
time = 1
f = 220
x = 0.0:1.0/sr:time
y = sin.(2 * pi * f * x)
load_audio(y, sr, :autoplay => true)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment