0.0.14 • Published 9 months ago

@echristian/edge-tts v0.0.14

Weekly downloads
-
License
-
Repository
-
Last release
9 months ago

Edge TTS

A TypeScript library for generating speech using Microsoft Edge's text-to-speech API

Generate speech from text using Microsoft Edge's text-to-speech service. This library provides access to Edge's TTS capabilities with subtitle generation support and voice customization options.

Installation

npm install @echristian/edge-tts

Usage

import { synthesize, synthesizeStream } from "@echristian/edge-tts";

// Basic usage with synthesize()
const { audio, subtitle } = await synthesize({
  text: "Hello, world!",
});

// Stream processing usage
const generator = synthesizeStream({ text: "Hello world" });
for await (const chunk of generator) {
  // chunk is a Uint8Array of raw audio data
  // Process or save each chunk as needed
}

// Collecting all streamed chunks
const chunks: Uint8Array[] = [];
for await (const chunk of synthesizeStream({ text: "Hello world" })) {
  chunks.push(chunk);
}

API

synthesize(options): Promise

Main function to generate speech from text.

synthesizeStream(options): AsyncGenerator

Creates an async generator that yields chunks of processed audio data. Each chunk has metadata headers automatically removed.

Uses the same options as synthesize(), but without subtitle support:

OptionTypeDefaultDescription
textstring(required)Text to convert to speech
voicestring"en-US-AvaNeural"Voice ID to use
languagestring"en-US"Language code
outputFormatstring"audio-24khz-96kbitrate-mono-mp3"Audio format
ratestring"default"Speaking rate
pitchstring"default"Voice pitch
volumestring"default"Audio volume

For detailed configuration options, refer to Microsoft's documentation:

Note: Some options may be limited by Microsoft Edge's service capabilities.

GenerateOptions

OptionTypeDefaultDescription
textstring(required)Text to convert to speech
voicestring"en-US-AvaNeural"Voice ID to use
languagestring"en-US"Language code
outputFormatstring"audio-24khz-96kbitrate-mono-mp3"Audio format
ratestring"default"Speaking rate
pitchstring"default"Voice pitch
volumestring"default"Audio volume
subtitleSubtitleOptions{ splitBy: "word", wordsPerCue: 10 }Subtitle options

SubtitleOptions

OptionTypeDefaultDescription
splitBy"word" | "duration""word"How to split subtitles
wordsPerCuenumber10Words per subtitle when using 'word'
durationPerCuenumber5000Duration (ms) when using 'duration'

GenerateResult

PropertyTypeDescription
audioBlobGenerated audio data
subtitleArrayGenerated subtitles

SubtitleResult

PropertyTypeDescription
textstringSubtitle text
startnumberStart time (ms)
endnumberEnd time (ms)
durationnumberDuration (ms)
0.0.14

9 months ago

0.0.13

9 months ago

0.0.12

9 months ago

0.0.11

10 months ago

0.0.10

10 months ago

0.0.9

10 months ago

0.0.8

11 months ago