web-audio-api
web-audio-api copied to clipboard
[../deps/mpg123/src/output/coreaudio.c:81] warning: Didn't have any audio data in callback (buffer underflow)
I got the above failure error message the code snippet:
audioCtx = new AudioContext,
Speaker = require('speaker');
audioCtx.outStream = new Speaker({
channels: audioCtx.format.numberOfChannels,
bitDepth: audioCtx.format.bitDepth,
sampleRate: audioCtx.sampleRate
})
let data;
let count;
let startTime;
var WebSocket = require('ws');
var wsUri = "ws://" + xlVAServer[0].wsURI;
console.log("Connecting to " + wsUri);
var ws = new WebSocket(wsUri);
ws.onopen = function(evt) { onOpen(evt) };
ws.onclose = function(evt) { onClose(evt) };
ws.onmessage = function(evt) { onMessage(evt) };
ws.onerror = function(evt) { onError(evt) };
// Event Handlers to websocket connection
function onOpen(evt) {
console.log("Connected to server");
}
function onClose(evt) {
console.log("Disconnected from server");
}
function onError(evt) {
console.log("Communication error");
}
function onMessage(evt) {
console.log("Receiving data on websocket ...");
if (evt.data instanceof ArrayBuffer)
{
if (count == 0) {
startTime = audioCtx.currentTime;
}
audioCtx.decodeAudioData(evt.data, function(data) {
count++;
startTime = startTime + 0.3;
let duration = playSound(data, startTime);
console.log('Duration: ' + duration);
startTime = startTime + duration;
});
}
}
function playSound(buffer, playTime)
{
let source = audioCtx.createBufferSource();
console.log('Audio playback...');
source.buffer = buffer;
source.start(playTime);
source.connect(audioCtx.destination);
console.log('connect destination ');
let duration = buffer.duration;
return duration;
}
function perform_tts(text)
{
data = new ArrayBuffer(0);
count = 0;
ws.binaryType = "arraybuffer";
console.log('Sending text ' + text);
ws.send(text);
}
export async function playAudio(text, image_name, start_delay, end_delay) {
switch(xlVAServer[0].useTL_TTS) {
case 'yes':
return perform_tts(text);
and a failure message: the 2 AudioBuffers don't have the same sampleRate
I don't quite understand why there is 2 audiobuffers here?
@LayMuiToh did you ever figure this out? Having a similar problem.