Skip to main content

Gradium

Gradium STT and TTS implementation for @micdrop/server.

This package provides high-quality real-time speech-to-text and text-to-speech implementations using Gradium's WebSocket streaming API.

Installation​

npm install @micdrop/gradium

Gradium STT (Speech-to-Text)​

Usage​

import { GradiumSTT } from '@micdrop/gradium'
import { MicdropServer } from '@micdrop/server'

const stt = new GradiumSTT({
apiKey: process.env.GRADIUM_API_KEY || '',
modelName: 'default', // Optional: model name
inputFormat: 'pcm_16000', // Optional: audio format
language: 'en', // Optional: language hint
region: 'eu', // Optional: 'eu' or 'us'
})

// Use with MicdropServer
new MicdropServer(socket, {
stt,
// ... other options
})

Options​

OptionTypeDefaultDescription
apiKeystringRequiredYour Gradium API key
modelNamestring'default'Model name to use for transcription
inputFormatGradiumInputFormat'pcm_16000'Audio input format of the incoming stream
languagestringOptionalLanguage hint (shortcut for jsonConfig.language)
region'eu' | 'us''eu'API region (EU or US endpoint)
jsonConfigGradiumASRJsonConfigOptionalAdvanced transcription configuration
connectionTimeoutnumber5000Timeout in milliseconds for WebSocket connection
transcriptionTimeoutnumber4000Timeout in milliseconds to wait for transcription
retryDelaynumber1000Delay in milliseconds between reconnection attempts
maxRetrynumber3Maximum number of reconnection attempts before failing

Advanced Transcription Configuration​

The jsonConfig option allows you to fine-tune the transcription:

const stt = new GradiumSTT({
apiKey: 'your-api-key',
jsonConfig: {
language: 'en', // Language hint
target_language: 'fr', // Optional: translation target language
delay_in_frames: 16, // 0 to 80, each frame = 80ms
},
})

Gradium TTS (Text-to-Speech)​

Usage​

import { GradiumTTS } from '@micdrop/gradium'
import { MicdropServer } from '@micdrop/server'

const tts = new GradiumTTS({
apiKey: process.env.GRADIUM_API_KEY || '',
voiceId: 'YTpq7expH9539ERJ', // Gradium voice ID
modelName: 'default', // Optional: model name
outputFormat: 'pcm_16000', // Optional: audio format
region: 'eu', // Optional: 'eu' or 'us'
})

// Use with MicdropServer
new MicdropServer(socket, {
tts,
// ... other options
})

Options​

OptionTypeDefaultDescription
apiKeystringRequiredYour Gradium API key
voiceIdstringRequiredGradium voice ID
modelNamestring'default'Model name to use for speech synthesis
outputFormatGradiumOutputFormat'pcm_16000'Audio output format
region'eu' | 'us''eu'API region (EU or US endpoint)
jsonConfigGradiumJsonConfigOptionalAdvanced voice configuration
connectionTimeoutnumber5000Timeout in milliseconds for WebSocket connection
retryDelaynumber1000Delay in milliseconds between reconnection attempts
maxRetrynumber3Maximum number of reconnection attempts before failing

Output Formats​

FormatDescription
pcmPCM 48kHz, 16-bit signed integer mono
pcm_16000PCM 16kHz, 16-bit signed integer mono
pcm_24000PCM 24kHz, 16-bit signed integer mono
pcm_8000PCM 8kHz, 16-bit signed integer mono
wavWAV format
opusOpus codec wrapped in an Ogg container
ulaw_8000u-law 8kHz
alaw_8000A-law 8kHz

Advanced Voice Configuration​

The jsonConfig option allows you to fine-tune voice characteristics:

const tts = new GradiumTTS({
apiKey: 'your-api-key',
voiceId: 'your-voice-id',
jsonConfig: {
temp: 0.7, // Temperature: 0 to 1.4 (default: 0.7)
cfg_coef: 2.0, // Voice similarity: 1.0 to 4.0 (default: 2.0)
padding_bonus: 0, // Speed control: -4.0 to 4.0
},
})
ParameterTypeRangeDefaultDescription
tempnumber0 - 1.40.7Controls randomness in speech generation
cfg_coefnumber1.0 - 4.02.0Controls similarity to the original voice
padding_bonusnumber-4.0 - 4.00Controls speech speed

Getting Started​

  1. Sign up for a Gradium account and get your API key
  2. Choose a voice ID from the Gradium voice library
  3. Install the package and configure with your credentials
import { GradiumTTS } from '@micdrop/gradium'

const tts = new GradiumTTS({
apiKey: 'your-gradium-api-key',
voiceId: 'your-voice-id',
region: 'eu', // Use 'us' for US endpoint
outputFormat: 'pcm_16000',
})

// Use with MicdropServer
new MicdropServer(socket, {
tts,
// ... other options
})