Last active
June 5, 2025 15:19
-
-
Save pschichtel/4ecaf5f68d55212b158316bed9f1d575 to your computer and use it in GitHub Desktop.
A very simplistic implementation of OpenAI Whisper's transcription API endpoint.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sanic>=23.6.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sanic import Sanic, response, HTTPResponse | |
from sanic.request import Request | |
app = Sanic("TranscriptionServer") | |
expected_content_type = 'multipart/form-data' | |
@app.post("/v1/audio/transcriptions") | |
async def transcribe_audio(request: Request) -> HTTPResponse: | |
mime_type = request.content_type.split(';')[0].strip().lower() | |
if mime_type != expected_content_type: | |
return response.json(body={'error': f"Content-Type must be {expected_content_type}"}, status=400) | |
form = request.form | |
files = request.files | |
if files is None or 'file' not in files: | |
return response.json(body={'error': 'No file provided'}, status=400) | |
file = files.get('file') | |
if file is None: | |
return response.json(body={'error': 'No file selected'}, status=400) | |
text = f'Mock transcription for file: {file.name} with {form}' | |
print(f"Text: {text}") | |
return response.json({'text': text}) | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=8080, fast=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment