@gladiaio/sdk

中文文档
2.2.1发布于 2026/10/23MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 3.4万

Gladia JavaScript/TypeScript SDK

原始使用文档
文档目录12 节
  1. Requirements
  2. Installation
  3. Usage
  4. Node.js / Browser (ESM)
  5. Node.js (CommonJS)
  6. Browser (script tag)
  7. Pre-recorded transcription
  8. Async pre-recorded
  9. Live transcription
  10. Waiting for the session to finish
  11. Documentation
  12. License

Gladia JavaScript SDK

A TypeScript/JavaScript SDK for the Gladia API.

Requirements

For non-browser environment, you need either Node.js 20+ or Bun .

Installation

npm install @gladiaio/sdk

If you are using Node.js < 22, you also need to install the ws package:

npm install ws

Usage

Import GladiaClient and create an instance.

Provide an API key with apiKey or the GLADIA_API_KEY environment variable. Get your API key here in under a minute.

You can also set GLADIA_API_URL. For live sessions, GLADIA_REGION (eu-west / us-west) is passed only on session creation (POST /v2/live).

Node.js / Browser (ESM)

import { GladiaClient } from '@gladiaio/sdk'

const gladiaClient = new GladiaClient({
  apiKey: 'your-api-key',
})

Node.js (CommonJS)

const { GladiaClient } = require('@gladiaio/sdk')

const gladiaClient = new GladiaClient({
  apiKey: 'your-api-key',
})

Browser (script tag)

<script src="https://unpkg.com/@gladiaio/sdk"></script>

<script>
  const gladiaClient = new Gladia.GladiaClient({
    apiKey: 'your-api-key',
  })
</script>

Pre-recorded transcription

transcribe() accepts a file path (Node), http(s) URL, File, or Blob. It uploads when needed, then polls until the job completes.

import { GladiaClient } from '@gladiaio/sdk'
import 'dotenv/config'

const gladiaClient = new GladiaClient()
const audioPath = '../data/online-meeting-example.mp4'

const result = await gladiaClient.preRecorded().transcribe(audioPath, {
  language_config: { languages: ['en'] },
})

console.log(result.result?.transcription?.full_transcript ?? '')

See all supported languages here !

Pass the options argument to enable features from Audio intelligence such as diarization, translation, PII redaction, and much more.

Async pre-recorded

If your runtime has no top-level await, wrap calls in an async function:

async function main() {
  const gladiaClient = new GladiaClient()
  const result = await gladiaClient.preRecorded().transcribe('./audio.mp3')
  console.log(result.result?.transcription?.full_transcript ?? '')
}

main().catch(console.error)

Live transcription

const liveSession = gladiaClient.liveV2().startSession({
  model: 'solaria-1',
  encoding: 'wav/pcm',
  sample_rate: 16000,
  bit_depth: 16,
  channels: 1,
  language_config: {
    languages: ['en'],
  },
  messages_config: {
    receive_partial_transcripts: true,
  },
})

liveSession.on('message', (message) => {
  if (message.type === 'transcript') {
    console.log(`${message.data.is_final ? 'F' : 'P'} | ${message.data.utterance.text.trim()}`)
  }
})

liveSession.once('started', () => {
  console.log(`Session ${liveSession.sessionId} started`)
})

liveSession.on('error', (err) => {
  console.error('An error occurred during live session:', err)
})

liveSession.once('ended', () => {
  console.log(`Session ${liveSession.sessionId} ended`)
})

liveSession.sendAudio(/* <audio_chunk> */)
liveSession.stopRecording()

See all the supported languages here !

Pass the options argument to enable features from Audio intelligence such as diarization, translation, PII redaction, and much more.

Waiting for the session to finish

To await shutdown after stopRecording(), wait on the ended event:

import { GladiaClient } from '@gladiaio/sdk'

async function runLive() {
  const gladiaClient = new GladiaClient({ apiKey: 'your-api-key' })
  const liveSession = gladiaClient.liveV2().startSession({
    language_config: { languages: ['en'] },
  })

  const ended = new Promise<void>((resolve) => {
    liveSession.once('ended', () => resolve())
  })

  liveSession.stopRecording()
  await ended
}

runLive().catch(console.error)

When you need the session id as soon as the backend has created the session:

const sessionId = await liveSession.getSessionId()

Documentation

License

MIT

版本与发布记录

@gladiaio/sdk 共发布 110 个版本,首次发布于 2025/09/09;过去 12 个月发布了 11 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.2.1latest2026/10/2324 天前
2.2.02026/10/131 个月前
2.1.02026/09/211 个月前
2.0.02026/09/102 个月前
1.1.02026/07/243 个月前
1.0.72026/06/304 个月前

关于 @gladiaio/sdk 的常见问题

@gladiaio/sdk 是什么?

Gladia JavaScript/TypeScript SDK

如何安装 @gladiaio/sdk?

在项目目录运行 npm install @gladiaio/sdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:eventemitter3(>=5)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@gladiaio/sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@gladiaio/sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@gladiaio/sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@gladiaio/sdk 可以商用吗?

@gladiaio/sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gladiaio/sdk 的下载量有多少?

根据 npm 官方下载统计,@gladiaio/sdk 在 2026/10/17 – 2026/11/15 这 30 天内被下载 33,868 次,日均约 1,129 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gladiaio/sdk 还在维护吗?

最新版本 2.2.1 发布于 2026/10/23(24 天前);至今共发布 110 个版本,其中过去 12 个月发布了 11 个;首次发布于 2025/09/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。