UNPKG

gpt-sovits-sdk

Version:

Node.js SDK for GPT-SoVITS API

437 lines (436 loc) 7.52 kB
/** * GPT-SoVITS SDK 类型定义 */ /** * SDK客户端配置选项 */ export interface GPTSoVITSClientOptions { /** * API基础URL,默认为http://127.0.0.1:9880 */ baseUrl?: string; /** * 请求超时时间(毫秒),默认为30000 */ timeout?: number; /** * 是否在控制台输出调试信息 */ debug?: boolean; /** * 自定义请求头 */ headers?: Record<string, string>; /** * 请求失败时的重试次数,默认为0 */ retries?: number; } /** * 文本语言类型 */ export declare enum TextLanguage { CHINESE = "zh", ENGLISH = "en", JAPANESE = "ja" } /** * 媒体类型 */ export declare enum MediaType { WAV = "wav", MP3 = "mp3", OGG = "ogg", RAW = "raw", AAC = "aac" } /** * 文本分割方法 */ export declare enum TextSplitMethod { CUT0 = "cut0", CUT1 = "cut1", CUT2 = "cut2", CUT3 = "cut3", CUT4 = "cut4", CUT5 = "cut5" } /** * TTS请求参数 */ export interface TTSRequestOptions { /** * 要合成的文本 */ text: string; /** * 文本语言,如 "zh", "en", "ja" */ textLang: TextLanguage | string; text_lang?: TextLanguage | string; /** * 参考音频路径或ID */ refAudioPath: string; ref_audio_path?: string; /** * 提示文本的语言 */ promptLang: TextLanguage | string; prompt_lang?: TextLanguage | string; /** * 参考音频的提示文本 */ promptText?: string; prompt_text?: string; /** * 辅助参考音频路径列表 */ auxRefAudioPaths?: string[]; aux_ref_audio_paths?: string[]; /** * GPT模型路径 */ gptModel?: string; gpt_model?: string; /** * SoVITS模型路径 */ sovitsModel?: string; sovits_model?: string; /** * Top-k采样,默认5 */ topK?: number; top_k?: number; /** * Top-p采样,默认1.0 */ topP?: number; top_p?: number; /** * 采样温度,默认1.0 */ temperature?: number; /** * 文本分割方法,默认"cut5" */ textSplitMethod?: TextSplitMethod | string; text_split_method?: TextSplitMethod | string; /** * 批处理大小,默认1 */ batchSize?: number; batch_size?: number; /** * 批处理分割阈值,默认0.75 */ batchThreshold?: number; batch_threshold?: number; /** * 是否将批处理分割为多个桶,默认true */ splitBucket?: boolean; split_bucket?: boolean; /** * 控制合成音频的速度,默认1.0 */ speedFactor?: number; speed_factor?: number; /** * 控制音频片段的间隔,默认0.3 */ fragmentInterval?: number; fragment_interval?: number; /** * 随机种子,默认-1 */ seed?: number; /** * 是否使用并行推理,默认true */ parallelInfer?: boolean; parallel_infer?: boolean; /** * T2S模型的重复惩罚,默认1.35 */ repetitionPenalty?: number; repetition_penalty?: number; /** * 输出媒体类型,可选值: "wav", "mp3", "ogg", "raw", "aac",默认"wav" */ mediaType?: MediaType | string; media_type?: MediaType | string; /** * 是否返回流式响应,默认false */ streamingMode?: boolean; streaming_mode?: boolean; } /** * TTS响应数据 */ export interface TTSResponse { /** * 生成的音频文件路径 */ audio_path: string; /** * 音频时长(秒) */ duration: number; /** * 媒体类型 */ media_type: string; } /** * 模型信息 */ export interface ModelInfo { /** * 模型名称 */ name: string; /** * 模型路径 */ path: string; /** * 模型类型 */ type: "gpt" | "sovits"; /** * 模型大小(字节) */ size?: number; /** * 最后修改时间 */ last_modified?: string; } /** * 模型列表响应 */ export interface ModelsResponse { /** * GPT模型列表 */ gpt_models: ModelInfo[]; /** * SoVITS模型列表 */ sovits_models: ModelInfo[]; } /** * 音频信息 */ export interface AudioInfo { /** * 音频ID */ id: string; /** * 音频名称 */ name: string; /** * 音频路径 */ path: string; /** * 完整路径 */ full_path: string; /** * 音频大小(字节) */ size?: number; /** * 音频时长(秒) */ duration?: number; /** * 提示文本 */ prompt_text?: string; /** * 角色名称(对于情感音频) */ character?: string; /** * 语言(对于情感音频) */ language?: string; /** * 情感类型(对于情感音频) */ emotion?: string; } /** * 参考音频列表响应 */ export interface ReferenceAudiosResponse { /** * 音频列表 */ audios: AudioInfo[]; /** * 子目录列表 */ directories?: string[]; } /** * 情感音频查询选项 */ export interface EmotionAudiosQueryOptions { /** * 角色名称 */ character?: string; /** * 语言 */ language?: string; /** * 情感类型 */ emotion?: string; } /** * 情感音频列表响应 */ export interface EmotionAudiosResponse { /** * 参考音频列表 */ referenceAudios: AudioInfo[]; /** * 可用角色列表 */ characters: string[]; /** * 可用语言列表 */ languages: string[]; /** * 可用情感类型列表 */ emotions: string[]; } /** * 设置模型请求 */ export interface SetModelRequest { /** * 模型路径 */ modelPath: string; } /** * API响应基础接口 */ export interface APIResponse<T = any> { /** * 状态码 */ code?: number; /** * 状态消息 */ message?: string; /** * 响应数据 */ data?: T; /** * 是否成功 */ success?: boolean; } /** * API错误响应 */ export interface APIErrorResponse { /** * 错误码 */ code: number; /** * 错误类型 */ error: string; /** * 错误消息 */ message: string; /** * 详细信息 */ detail?: any; } /** * SDK错误类 */ export declare class GPTSoVITSError extends Error { /** * 错误码 */ code?: number; /** * 原始错误 */ cause?: any; /** * 请求URL */ url?: string; /** * 请求方法 */ method?: string; constructor(message: string, options?: { code?: number; cause?: any; url?: string; method?: string; }); } /** * 健康检查响应 */ export interface HealthResponse { /** * 状态 */ status: string; /** * 版本 */ version: string; /** * 模型是否已加载 */ models_loaded: boolean; } /** * 根端点响应 */ export interface RootResponse { /** * 欢迎消息 */ message: string; /** * 版本 */ version: string; /** * 文档URL */ docs_url: string; /** * ReDoc URL */ redoc_url: string; }