Microsoft Edge TTS Python Library

7.2.8 · active · verified Sat Apr 11

edge-tts is a Python library (current version 7.2.8) that provides access to Microsoft Edge's online text-to-speech (TTS) service. It allows developers to convert text into natural-sounding speech without needing the Edge browser, Windows, or an API key, by leveraging the same cloud voices used by Edge. The library maintains an active release cadence, frequently updating to address changes in the underlying Microsoft service.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to convert a text string into an MP3 audio file using a specified voice. It uses `asyncio` for asynchronous operations, which is fundamental to how `edge-tts` works. Replace 'en-US-JennyNeural' with your desired voice; you can list all available voices using the command-line tool `edge-tts --list-voices`.

import asyncio
import edge_tts
import os

TEXT = "Hello, this is a test of the Microsoft Edge Text-to-Speech library."
VOICE = "en-US-JennyNeural" # You can list available voices with `edge-tts --list-voices`
OUTPUT_FILE = "hello.mp3"

async def main():
    print(f"Generating speech for: '{TEXT}' with voice '{VOICE}'")
    try:
        communicate = edge_tts.Communicate(text=TEXT, voice=VOICE)
        await communicate.save(OUTPUT_FILE)
        print(f"Audio saved to {OUTPUT_FILE}")
    except Exception as e:
        print(f"An error occurred: {e}")
        print("Ensure you have a stable internet connection and the voice name is correct.")

if __name__ == "__main__":
    asyncio.run(main())

view raw JSON →