Published
Edited
Mar 7, 2022
Insert cell
Insert cell
Insert cell
Meyda = require(`meyda@${version.substring(1)}`)
Insert cell
Insert cell
audioContext = 'AudioContext' in window ? new AudioContext() : new window.webkitAudioContext()
Insert cell
audioFile = {
const oscillator = audioContext.createOscillator()
oscillator.frequency.setValueAtTime(261.6, audioContext.currentTime)
const destination = audioContext.createMediaStreamDestination()
const mediaRecorder = new MediaRecorder(destination.stream)
oscillator.connect(destination)
const chunks = []
mediaRecorder.ondataavailable = (evt) => { chunks.push(evt.data) }
// Record
mediaRecorder.start(10)
oscillator.start(0)
// Stop recording after one second
await new Promise((resolve) => setTimeout(() => {
mediaRecorder.stop()
oscillator.stop(0)
resolve()
}, 1000))
return new Blob(chunks, { 'type' : 'audio/ogg; codecs=opus' });
}
Insert cell
blobUrl = URL.createObjectURL(audioFile)
Insert cell
Insert cell
html`<audio src="${blobUrl}" controls />`
Insert cell
Insert cell
audioBuffer = audioContext.decodeAudioData(await (await fetch(blobUrl)).arrayBuffer())
Insert cell
Insert cell
{
Meyda.chromaBands = 12
const chroma = Meyda.extract('chroma', audioBuffer.getChannelData(0).slice(0, 4096))
return arrayTable(chroma)
}
Insert cell
Insert cell
{
Meyda.chromaBands = 24
const chroma = Meyda.extract('chroma', audioBuffer.getChannelData(0).slice(0, 4096))
return arrayTable(chroma)
}
Insert cell
Insert cell
Insert cell
arrayTable = a => {
const tableRows = a.map(
(d, i) => `${d === 1 ? `**${i}**` : i} | ${d === 1 ? `**${d}**` : d}`
).join('\n')
return md`
index | value
---|---
${tableRows}
`
}
Insert cell
releases = (await fetch('https://api.github.com/repos/meyda/meyda/releases')).json()
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more