Edge TTS API with Word-by-Word Subtitles

This project provides a REST API for Microsoft Edge's text-to-speech service with word-by-word subtitle generation and highlighting capabilities.

Features

  • Text-to-speech conversion using Microsoft Edge TTS
  • Word-by-word subtitle generation in SRT format
  • Audio file generation
  • Multiple voice support
  • RESTful API interface

Requirements

  • Python 3.7+
  • edge-tts library
  • Flask

Installation

  1. Clone this repository
  2. Install the required packages:
    pip install -r requirements.txt
    

Usage

  1. Start the Flask server:

    python app.py
    
  2. The API will be available at http://localhost:7860

API Endpoints

Convert Text to Speech with Subtitles

POST /tts

Convert text to speech with word-by-word subtitles.

Request Body:

{
  "text": "Text to convert to speech",
  "voice": "en-US-JennyNeural"  // Optional, defaults to en-US-JennyNeural
}

Response:

{
  "audio": "base64_encoded_audio_data",
  "subtitles": "SRT formatted subtitles",
  "format": "mp3"
}

Get Audio File Only

GET /tts/audio/<text>

Get only the audio file for the provided text.

Query Parameters:

  • voice (optional): Voice to use for TTS

Get Subtitles Only

GET /tts/subtitles/<text>

Get only the subtitles for the provided text.

Query Parameters:

  • voice (optional): Voice to use for TTS

List Available Voices

GET /voices

Get a list of all available voices.

Example Usage

JavaScript Example

const text = "Hello, this is a test.";
const response = await fetch('http://localhost:7860/tts', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({text: text})
});

const data = await response.json();
const audio = new Audio('data:audio/mpeg;base64,' + data.audio);
audio.play();

Deploying to Hugging Face Spaces

To deploy this API to Hugging Face Spaces:

  1. Create a new Space on Hugging Face
  2. Upload the files to your Space repository
  3. Configure the Space to use Docker
  4. The Space will automatically build and run using the provided Dockerfile
  5. The app will start automatically on port 7860

License

This project is licensed under the MIT License.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support