Extraction via websocket

Nabla also offer a direct endpoint for live audio analysis, using websocket. This is ideal to test our service on e.g. audio files. The following snippet shows an example call implemented in Node.JS.

Several notes:

  • The authentication header is expected to be passed as one of the options of the protocol array.
  • The first message sent is expected to be a description of the audio format expected:
    • mime - string: mime type of the audio provided. See: supported audio mime type
    • sampleRateHertz - integer: sampling rate, required for webM
    • language - string: expected language spoken
  • All the other messages are expected to be subsequent binary arrays
  • Messages received from server are ensured to be json strings, corresponding to TranscriptItem objects (defined here) or EHRItems object (defined here)
import WebSocket from 'ws';

const ws = new WebSocket(
  'wss://api.nabla.com/v1/extract/ws', 
  [
    "authorization-<TOKEN>"
  ]
);

ws.onmessage = (event) =>  {
    var jsonObject = JSON.parse(event.data);
    console.log(`Received item of type ${jsonObject["type"]}`);
}

// [...]

ws.send(
  JSON.stringify(
    {
      mime: "audio/webm;codecs=opus",
      sampleRateHertz: "48000",
      language: "fr-FR"
    }
  )
)

// [...]

while (...) {
    ws.send(getNextAudioArrayBuffer())
}

Supported audio MIME types

MIME

Description

"audio/mp3"

MPEG Audio Layer III

"audio/pcm"

16-bit linear pulse-code modulation (PCM) encoding.

"audio/flac"

Free Lossless Audio Codec

"audio/webm;codec=opus"

Opus encoded audio in a webm container. Sample rate must be one of 8000 Hz, 12000 Hz, 16000 Hz, 24000 Hz, or 48000 Hz