コンテンツにスキップ

はじめに

インストール

Terminal window
npm install waa-play

クイックスタート: クラス API (WaaPlayer)

WaaPlayerAudioContext をラップし、すべてのモジュールをメソッドとして提供します。最も簡単な使い方です。

import { WaaPlayer } from "waa-play";
const player = new WaaPlayer();
// Generate a 440 Hz sine tone, 2 seconds long
const buffer = player.createSineBuffer(440, 2);
// Start playback — returns a Playback handle
const playback = player.play(buffer);
// Listen to position updates
playback.on("timeupdate", ({ position }) => console.log(position));
// Clean up when done
player.dispose();

クイックスタート: 関数 API (BYO AudioContext)

完全な制御が必要な場合は、個別の関数をインポートして自前の AudioContext を使用します。このアプローチは完全に tree-shake 可能です。

import { createContext, ensureRunning, play } from "waa-play";
import { createSineBuffer } from "waa-play/synth";
const ctx = createContext();
await ensureRunning(ctx);
const buffer = createSineBuffer(ctx, 440, 2);
const pb = play(ctx, buffer);

すべての関数が AudioContext を第一引数に取るため、隠れた global state は一切ありません。

モジュール

waa-play は 12 の独立モジュールで構成されています。各モジュールは個別のエントリポイントなので、バンドラーは未使用のコードを tree-shake できます。

モジュールインポート用途
playerwaa-playWaaPlayer クラス — 全モジュールのコンビニエンスラッパー
contextwaa-play/contextAudioContext ライフサイクル (createContext, ensureRunning, now)
bufferwaa-play/buffer音声ファイル読み込み (loadBuffer, loadBufferFromBlob)
playwaa-play/playコア再生エンジン — Playback ハンドルを返す
emitterwaa-play/emitter型安全イベントエミッター (createEmitter<Events>())
nodeswaa-play/nodesAudio node ファクトリ、chain() / disconnectChain()
waveformwaa-play/waveformAudioBuffer からのピーク / RMS 抽出
fadewaa-play/fadeフェードイン、フェードアウト、クロスフェードユーティリティ
schedulerwaa-play/scheduler先読みスケジューラとクロック
synthwaa-play/synthバッファ合成 (サイン波、ノイズ、クリック)
adapterswaa-play/adaptersFramework 統合 (getSnapshot, subscribeSnapshot, onFrame)
stretcherwaa-play/stretcherWSOLA ベースの pitch 保持 time-stretch