node.jsobsobs-studio

obs-websocket-js play audio url


I need to switch the scene and play an audio file through a third party url

Previously it could have been done something like this

const OBSWebSocket = require('obs-websocket-js');
const obs = new OBSWebSocket();

obs.connect(obsSettings)
   .then(() => {
         obs.send('SetCurrentScene', { 'scene-name': 'YourSceneName' });
         obs.send('PlayAudio', { source: 'YourAudioSourceName', file: url });
             console.log('Audio playback started');
         })
         .catch(err => {
             console.error(`OBS connection error: ${err}`);
  });

but now the obs.send command does not work, instead of it obs.call, and let’s say to change the scene I need to use this code

obs.call('SetCurrentProgramScene', { sceneName: 'YourSceneName' });

But how can I play audio in obs? I can't find how this is currently implemented

In general, the essence of my question is to translate the text in a voice message and display it in obs

This is how I do things

const voiceUrl = googleTTS.getAudioUrl(response, {
       lang: 'en',
       slow: false,
       host: 'https://translate.google.com',
  });
console.log(`Voice message: ${voiceUrl}`);
playVoice('Voice', voiceUrl);

I get a link to this voice message, then call the playVoice function to play it in obs

const OBSWebSocket = require('obs-websocket-js').default;
const obs = new OBSWebSocket();

function playVoice(sourceName, voiceUrl) {
    obs.call('SetCurrentProgramScene', { sceneName: 'Main' });
    obs.call('PlayAudio', { source: sourceName, file: voiceUrl });
}

SetCurrentProgramScene with scene change works as it should. But how can I play this audio through url? PlayAudio request not working


Solution

  • This is not exact answer to your question, I think the websocket api seems not to support this sort of activity anymore (see https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requests ) Have you thought different approach to this problem:

    You could do just web app using node and express + socket.io... and serve empty (and transparent) webpage that plays the audio using javascript and tag and add the page as browser source.