5

I want to send audio signal coming from my audio interface (focusrite saffire) to my nodejs server. How should I go about doing this? The easiest way would be to access the audio interface from the browser (html5) like capturing microphone output with getUserMedia (https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia), but couldn't find a way to access my audio interface through that library. Otherwise, I'm planning on creating a desktop application, but don't know if there is a function/library to allow access to my usb-connected audio interface.

cwo
  • 113
  • 6
  • 1
    what OS are you on ? if linux there are a number of tools to view and change default input audio device – Scott Stensland Nov 09 '18 at 23:19
  • 1
    @ScottStensland Thanks for your reply, the OS would be linux. So after changing the default input audio device to my audio interface on the OS, I could be able to use that for the input in getUserMedia on the browser? If that's the case, I will report back once I get a hold of my audio interface. – cwo Nov 10 '18 at 22:42

2 Answers2

0

This probably has little to do with the Javascript or the MediaDevices API. On Linux, using Firefox, PulseAudio is required to interface with your audio hardware. Since your soundcard is an Input/Output interface, you should be able to test it pretty easily by simply playing any sound file in the browser.

Most of PulseAudio configuration can be achieved using pavucontrol GUI. You should check the "configuration" tab and both "input device" & "output device" tabs to make sure your Focusrite is correctly set up and used as sound I/O.

Once this is done, you should be able to access an audio stream using the following (only available if on a "secure context", ie localhost or served through HTTPS, as stated in the MDN page you mentionned):

navigator.mediaDevices.getUserMedia({ audio: true })
  .then(function(stream) {
    // do whatever you want with this audio stream
  })

(code snippet taken from the MDN page about MediaDevices)

Sending audio to the server is a whole other story. Have you tried anything? Are you looking for a real-time communication with the server? If so, I'd start by having a look at the WebSockets API. The WebRTC docs might be worth reading too, but it is more oriented to client-to-client communications.

corbin-c
  • 669
  • 8
  • 20
0

How to use exact device id

Use media device constrain to pass exact device id.

An sample would be

const preferedDeviceName = '<your_device_name>'
const deviceList = await navigator.mediaDevices.enumerateDevices()
const audio = devices.find((device) => device.kind === 'audioinput' && device.label === preferedDeviceName)
const {deviceId} = audio;
navigator.mediaDevices.getUserMedia({audio: { deviceId }}

How to process and send to the backend

Possible duplicate of this

Still not clear follow this

ChandraKumar
  • 515
  • 4
  • 14