Quick Start
This is the minimal graph to synthesize a tone:
ts
import { AudioContext } from '@nativescript/audio-context';
const ctx = new AudioContext({ latencyHint: 'interactive' });
const osc = ctx.createOscillator({ type: 'sine', frequency: 440 });
const gain = ctx.createGain({ gain: 0.12 });
osc.connect(gain);
gain.connect(ctx.destination);
await ctx.resume();
osc.start();
setTimeout(async () => {
osc.stop();
await ctx.close();
}, 1200);Lifecycle notes
- Call
resume()before playback. - Stop sources when done.
- Call
close()to release resources.