Use the speech Node.js SDK to submit audio URLs to Qwen-Audio-ASR-Filetrans, query asynchronous tasks, and download transcripts.
Install the SDK
Requires Node.js 18 or later. Download the SDK 0.1.0 package, then run this command in your project:
Quick start
Obtain an API key in the console and set it as the DASHSCOPE_API_KEY environment variable.
Save the following example as example.mjs and run node example.mjs.
API reference
Constructor options
Constructor options for TranscriptionClient:
| Parameter | Type | Required | Description |
|---|---|---|---|
apiKey | string | No | API key. Defaults to DASHSCOPE_API_KEY. |
baseUrl | string | No | Set the service hostname to ap-southeast-1.maas.qwencloudapi.com (Singapore). |
model | string | No | Model ID. Default: qwen-audio-3.1-asr-flash-filetrans. |
pollIntervalMs | number | No | Polling interval. Default: 3000 ms. |
pollTimeoutMs | number | No | Polling timeout in ms. Default: 600000. |
requestTimeoutMs | number | No | HTTP request timeout in ms. Default: 30000; 0 disables the per-request timeout. |
Transcription parameters
The second argument of transcribe() and submitTask() is parameters; the third accepts context. See the HTTP API for full model parameter details.
| Parameter | Type | Required | Description |
|---|---|---|---|
fileUrls | string | string[] | Yes | Publicly accessible audio URL; one file per task. |
parameters.keep_dialect | boolean | No | Preserve dialect expressions. Default: false. |
parameters.vocabulary_id | string | No | Precompiled vocabulary ID. |
parameters.vocabulary | Record<string, number> | No | Instant vocabulary: words as keys and weights in [1,5] or 50 as values. |
parameters.channel_id | number[] | No | Audio channel indices. Default: [0]. |
parameters.special_word_filter | string | Record<string, unknown> | No | Sensitive-word filtering configuration as a JSON string or object. |
parameters.diarization_enabled | boolean | No | Speaker diarization for mono audio. Default: false. |
parameters.speaker_count | number | No | Expected speaker count: [2,100]. Requires speaker diarization. |
parameters.language_hints | string[] | No | Recognition language hints. Up to the first 4 values take effect. Language is detected automatically if omitted. |
callOpts.context / submitOpts.context | AsrContextMessage[] | No | Recognition context. Message format: { role, content: [{ type: "input_text", text }] }, with role set to user or assistant. Up to 5 messages per role and fewer than 400 characters in total, ordered by conversation turn. |
callOpts.onProgress | (status: string, response: QueryTaskResponse) => void | No | Polling progress callback with status and raw response. |
Main methods
| Method | Return value | Description |
|---|---|---|
transcribe(fileUrls: string | string[], parameters?: TranscriptionParameters, callOpts?: TranscribeCallOptions) | Promise<TranscriptionJobResult> | Submit audio, poll, and download results. callOpts accepts context and a progress callback. |
submitTask(fileUrls: string | string[], parameters?: TranscriptionParameters, submitOpts?: TranscriptionSubmitOptions) | Promise<{ taskId: string; taskStatus: string }> | Submit a task and return its ID and initial status. Set context with submitOpts.context. |
fetchTask(taskId: string, requestTimeoutMs?: number) | Promise<QueryTaskResponse> | Query a task once for its status and result URLs. |
Return values
| Field | Type | Description |
|---|---|---|
taskId | string | Task ID. |
taskStatus | string | Task status. |
results | FileTranscriptionResult[] | Per-file results with subtaskStatus, text, and transcription; failed items include code and message. |
usage | RecognitionUsage | undefined | Usage returned by the service. |
raw | QueryTaskResponse | Raw task query response. |