Skip to main content

Gladia

Gladia provides speech-to-text (STT) only. The Mastra integration uploads prerecorded audio, waits for Gladia to finish transcribing it, and returns the combined transcript as a string.

Installation
Direct link to Installation

npm install @mastra/voice-gladia@latest

API key
Direct link to API key

Set GLADIA_API_KEY or pass the key through listeningModel.apiKey. The constructor throws GLADIA_API_KEY is not set. when neither value is available.

Usage example
Direct link to Usage example

Set GLADIA_API_KEY to use the default configuration:

import { createReadStream } from 'node:fs'
import { GladiaVoice } from '@mastra/voice-gladia'

const voice = new GladiaVoice()
const audio = createReadStream('./audio.m4a')

const transcript = await voice.listen(audio, {
fileName: 'audio.m4a',
mimeType: 'audio/mp4',
options: {
diarization: true,
detect_language: true,
},
})

You can also pass the API key directly:

import { GladiaVoice } from '@mastra/voice-gladia'

const voice = new GladiaVoice({
listeningModel: {
apiKey: process.env.GLADIA_API_KEY,
},
})

Constructor parameters
Direct link to Constructor parameters

listeningModel?:

GladiaConfig
Configuration for speech-to-text.
GladiaConfig

apiKey?:

string
Gladia API key. Falls back to the GLADIA_API_KEY environment variable.

Methods
Direct link to Methods

listen()
Direct link to listen

Uploads prerecorded audio and returns the full transcript.

audioStream:

NodeJS.ReadableStream
Audio stream to transcribe. The stream is buffered before it is uploaded.

mimeType:

string
MIME type of the audio file. The method throws an error if this value is missing.

fileName:

string
Name of the uploaded audio file. The method throws an error if this value is missing.

options?:

GladiaListenOptions
Options for the prerecorded transcription job.
GladiaListenOptions

diarization?:

boolean
Whether to identify different speakers in the recording.

diarization_config?:

object
Speaker-count settings for diarization.
object

number_of_speakers?:

number
Exact number of speakers in the recording.

min_speakers?:

number
Minimum number of speakers to detect.

max_speakers?:

number
Maximum number of speakers to detect.

translation?:

boolean
Whether to translate the transcript.

translation_config?:

object
Translation model and target languages.
object

model?:

'base' | 'enhanced'
Translation model to use.

target_languages?:

string[]
Languages to translate the transcript into.

detect_language?:

boolean
Whether to detect the spoken language automatically.

enable_code_switching?:

boolean
Whether to detect multiple languages within the recording.

Returns: Promise<string> containing the full transcript.

speak()
Direct link to speak

Gladia doesn't support text-to-speech. Calling this method throws Gladia does not support text-to-speech.

Important notes
Direct link to Important notes

  • Gladia processes prerecorded audio through an upload and transcription job. It doesn't provide streaming transcription through this package.
  • The input stream is fully buffered before upload.
  • listen() returns only full_transcript. It doesn't return per-speaker segments or other response metadata.
  • The integration polls once per second until the job finishes or fails. It doesn't set a polling timeout.
  • A Gladia API key is required.