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
Pre-load a MP3 file from another website.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
Cancel a sound that is playing.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
Play a MP3 file from another website.os.playSound("https://www.testsounds.com/track06.mp3");
os.beginAudioRecording(options?: Omit<BeginAudioRecordingAction, ("type" | "taskId")>): 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<BeginAudioRecordingAction, ("type" | "taskId")> and is the options that determines how the audio should be recorded.
Examples
Record some audio for 10 seconds and download the file.await os.beginAudioRecording();
await os.sleep(10000);
const data = await os.endAudioRecording();
os.download(data);Stream some raw audio data for 10 seconds.await os.beginAudioRecording({
stream: true,
mimeType: 'audio/x-raw'
});
//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
Record some audio for 10 seconds and download the file.await os.beginAudioRecording();
await os.sleep(10000);
const data = await os.endAudioRecording();
os.download(data);