TTS_SAMPLE_RATE (src/tts.ts)

builderbot · packages/provider-voice-sip/src/tts.ts · typescript · MIT
voice, Voice / Speech

OpenAI TTS synthesis helper returning PCM buffer for LiveKit.

// Source: https://github.com/codigoencasa/builderbot | License: MIT | Copyright 2022 Leifer Mendez
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * LAYER: Infrastructure
 * Contains: Tts, SynthesizeOptions
 * Rules: Implements ports from Application. Can use any framework.
 * BigO: O(1) score:5
 * keywords: [Tts, SynthesizeOptions]
 * GOAL: Own the "tts" concern of the provider-voice-sip package.
 */
import OpenAI from 'openai'

/** Sample rate of OpenAI TTS PCM output (24 kHz, 16-bit, mono). */
export const TTS_SAMPLE_RATE = 24000

export interface SynthesizeOptions {
    /** OpenAI TTS model. Default 'gpt-4o-mini-tts'. */
    model?: string
    /** Voice name. Default 'alloy'. */
    voice?: string
}

/**
 * Synthesize speech from text using OpenAI TTS, returning 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key