Edge TTS for Node.js

1.2.10 · active · verified Sun Apr 19

node-edge-tts is a Node.js module providing an interface to Microsoft Edge's free online Text-to-Speech (TTS) service. Currently at version 1.2.10, this library allows developers to convert text into speech without needing an API key, relying on the public Edge TTS endpoint. It offers both a programmatic API for integrating TTS into Node.js applications and a command-line interface for quick conversions. Key features include configurable voices, languages, output formats, and the ability to save detailed subtitles alongside the audio. Unlike cloud-based TTS solutions that often require authentication and consumption-based billing, node-edge-tts leverages a readily available service, making it suitable for projects requiring an accessible and free text-to-speech option, though with potential limitations inherited from the underlying Edge service regarding supported speech configurations. The project appears to be actively maintained, with regular updates indicated by its current version number.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to instantiate EdgeTTS, configure it with a voice and output format, and generate an audio file with corresponding subtitles.

import { EdgeTTS } from 'node-edge-tts';
import * as path from 'path';
import * as fs from 'fs';

async function generateSpeech() {
  const outputDir = './audio_output';
  if (!fs.existsSync(outputDir)) {
    fs.mkdirSync(outputDir, { recursive: true });
  }
  const audioFilePath = path.join(outputDir, 'hello_world.mp3');

  const tts = new EdgeTTS({
    voice: 'en-US-AriaNeural',
    lang: 'en-US',
    outputFormat: 'audio-24khz-96kbitrate-mono-mp3',
    saveSubtitles: true,
    // proxy: 'http://localhost:7890', // Uncomment and configure if behind a proxy
    // timeout: 15000 // Increase timeout if network is slow
  });

  try {
    console.log(`Generating speech to ${audioFilePath}...`);
    await tts.ttsPromise('Hello world, this is a test from node-edge-tts!', audioFilePath);
    console.log('Speech generated successfully!');
    console.log(`Subtitles saved to ${audioFilePath.replace('.mp3', '.json')}`);
  } catch (error) {
    console.error('Failed to generate speech:', error);
  }
}

generateSpeech();

view raw JSON →