mandada/forced-alignment-server
AssemblyAI Transcription Server
This Node.js/Express server provides an API to transcribe audio files using AssemblyAI's asynchronous transcription service. It includes a caching layer using Cloudflare R2 to avoid re-transcribing the same audio files.
Features
- Asynchronous Transcription: Submits audio URLs for transcription and returns a job ID immediately.
- Status Polling: Allows clients to poll for the transcription status.
- Cloudflare R2 Caching: Caches completed transcriptions to reduce costs and improve response times.
- Secure: Uses environment variables to manage API keys and other secrets.
Setup
- Install Dependencies:
npm install- Create `.env` file: Create a
.envfile in the root of the project and add the following environment variables:
ASSEMBLYAI_API_KEY=your_assemblyai_api_key
R2_ACCOUNT_ID=your_r2_account_id
R2_ACCESS_KEY_ID=your_r2_access_key_id
R2_SECRET_ACCESS_KEY=your_r2_secret_access_key
R2_BUCKET_NAME=saintshubapp-transcribed-sermons- Run the server:
npm run devThe server will start on http://localhost:3000.
Testing Endpoints
You can use curl to test the server endpoints.
1. Submit a transcription job
This will submit an audio URL to the /transcribe endpoint. The server will return a JSON object with the status and the transcription job ID.
curl -X POST -H "Content-Type: application/json" -d '{"audioUrl": "https://assemblyai-realtimestatic-prod.s3.us-west-2.amazonaws.com/static/demos/media/20130514-105844-320k.mp3"}' http://localhost:3000/transcribe2. Extract Text from a PDF
This will submit a PDF URL to the /extract-pdf endpoint. The server will download the PDF, extract its text content, cache the result in R2, and return the full text.
curl -X POST -H "Content-Type: application/json" -d '{"pdfUrl": "https://www.sounddoctrine.net/sermons/pdf/101214.pdf"}' http://localhost:3000/extract-pdfExpected Response:
{
"status": "processing",
"id": "some-transcription-id"
}2. Check the transcription status
Use the id from the previous step to poll the /status/:id endpoint. Replace YOUR_TRANSCRIPTION_ID with the actual ID.
curl http://localhost:3000/status/YOUR_TRANSCRIPTION_IDExpected Response (once completed):
The server will return the full transcription object from AssemblyAI, including the text and word-level timestamps.
{
"id": "YOUR_TRANSCRIPTION_ID",
"status": "completed",
"text": "This is the transcribed text...",
"words": [...]
}