Audio Actions
os.bufferSound(url: string): Promise<any>
Loads the audio from the given URL without playing it. Returns a promise that resolves once the sound has been loaded.
This is useful for pre-loading a sound so that there will be no delay when playing it with os.playSound(url)
.
The first parameter is a string and is the URL of the audio/music/sound clip that should be loaded.
Examples
os.bufferSound("https://www.testsounds.com/track06.mp3");
os.cancelSound(soundId: (string | number | object)): Promise<any>
Cancels the sound with the given ID. Returns a promise that resolves once the sound has been canceled.
The first parameter is a (string | number | object) and is the ID of the sound that was returned from
os.playSound(url)
.
Examples
const id = await os.playSound("https://www.testsounds.com/track06.mp3");
os.cancelSound(id);
os.playSound(url: string): Promise<any>
Loads and plays the audio (MP3, WAV, etc.) from the given URL.
Returns a promise that resolves with the ID of the sound when the sound starts playing. The sound ID can then be used with os.cancelSound(soundId)
to stop the sound.
The first parameter is a string and is the URL of the audio/music/sound clip that should be played.
Examples
os.playSound("https://www.testsounds.com/track06.mp3");
os.beginAudioRecording(options?: Omit): Promise<void>
Starts a new audio recording. Returns a promise that resolves when recording has started. The returned promise will throw an error if recording could not be started. Reasons for this include insufficient permissions and not having a microphone.
Triggers @onBeginAudioRecording
once recording has started and continuously triggers @onAudioChunk
if stream is set to true.
The first parameter is optional and is a Omit and is the options that determines how the audio should be recorded.
Examples
await os.beginAudioRecording();
await os.sleep(10000);
const data = await os.endAudioRecording();
os.download(data);
await os.beginAudioRecording({
stream: true,
mimeType: 'audio/x-raw'
});
// @onAudioChunk will be called whenever a new sample is available.
await os.sleep(10000);
await os.endAudioRecording();
os.endAudioRecording(): Promise<Blob>
Stops the audio recording that is in progress. Returns a promise that resolves with the recorded data. If the recording was started with stream: true, then the recorded data will be null.
Triggers @onEndAudioRecording
once recording has finished.
Examples
await os.beginAudioRecording();
await os.sleep(10000);
const data = await os.endAudioRecording();
os.download(data);