Hiyve Components - v1.0.0
    Preparing search index...

    Sounds notes through Web Audio — with recorded samples when samples names a host, otherwise with a small built-in voice that needs no download. Give it an audio context started from a user gesture (a click on an answer is one); play returns a function that stops the note early.

    const synth = new NoteSynth(new AudioContext(), { samples: { baseUrl: 'https://cdn.example.com/soundfonts/FluidR3_GM/' } });
    synth.play(60); // middle C, on the piano
    synth.play([60, 64, 67]); // a chord
    Index

    Constructors

    Accessors

    Methods

    Constructors

    Accessors

    • get context(): AudioContext

      The context the notes sound through.

      Returns AudioContext

    Methods

    • Sound one note or several together, for durationMs unless told otherwise; returns a function that stops them early. listener is told as each starts and stops sounding. When the browser holds the sound back until a tap, nothing sounds or is announced, and onNeedsGesture is told.

      Parameters

      • midi: number | readonly number[]
      • durationMs: number = ...
      • Optionallistener: NoteSynthListener

      Returns () => void

    • Sound notes one after another, stepMs apart (default: 500), each for durationMs unless told otherwise — a melodic interval, a scale. Returns a function that stops them, those still to come included. listener is told as each starts and stops sounding.

      Parameters

      • midis: readonly number[]
      • stepMs: number = 500
      • durationMs: number = ...
      • Optionallistener: NoteSynthListener

      Returns () => void

    • Download the samples of some keys ahead of time; with no samples, nothing to do.

      Parameters

      • midis: readonly number[]

      Returns Promise<void>