in src/sdk/Audio/SpeakerAudioDestination.ts [79:126]
public close(cb?: () => void, err?: (error: string) => void): void {
this.privIsClosed = true;
if (this.privSourceBuffer !== undefined) {
this.handleSourceBufferUpdateEnd().then(() => {
if (!!cb) {
cb();
}
}, (error: string): void => {
if (!!err) {
err(error);
}
});
} else if (this.privAudioOutputStream !== undefined && typeof window !== "undefined") {
if ((this.privFormat.formatTag === AudioFormatTag.PCM || this.privFormat.formatTag === AudioFormatTag.MuLaw
|| this.privFormat.formatTag === AudioFormatTag.ALaw) && this.privFormat.hasHeader === false) {
// tslint:disable-next-line:no-console
console.warn(`Play back is not supported for raw PCM, mulaw or alaw format without header.`);
if (!!this.onAudioEnd) {
this.onAudioEnd(this);
}
} else {
let receivedAudio = new ArrayBuffer(this.privBytesReceived);
this.privAudioOutputStream.read(receivedAudio).then((_: number): void => {
receivedAudio = SynthesisAdapterBase.addHeader(receivedAudio, this.privFormat);
const audioBlob = new Blob([receivedAudio], { type: AudioFormatToMimeType[this.privFormat.formatTag] });
this.privAudio.src = window.URL.createObjectURL(audioBlob);
this.notifyPlayback().then(() => {
if (!!cb) {
cb();
}
}, (error: string): void => {
if (!!err) {
err(error);
}
});
}, (error: string): void => {
if (!!err) {
err(error);
}
});
}
} else {
// unsupported format, call onAudioEnd directly.
if (!!this.onAudioEnd) {
this.onAudioEnd(this);
}
}
}