Skip to content

Use video-to-text-js to upload media, create transcription tasks, and poll for results.

The Node.js client wraps the public upload and task APIs with typed helpers.

Terminal window
pnpm add video-to-text-js
import { VideoToTextClient } from 'video-to-text-js'
const client = new VideoToTextClient({
apiKey: process.env.VTT_API_KEY!,
})
import { readFile } from 'node:fs/promises'
const file = await readFile('meeting.mp4')
const task = await client.transcriptions.transcribeFile(file, {
filename: 'meeting.mp4',
mimetype: 'video/mp4',
language: 'Auto',
timestampMode: 'CHUNK',
transcriptionMode: 'balanced',
timeoutMs: 10 * 60 * 1000,
})
console.log(task.fullText)

Use precision when accuracy is more important than credit cost.

const upload = await client.uploads.create({
filename: 'meeting.mp4',
mimetype: 'video/mp4',
})
await client.uploads.put(upload.uploadUrl, file, {
mimetype: 'video/mp4',
})
const asset = await client.uploads.complete(upload.uploadId, {
fileKey: upload.fileKey,
fileUrl: upload.fileUrl,
filename: 'meeting.mp4',
mimetype: 'video/mp4',
fileSize: file.byteLength,
})
const created = await client.tasks.create({
assetId: asset.assetId,
language: 'Auto',
timestampMode: 'CHUNK',
transcriptionMode: 'balanced',
})
const result = await client.tasks.wait(created.transcriptId)
console.log(result.fullText)

tasks.wait() returns when the task reaches SUCCEEDED. If the task reaches FAILED or CANCELED, the client throws an APIError and uses showError as the error detail when available.

Task details include fullText, chunks, words, sourceDurationMs, resultLanguage, transcriptionMode, and billedCredits.

import { APIError, RateLimitError, UploadError } from 'video-to-text-js'
try {
await client.transcriptions.transcribeFile(file, {
filename: 'meeting.mp4',
mimetype: 'video/mp4',
})
} catch (error) {
if (error instanceof RateLimitError) {
console.error('Please retry later.')
} else if (error instanceof UploadError) {
console.error('The media upload did not complete.')
} else if (error instanceof APIError) {
console.error(error.errorCode, error.detail)
}
}

For source code, issues, and contributions, visit the video-to-text-js GitHub repository. Install the latest video-to-text-js package from npm.