Learn how to transcribe streaming audio in TypeScript.
node -v
.tsc -v
npm init
to create an NPM package, and then install the AssemblyAI package via NPM:
main.ts
and add the below code, replacing YOUR_API_KEY
with your copied API key.sample_rate
is the number of audio samples per second, measured in hertz (Hz). Higher sample rates result in higher quality audio, which may lead to better transcripts, but also more data being sent over the network.We recommend the following sample rates:8_000
(8 kHz)16_000
(16 kHz)48_000
(48 kHz)on("transcript.partial")
, and on("transcript.final")
callbacks to handle partial and final transcripts separately.on("open")
callback, create a new microphone stream. The sampleRate
needs to be the same value as the real-time service settings.SoxRecording
formats the audio data for you. If you want to stream data from elsewhere, make sure that your audio data is in the following format:transcriber.sendAudio(buffer)
.tsc main.ts
to compile the JavaScript file, and then run node main.js
to run it.