webaudio

API for Web Audio (JS)

Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version Unknown
License MIT
CI Status Passing
Downloads 0
Last Indexed 2026-07-21 05:24

Installation

nimble install webaudio
choosenim install webaudio
git clone https://github.com/ftsf/nim-webaudio

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
webaudio - - - - - - -

Source

Repository https://github.com/ftsf/nim-webaudio
Homepage https://github.com/ftsf/nim-webaudio
Registry Source nimble_official

README

Nim Wrapper for the Web Audio API

Example code for creating an oscillator that responds to clicks on the screen and fades and changes pitch over time.

Try it!

import webaudio
import dom

var ctx = newAudioContext()

var gain = ctx.createGain()
gain.gain.value = 0.5
gain.connect(ctx.destination)

var osc = ctx.createOscillator()
osc.type = "square"
osc.frequency.value = 440.0
osc.connect(gain)
osc.start()

discard window.setInterval(
  proc() =
    if gain.gain.value > 0.0:
      gain.gain.value -= 0.01
      if gain.gain.value < 0.0:
        gain.gain.value = 0.0
  , 30)

discard window.setInterval(
  proc() =
    osc.frequency.value *= 0.5
    if osc.frequency.value < 20.0:
      gain.gain.value = 0.0
  , 60)

window.addEventListener("mousedown") do(e: Event):
  osc.stop()
  osc = ctx.createOscillator()
  osc.type = "square"
  osc.frequency.value = 880.0
  osc.connect(gain)
  gain.gain.value = 0.5
  osc.start()