Un cliente basado en TypeScript para interactuar con la API de texto a voz (TTS) de Microsoft Edge. Este paquete es compatible con los entornos de nodo.js y el navegador , lo que lo hace versátil para varios casos de uso.
https://www.npmjs.com/package/edge-tts-client
Para instalar el paquete, ejecute:
npm install edge-tts-client import { EdgeTTSClient , ProsodyOptions , OUTPUT_FORMAT } from 'edge-tts-client' ;
// Initialize the client
const ttsClient = new EdgeTTSClient ( ) ;
// Set metadata for synthesis
await ttsClient . setMetadata ( 'en-US-GuyNeural' , OUTPUT_FORMAT . AUDIO_24KHZ_48KBITRATE_MONO_MP3 ) ;
// Define SSML options
const options = new ProsodyOptions ( ) ;
options . pitch = 'medium' ;
options . rate = 1.2 ;
options . volume = 90 ;
// Synthesize text to a stream
const stream = ttsClient . toStream ( 'Hello, world!' , options ) ;
// Handle the audio stream
stream . on ( 'data' , ( audioChunk ) => {
console . log ( 'Received audio chunk:' , audioChunk ) ;
} ) ;
stream . on ( 'end' , ( ) => {
console . log ( 'Synthesis complete.' ) ;
} ) ; EdgeTTSClientLa clase principal para interactuar con el borde TTS.
setMetadata(voiceName: string, outputFormat: OUTPUT_FORMAT, voiceLocale?: string): Promise<void>
toStream(input: string, options?: ProsodyOptions): EventEmitter
close(): void
ProsodyOptionsDefine las opciones de prosodia para la síntesis de SSML:
pitch : Pitch of the Voice (por ejemplo, 'medium' , 'high' ).rate : velocidad del discurso (por ejemplo, 1.0 , 1.2 ).volume : Volumen del audio (por ejemplo, 90 , 'loud' ).OUTPUT_FORMATUn enum que define los formatos de salida disponibles, como:
AUDIO_24KHZ_48KBITRATE_MONO_MP3WEBM_24KHZ_16BIT_MONO_OPUS Para construir el proyecto, ejecute:
npm run buildPara ejecutar pruebas con Vitest:
npm run test ¡Las contribuciones son bienvenidas! Abra un problema o envíe una solicitud de extracción de cambios o mejoras.