Un client basé sur TypeScript pour interagir avec l'API Text-to-Speech (TTS) de Microsoft Edge. Ce package est compatible avec les environnements Node.js et Browser , ce qui le rend polyvalent pour divers cas d'utilisation.
https://www.npmjs.com/package/edge-tts-client
Pour installer le package, exécutez:
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 classe principale pour interagir avec Edge TTS.
setMetadata(voiceName: string, outputFormat: OUTPUT_FORMAT, voiceLocale?: string): Promise<void>
toStream(input: string, options?: ProsodyOptions): EventEmitter
close(): void
ProsodyOptionsDéfinit les options de prosodie pour la synthèse SSML:
pitch : Pitch of the Voice (par exemple, 'medium' , 'high' ).rate : vitesse de la parole (par exemple, 1.0 , 1.2 ).volume : volume de l'audio (par exemple, 90 , 'loud' ).OUTPUT_FORMATUne enum définissant les formats de sortie disponibles, tels que:
AUDIO_24KHZ_48KBITRATE_MONO_MP3WEBM_24KHZ_16BIT_MONO_OPUS Pour construire le projet, exécutez:
npm run buildPour exécuter des tests avec Veest:
npm run test Les contributions sont les bienvenues! Veuillez ouvrir un problème ou soumettre une demande de traction pour toute modification ou amélioration.