Soniox

Async transcription with Node SDK

Transcribe audio files asynchronously with the Soniox Node SDK

Soniox Node SDK supports asynchronous transcription for audio files. This allows you to transcribe recordings without maintaining a live connection or streaming pipeline. You can either wait for completion or create a job and retrieve the results based on the webhook event.

Quickstart

SDK provides you a convenient method to transcribe audio from a local file, public URL, or previously uploaded file.

The transcribe method will:

  1. Upload the file to Soniox if it's not already uploaded (if file is provided)
  2. Transcribe the audio
  3. Await for the transcription to complete (if wait: true is provided)
  4. Return the transcription object and final transcript (you can disable this by setting fetch_transcript: false and fetch transcript later using getTranscript method)
  5. Delete the file from Soniox if was uploaded (configurable using cleanup option)

Don't forget to remove files and transcriptions from Soniox after you're done with them if cleanup option is not set.

Transcribe from a local file and delete everything after transcription is complete

const transcription = await client.stt.transcribe({
  model: 'stt-async-v4',
  file: audio, // Buffer, Uint8Array, Blob, ReadableStream
  filename: 'audio.mp3',
  wait: true,
  cleanup: ['file', 'transcription'],
});

Transcribe from a public URL and fetch the transcript later using getTranscript method

const transcription = await client.stt.transcribe({
  model: 'stt-async-v4',
  audio_url: 'https://soniox.com/media/examples/coffee_shop.mp3',
  wait: true,
});

const transcript = await transcription.getTranscript();

Transcribe from a previously uploaded file and setup a webhook to get the transcription when it's complete

const transcription = await client.stt.transcribe({
  model: 'stt-async-v4',
  file_id: file.id,
  wait: false,
  webhook_url: 'https://example.com/webhook',
});

Learn more about testing webhooks locally.

Retrieve list of transcriptions

You can retrieve a list of transcriptions using list method.

const transcriptions = await client.stt.list({
    limit: 100,
});

The returned result is async iterable - use for await...of to iterate through all pages.

for await (const transcription of transcriptions) {
    console.log(transcription.id, transcription.status);
}

Get transcription

You can get a transcription by ID using get method.

const transcription = await client.stt.get(transcription.id);
console.log(transcription.id, transcription.status);

Get transcription transcript

You can get a transcription transcript using getTranscript method.

const transcript = await transcription.getTranscript();
console.log(transcript.text);

Or get transcript by transcription ID.

const transcript = await client.stt.getTranscript(transcription.id);
console.log(transcript.text);

Segmenting transcripts

Group tokens by speaker and language changes:

const transcript = await transcription.getTranscript();

for (const segment of transcript?.segments() ?? []) {
  console.log(`[${segment.speaker}][${segment.language}] ${segment.text}`);
}

Delete or destroy transcription

You can delete or destroy a transcription using delete or destroy method.

Delete transcription only

await client.stt.delete(transcription.id);

Delete transcription and its file if it was uploaded

await client.stt.destroy(transcription.id);

Delete all transcriptions and files from your account

Delete all transcriptions

You can delete all transcriptions using stt.delete_all method.

await client.stt.delete_all();

Delete all transcriptions and their files

You can delete all transcriptions and their files using stt.destroy_all method.

await client.stt.destroy_all();

delete_all and destroy_all operations are irreversible and cannot be undone.