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

91 lines (90 loc) 2.72 kB
import { AbstractTTSClient } from "../core/abstract-tts"; import type { SpeakOptions, TTSCredentials, UnifiedVoice } from "../types"; /** * SAPI TTS Client Credentials */ export interface SAPITTSCredentials extends TTSCredentials { } /** * SAPI TTS Client for Windows environments * * This client uses Windows Speech API (SAPI) through PowerShell to provide: * - High-quality Windows TTS synthesis * - SSML support * - Rich voice metadata * - Word boundary events * - Rate, pitch, and volume controls */ export declare class SAPITTSClient extends AbstractTTSClient { private static readonly TEMP_PREFIX; constructor(credentials?: SAPITTSCredentials); /** * Validate that we're running on Windows with PowerShell available */ private validateEnvironment; /** * SAPI does not require credentials but we validate the environment */ checkCredentials(): Promise<boolean>; /** * Get available SAPI voices with rich metadata */ getVoices(): Promise<UnifiedVoice[]>; /** * Get raw voices from SAPI */ protected _getVoices(): Promise<UnifiedVoice[]>; /** * Run a PowerShell script and return the output */ private runPowerShellScript; /** * Convert culture code to ISO 639-3 language code */ private convertCultureToISO639; /** * Synthesize text to audio bytes using SAPI */ synthToBytes(text: string, options?: SpeakOptions): Promise<Uint8Array>; /** * Synthesize text to a byte stream with word boundaries */ synthToBytestream(text: string, options?: SpeakOptions): Promise<{ audioStream: ReadableStream<Uint8Array>; wordBoundaries: Array<{ text: string; offset: number; duration: number; }>; }>; /** * Convert rate option to SAPI rate format * @param rate Rate option (string or number) * @returns Rate value for SAPI (-10 to 10) */ private convertRate; /** * Convert volume option to SAPI volume format * @param volume Volume option (string or number) * @returns Volume value for SAPI (0 to 100) */ private convertVolume; /** * Escape a string for use in PowerShell * @param str String to escape * @returns Escaped string */ private escapePowerShellString; /** * Strip SSML tags from text (fallback for plain text processing) * @param text Text with SSML tags * @returns Plain text without SSML tags */ private stripSSML; /** * Ensure SSML has proper format for SAPI * @param text SSML text * @returns Properly formatted SSML */ private ensureProperSSML; }