Last active
July 6, 2022 22:51
-
-
Save nicolaspanel/d1a275c54e85cd7df341337c137e50fb to your computer and use it in GitHub Desktop.
Getting started with Deeptranscript WebSocket streaming API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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