UNPKG

js-tts-wrapper

Version:

A JavaScript/TypeScript library that provides a unified API for working with multiple cloud-based Text-to-Speech (TTS) services

67 lines (66 loc) 2.58 kB
// Factory for TTS clients (browser/server compatible) import { AzureTTSClient } from "./engines/azure.js"; import { ElevenLabsTTSClient } from "./engines/elevenlabs.js"; import { EspeakWasmTTSClient } from "./engines/espeak-wasm.js"; import { EspeakTTSClient } from "./engines/espeak.js"; import { GoogleTTSClient } from "./engines/google.js"; import { OpenAITTSClient } from "./engines/openai.js"; import { PlayHTTTSClient } from "./engines/playht.js"; import { PollyTTSClient } from "./engines/polly.js"; import { SherpaOnnxWasmTTSClient } from "./engines/sherpaonnx-wasm.js"; import { SherpaOnnxTTSClient } from "./engines/sherpaonnx.js"; import { WatsonTTSClient } from "./engines/watson.js"; import { WitAITTSClient } from "./engines/witai.js"; import { SAPITTSClient } from "./engines/sapi.js"; // Import MockTTSClient for testing let MockTTSClient; try { // Dynamic import to avoid circular dependencies import("./__tests__/mock-tts-client.helper.js") .then((module) => { MockTTSClient = module.MockTTSClient; }) .catch(() => { // Ignore errors }); } catch (_e) { // Ignore errors } export function createTTSClient(engine, credentials) { switch (engine) { case "azure": return new AzureTTSClient(credentials); case "google": return new GoogleTTSClient(credentials); case "polly": return new PollyTTSClient(credentials); case "elevenlabs": return new ElevenLabsTTSClient(credentials); case "openai": return new OpenAITTSClient(credentials); case "playht": return new PlayHTTTSClient(credentials); case "watson": return new WatsonTTSClient(credentials); case "witai": return new WitAITTSClient(credentials); case "sherpaonnx": return new SherpaOnnxTTSClient(credentials); case "sherpaonnx-wasm": return new SherpaOnnxWasmTTSClient(credentials); case "espeak": return new EspeakTTSClient(credentials); case "espeak-wasm": return new EspeakWasmTTSClient(credentials); case "sapi": return new SAPITTSClient(credentials); case "mock": if (MockTTSClient) { return new MockTTSClient(); } throw new Error("MockTTSClient is not available. This is only available in development/testing environments."); default: throw new Error(`Engine '${engine}' is not supported in the factory.`); } }