All files / modules/tts provider.interface.ts

0% Statements 0/0
0% Branches 1/1
0% Functions 1/1
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70                                                                                                                                           
/**
 * TTS Provider 统一接口
 * 
 * 所有语音合成供应商必须实现此接口。
 * synthesize 方法签名统一为 (text, voice, params, outputPath),返回本地文件路径或 cloud:URL。
 */
 
import { VoiceParams } from '../../types';
 
/** TTS 模型配置(来自 models.json 中 input 含 'tts' 的模型条目) */
export interface TtsModelConfig {
  /** 模型 ID(如 'speech-2.8-hd', 'qwen3-tts-instruct-flash') */
  id: string;
  /** 模型显示名 */
  name: string;
  /** API 路径(如 '/t2a_async_v2'),可选 */
  apiPath?: string;
  /** 是否启用 */
  enabled: boolean;
}
 
export interface ITtsProvider {
  /** Provider 唯一标识(如 'minimax-tts', 'bailian-tts') */
  readonly name: string;
  /** 所属供应商 key(与 models.json 中 vendors 的 key 对应,如 'minimax', 'bailian') */
  readonly vendor: string;
  /** 合成模式:'async' 异步轮询 | 'sync' 同步返回 | 'stream' 流式 | 'mock' 模拟 */
  readonly mode: 'async' | 'sync' | 'stream' | 'mock';
  /** 单次调用最大文本长度(字符),超过会触发分段 */
  readonly maxTextLength: number;
  /** 并发上限(1 = 串行, 2+ = 并行) */
  readonly concurrency: number;
  /** 默认 TTS 模型 ID(从 models.json 读取) */
  readonly modelId: string;
  /** TTS API 基础路径(从 models.json vendor 的 ttsApiPath 读取) */
  readonly ttsApiPath: string;
 
  /**
   * 语音合成
   * @param text       要合成的文本
   * @param voice      音色标识(如 'Cherry', 'audiobook_male_1')
   * @param params     语音参数(语速、音调、音量)
   * @param outputPath 输出文件路径(.mp3)
   * @returns          返回本地文件路径(如 '/path/to/output.mp3')
   *                   或云端 URL 标记(如 'cloud:https://...')
   */
  synthesize(
    text: string,
    voice: string,
    params: VoiceParams,
    outputPath: string,
  ): Promise<string>;
 
  /** 
   * 健康检查(可选)
   * @returns true = Provider 可用,false = 不可用
   */
  healthCheck?(): Promise<boolean>;
}
 
/** TTS 合成结果 */
export interface SynthesizeResult {
  /** 本地文件路径 或 云端URL */
  path: string;
  /** 是否来自云端(需下载) */
  isCloud: boolean;
  /** 所属 Provider */
  provider: string;
}