Qwen-Audio-ASR-Filetrans Node.js SDK

Updated at:

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:

npm install ./dashscope-sdk-nodejs-0.1.0.tgz

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.

import { TranscriptionClient } from 'dashscope-sdk-nodejs/asr'

const client = new TranscriptionClient({
  apiKey: process.env.DASHSCOPE_API_KEY,
  workspaceId: process.env.DASHSCOPE_WORKSPACE_ID,
  baseUrl: 'dashscope.aliyuncs.com',
  model: 'qwen-audio-3.1-asr-flash-filetrans',
})
const job = await client.transcribe(
  'https://dashscope.oss-cn-beijing.aliyuncs.com/audios/welcome.mp3',
)
for (const result of job.results) {
  if (result.subtaskStatus === 'SUCCEEDED') {
    console.log('Transcript:', result.text)
  } else {
    console.error(result.code, result.message)
    process.exitCode = 1
  }
}

API reference

Constructor options

Constructor options for TranscriptionClient:

Parameter

Type

Required

Description

apiKey

string

No

API key. Defaults to DASHSCOPE_API_KEY.

workspaceId

string

No

Workspace ID. Defaults to DASHSCOPE_WORKSPACE_ID.

baseUrl

string

No

Service hostname. Default: dashscope.aliyuncs.com (Beijing).

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.