edge tts client
1.0.2
一个基于打字稿的客户端,用于与Microsoft Edge的文本到语音(TTS)API进行交互。该软件包与Node.js和浏览器环境均兼容,使其在各种用例中具有多功能性。
https://www.npmjs.com/package/edge-tts-client
要安装软件包,请运行:
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.' ) ;
} ) ; EdgeTTSClient与边缘TT交互的主要类。
setMetadata(voiceName: string, outputFormat: OUTPUT_FORMAT, voiceLocale?: string): Promise<void>
toStream(input: string, options?: ProsodyOptions): EventEmitter
close(): void
ProsodyOptions定义SSML合成的韵律选项:
pitch :声音的音调(例如, 'medium' , 'high' )。rate :语音速度(例如, 1.0 ) 1.2volume :音频的音量(例如, 90 , 'loud' )。OUTPUT_FORMAT定义可用输出格式的枚举,例如:
AUDIO_24KHZ_48KBITRATE_MONO_MP3WEBM_24KHZ_16BIT_MONO_OPUS 要构建项目,请运行:
npm run build用vitest进行测试:
npm run test 欢迎捐款!请打开问题或提交任何更改或改进的拉请请求。