A FastAPI-based web service for forced alignment of audio and text using Montreal Forced Aligner (MFA) and Kalpy.
- RESTful API for audio-transcript alignment
- Returns alignment results as JSON with word and phone-level timing
- Currently hardcodes the dictionaries, so only supports one language at a time
-
Clone this repository:
git clone git@github.com:stephenmac7/mfa-service.git cd mfa-service -
Create the conda environment from the environment file:
conda env create -f environment.yml
-
Activate the environment:
conda activate mfa-service
-
Download the required MFA models:
mfa model download acoustic english_mfa mfa model download dictionary english_us_mfa
-
Activate the conda environment (if not already activated):
conda activate mfa-service
-
Start the FastAPI server:
fastapi dev main.py --port 8001
-
The API will be available at
http://localhost:8001- Interactive API docs:
http://localhost:8001/docs - Alternative docs:
http://localhost:8001/redoc
- Interactive API docs:
POST /align
Upload a WAV file and transcript to get alignment results.
Parameters:
audio(file): WAV audio filetranscript(form field): Text transcript of the audio
Example using curl:
curl -X POST "http://localhost:8001/align" \
-F "audio=@your_audio.wav" \
-F "transcript=Your transcript text here"Example using Python:
import requests
files = {'audio': open('your_audio.wav', 'rb')}
data = {'transcript': 'Your transcript text here'}
response = requests.post('http://localhost:8001/align', files=files, data=data)
print(response.json())If you add new dependencies, update the environment.yml file and recreate the environment:
conda env update -f environment.yml --prune