UNPKG

2.78 kBTypeScriptView Raw
1import { ToneAudioNode, ToneAudioNodeOptions } from "../../core/context/ToneAudioNode.js";
2import { Gain } from "../../core/context/Gain.js";
3import { PlaybackState } from "../../core/util/StateTimeline.js";
4export interface RecorderOptions extends ToneAudioNodeOptions {
5 mimeType?: string;
6}
7/**
8 * A wrapper around the MediaRecorder API. Unlike the rest of Tone.js, this module does not offer
9 * any sample-accurate scheduling because it is not a feature of the MediaRecorder API.
10 * This is only natively supported in Chrome and Firefox.
11 * For a cross-browser shim, install (audio-recorder-polyfill)[https://www.npmjs.com/package/audio-recorder-polyfill].
12 * @example
13 * const recorder = new Tone.Recorder();
14 * const synth = new Tone.Synth().connect(recorder);
15 * // start recording
16 * recorder.start();
17 * // generate a few notes
18 * synth.triggerAttackRelease("C3", 0.5);
19 * synth.triggerAttackRelease("C4", 0.5, "+1");
20 * synth.triggerAttackRelease("C5", 0.5, "+2");
21 * // wait for the notes to end and stop the recording
22 * setTimeout(async () => {
23 * // the recorded audio is returned as a blob
24 * const recording = await recorder.stop();
25 * // download the recording by creating an anchor element and blob url
26 * const url = URL.createObjectURL(recording);
27 * const anchor = document.createElement("a");
28 * anchor.download = "recording.webm";
29 * anchor.href = url;
30 * anchor.click();
31 * }, 4000);
32 * @category Component
33 */
34export declare class Recorder extends ToneAudioNode<RecorderOptions> {
35 readonly name = "Recorder";
36 /**
37 * Recorder uses the Media Recorder API
38 */
39 private _recorder;
40 /**
41 * MediaRecorder requires
42 */
43 private _stream;
44 readonly input: Gain;
45 readonly output: undefined;
46 constructor(options?: Partial<RecorderOptions>);
47 static getDefaults(): RecorderOptions;
48 /**
49 * The mime type is the format that the audio is encoded in. For Chrome
50 * that is typically webm encoded as "vorbis".
51 */
52 get mimeType(): string;
53 /**
54 * Test if your platform supports the Media Recorder API. If it's not available,
55 * try installing this (polyfill)[https://www.npmjs.com/package/audio-recorder-polyfill].
56 */
57 static get supported(): boolean;
58 /**
59 * Get the playback state of the Recorder, either "started", "stopped" or "paused"
60 */
61 get state(): PlaybackState;
62 /**
63 * Start the Recorder. Returns a promise which resolves
64 * when the recorder has started.
65 */
66 start(): Promise<void>;
67 /**
68 * Stop the recorder. Returns a promise with the recorded content until this point
69 * encoded as {@link mimeType}
70 */
71 stop(): Promise<Blob>;
72 /**
73 * Pause the recorder
74 */
75 pause(): this;
76 dispose(): this;
77}