Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[../deps/mpg123/src/output/coreaudio.c:81] warning: Didn't have any audio data in callback (buffer underflow) #69

Open
LayMuiToh opened this issue Apr 9, 2019 · 2 comments

Comments

@LayMuiToh
Copy link

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);
@LayMuiToh LayMuiToh changed the title Didn't have any audio data in callback (buffer underflow) [../deps/mpg123/src/output/coreaudio.c:81] warning: Didn't have any audio data in callback (buffer underflow) Apr 9, 2019
@LayMuiToh
Copy link
Author

LayMuiToh commented Apr 9, 2019

and a failure message:
the 2 AudioBuffers don't have the same sampleRate

I don't quite understand why there is 2 audiobuffers here?

@swordsreversed
Copy link

@LayMuiToh did you ever figure this out? Having a similar problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants