{"library":"node-web-audio-api","title":"Node Web Audio API","description":"Node Web Audio API provides a robust and specification-compliant implementation of the W3C Web Audio API for Node.js environments. Currently at version 1.0.9, it leverages a performant Rust backend (`web-audio-api-rs`) and `napi-rs` bindings to offer core audio processing capabilities, including `AudioContext`, `OscillatorNode`, and `GainNode`, suitable for server-side audio generation and manipulation. While a strict release cadence isn't published, updates align with improvements in its underlying Rust components. Key differentiators include its high performance and strict adherence to the Web Audio API specification, which is crucial for developers porting browser-based audio applications or building new audio services in Node.js. An accompanying `isomorphic-web-audio-api` package is available for cross-platform development.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install node-web-audio-api"],"cli":null},"imports":["import { AudioContext } from 'node-web-audio-api';","import { OscillatorNode } from 'node-web-audio-api';","import { GainNode } from 'node-web-audio-api';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { AudioContext, OscillatorNode, GainNode } from 'node-web-audio-api';\n\nconst audioContext = new AudioContext();\n\nconsole.log('Generating audio for 10 seconds...');\n\nconst stopTime = audioContext.currentTime + 10;\n\nconst intervalId = setInterval(() => {\n  if (audioContext.currentTime >= stopTime) {\n    clearInterval(intervalId);\n    console.log('Audio generation stopped.');\n    audioContext.close(); // Important to close context to release resources\n    return;\n  }\n\n  const now = audioContext.currentTime;\n  const frequency = 200 + Math.random() * 2800; // Random frequency between 200Hz and 3000Hz\n\n  const env = new GainNode(audioContext, { gain: 0 });\n  env.connect(audioContext.destination);\n  env.gain\n    .setValueAtTime(0, now)\n    .linearRampToValueAtTime(0.2, now + 0.02)\n    .exponentialRampToValueAtTime(0.0001, now + 1);\n\n  const osc = new OscillatorNode(audioContext, { frequency });\n  osc.connect(env);\n  osc.start(now);\n  osc.stop(now + 1);\n}, 80);\n","lang":"typescript","description":"This quickstart initializes an AudioContext and creates an oscillating sound with a random frequency and a decaying envelope every 80 milliseconds for a duration of 10 seconds.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}