CoolFace
Apppublic

guilheogumucio/tts-alignment

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
App README

๐ŸŽ™๏ธ Forced Alignment Service

TRUE forced alignment using Aeneas.

Overview

This service provides word-level forced alignment between audio files and your provided text. Aeneas performs TRUE forced alignment using TTS synthesis + MFCC/DTW:

  • โ€”โœ… Uses YOUR exact text directly
  • โ€”โœ… Does NOT re-transcribe the audio
  • โ€”โœ… Aligns the words you provide with the audio timing
  • โ€”โœ… Simple setup - no complex acoustic models required

This is ideal for audiobooks where you already have the text and need accurate word-level timestamps.

Security

To enable API key authentication, set the ALIGNMENT_API_KEY environment variable:

  • โ€”When set, all alignment requests must include a valid api_key parameter
  • โ€”The health endpoint returns authEnabled: true when authentication is enabled

Technology Stack

ComponentTechnology
FrameworkPython + Gradio
AlignmentAeneas (TTS + DTW)
TTS EngineeSpeak
HostingDocker / Hugging Face

API Endpoints

POST /call/align (Gradio API)

Align audio with text to get word-level timestamps.

Request (Gradio format):

json
{
  "data": [
    "https://r2.example.com/audio.mp3",
    "Chapter One. It was the best of times...",
    "en",
    "507f1f77bcf86cd799439011",
    0,
    "your-api-key"
  ]
}
Note: The api_key (last parameter) is required if ALIGNMENT_API_KEY is configured on the server.

Response:

json
{
  "success": true,
  "metadata": {
    "engine": "aeneas",
    "ttsEngine": "espeak",
    "language": "en",
    "duration": 12.5,
    "wordCount": 42,
    "confidence": 0.9,
    "processingTime": 3.2,
    "audioId": "507f1f77bcf86cd799439011",
    "paragraphIndex": 0
  },
  "segments": [
    {
      "id": "w0",
      "word": "Chapter",
      "start": 0.5,
      "end": 1.1,
      "confidence": 0.9
    },
    { "id": "w1", "word": "One", "start": 1.15, "end": 1.8, "confidence": 0.9 }
  ]
}

GET /health

Health check endpoint.

Response:

json
{
  "status": "ok",
  "service": "alignment",
  "engine": "aeneas",
  "version": "1.7.x",
  "authEnabled": true
}
Note: authEnabled indicates whether API key authentication is required.

Supported Languages

CodeLanguage
enEnglish
esSpanish
ptPortuguese
frFrench
deGerman
itItalian
nlDutch
plPolish
ruRussian

Local Development

bash
# Build Docker image
docker build -t alignment-service .

# Run container
docker run -p 7860:7860 alignment-service

# Access UI
open http://localhost:7860

Deployment to Hugging Face Spaces

  1. 1.Create a new Space at https://huggingface.co/spaces
  2. 2.Select "Docker" SDK
  3. 3.Choose "CPU Basic" hardware (FREE)
  4. 4.Upload files:
  5. 5.Dockerfile
  6. 6.app.py
  7. 7.requirements.txt
  8. 8.README.md
  9. 9.Wait for build (~5-10 minutes first time)

Performance

MetricValue
Cold Start~10-30 seconds
Processing Speed~5-10x realtime
Memory Usage~1-2GB
Max Audio Length~10 minutes recommended

Integration with Main API

The NestJS API calls this service via HTTP (Gradio format):

typescript
const response = await axios.post(
  "https://your-alignment-service.hf.space/call/align",
  {
    data: [
      audioUrl,
      paragraphText,
      "en",
      audioId,
      paragraphIndex,
      process.env.ALIGNMENT_API_KEY,
    ],
  },
);
// Response: { data: [jsonStringResult] }
const result = JSON.parse(response.data.data[0]);

Limitations

  • โ€”CPU-only inference
  • โ€”Best for audio < 10 minutes
  • โ€”Text must match audio closely for accurate alignment
  • โ€”May queue during high load (max 20 concurrent)

Cost Summary

ResourceLimitCost
Compute16GB RAM, 2 vCPU$0/month
Storage50GB$0/month
RequestsUnlimited$0/month

Total Monthly Cost: $0