Transcribe audio from URL or upload from local disk.
Make sure you have Python and Redis installed on your system. After cloning this repo, follow these steps.
-
Create and activate virtual env:
python -m venv venv . venv/bin/activate
-
Install the dependencies:
pip install -r requirements.txt
-
Copy the
.env_sample
file into.env
and modify its values:REDIS_HOST=localhost REDIS_PORT=6379
-
Run the development server:
uvicorn src.main:app --reload
It will run on
localhost
and accepting requests on port 8000. -
Open another terminal and activate the virtual env as well:
. venv/bin/activate
-
Run the celery task:
celery -A src.tasks --loglevel=info
Once the API is up and running, you can transcribe your audio files e.g:
import time
import requests
API_URL = 'http://localhost:8000'
# Upload audio file
with open('/path/to/audio.wav', 'rb') as f:
r = requests.post(f'{API_URL}/transcribe', files={'audio': f})
r.raise_for_status()
# Check the status and retrieve the transcriptin
task_id = r.json()['taskId']
while True:
r = requests.get(f'{API_URL}/transcribe/{task_id}')
status = r.json()['status']
print(f'Status = {status}')
if status == 'DONE':
break
time.sleep(1)
print('Result = ', r.json()['result'])
If you have Docker installed on your machine, you can run the API using Docker:
-
Copy the
.env_sample
file into.env
and modify its values:REDIS_HOST=redis REDIS_PORT=6379
-
Run the app:
docker compose up
The API will be running and accepting requests on port 8000.
FastAPI automatically generates the documentation for the API, you can access the docs at http://localhost:8000/docs
.
MIT