Skip to content

Instantly share code, notes, and snippets.

@nicolaspanel
Last active July 6, 2022 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicolaspanel/d1a275c54e85cd7df341337c137e50fb to your computer and use it in GitHub Desktop.
Save nicolaspanel/d1a275c54e85cd7df341337c137e50fb to your computer and use it in GitHub Desktop.
Getting started with Deeptranscript WebSocket streaming API
const querystring = require('querystring');
const ws = require("ws");
const qs = querystring.stringify({{
language: 'fr',
sampleRate: sampleRate, // WARN: must match recording configuration
format: 's16le', // WARN: must match recording configuration
// expectedPhrases: ['can be a word or a short sentence'],
}})
const socket = new ws.WebSocket(`wss://:${{process.env.API_TOKEN}}@stream.deeptranscript.com/?${{qs}}`);
socket.on('open', () => {{
console.log('socket opened');
// Raw data is sent as is, no preprocessing needed
inputStream.on('data', (bytes) => socket.send(bytes, {{ binary: true }});
// IMPORTANT: send empty buffer to tell DT to terminate
// transcription automatically close after 3s with no input data
inputStream.on('end', () => socket.send(Buffer.from([]), {{ binary: true }}));
}});
socket.on('error', (err) => console.error(err));
socket.on('message', (data) => console.log('message received: %s', data));
socket.on('close', () => console.log('close event received => done'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment