UNPKG

volcengine-tts

Version:

适用于火山引擎模块,支持火山引擎 等 TTS 服务。

82 lines (78 loc) 2.23 kB
import { Readable } from 'stream'; interface VolcanoConfig { appId: string; accessToken: string; userId?: string; encoding?: "wav" | "pcm" | "ogg_opus" | "mp3"; } interface EdgeConfig { trustedToken: string; } interface OpenAIConfig { apiKey: string; model?: string; baseUrl?: string; } interface TTSConfig { /** * 默认音色 * * 当指定的音色不存在时,会 fallback 到默认音色 */ defaultSpeaker?: string; volcano?: VolcanoConfig; edge?: EdgeConfig; openai?: OpenAIConfig; } type TTSBuilder = (options: TTSConfig & { stream?: Readable; text: string; speaker: string; }) => Promise<Uint8Array | null>; interface CustomTextProcessorParams { text: string; outputStream: Readable; tts: (options: TTSOptions) => Promise<Uint8Array | null>; options: TTSOptions; } interface TTSOptions extends TTSConfig { stream?: Readable; text?: string; speaker?: string; protocol?: "default" | "websocket"; operation?: "submit" | "query"; signal?: AbortSignal; textFilter?: (text: string) => string; customTextProcessor?: (params: CustomTextProcessorParams) => Promise<void>; audioReplacements?: any; audioBasePath?: string; } interface TTSSpeaker { /** * 音色名称 */ name?: string; /** * 音色性别分类,男女(可选) */ gender?: string; /** * 音色标识 */ speaker: string; } interface TTSProvider { name: string; speakers: TTSSpeaker[]; tts: TTSBuilder; } /** * 此处注册 TTS 服务提供商 */ declare const kTTSProviders: TTSProvider[]; declare const kTTSSpeakers: TTSSpeaker[]; declare function tts(options: TTSOptions): Promise<Uint8Array<ArrayBufferLike> | null>; declare function createTTS(config: TTSConfig): (options: TTSOptions) => Promise<Uint8Array<ArrayBufferLike> | null>; declare function tts2(options: TTSOptions): Promise<Uint8Array<ArrayBufferLike> | null>; declare function createTTS2(config: TTSConfig): (options: TTSOptions) => Promise<Uint8Array<ArrayBufferLike> | null>; export { type TTSConfig, type TTSOptions, createTTS, createTTS2, kTTSProviders, kTTSSpeakers, tts, tts2 };