Cyril Dupland commited on
Commit ·
663d026
1
Parent(s): 4855f78
feat transcription: update audio file upload limits to be configurable via settings, enhancing flexibility for transcription service. Update documentation to reflect new maximum file size and chunking behavior for large audio files.
Browse files- .env.example +3 -1
- api/routes/transcription.py +11 -10
- config/settings.py +2 -0
.env.example
CHANGED
|
@@ -21,4 +21,6 @@ LANGCHAIN_PROJECT=routeur-ia
|
|
| 21 |
# DAILY_API_KEY=61efebb10fa3956006a11e194980876c4453311ef25737fb2e434bc040326deb
|
| 22 |
|
| 23 |
# PDF - logo en haut du document (section dédiée)
|
| 24 |
-
PDF_LOGO_PATH=assets/logo.png
|
|
|
|
|
|
|
|
|
| 21 |
# DAILY_API_KEY=61efebb10fa3956006a11e194980876c4453311ef25737fb2e434bc040326deb
|
| 22 |
|
| 23 |
# PDF - logo en haut du document (section dédiée)
|
| 24 |
+
PDF_LOGO_PATH=assets/logo.png
|
| 25 |
+
|
| 26 |
+
MAX_UPLOAD_MB_AUDIO=500
|
api/routes/transcription.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
"""Transcription routes for audio to text conversion."""
|
| 2 |
from fastapi import APIRouter, UploadFile, File, HTTPException, status, Depends, Query
|
| 3 |
from typing import Optional
|
|
|
|
| 4 |
from core.security import get_current_user
|
| 5 |
from domain.models import TranscriptionResponse, ErrorResponse
|
| 6 |
from services.transcription_service import transcription_service, meeting_transcription_service
|
|
@@ -31,7 +32,7 @@ async def transcribe_meeting_audio(
|
|
| 31 |
|
| 32 |
**Supported formats:** mp3, mp4, mpeg, mpga, m4a, wav, webm
|
| 33 |
|
| 34 |
-
**Max file size:**
|
| 35 |
|
| 36 |
Args:
|
| 37 |
file: Meeting audio file upload
|
|
@@ -52,16 +53,16 @@ async def transcribe_meeting_audio(
|
|
| 52 |
detail="Unsupported file format. Supported: mp3, mp4, mpeg, mpga, m4a, wav, webm",
|
| 53 |
)
|
| 54 |
|
| 55 |
-
# Check file size (25 MB
|
| 56 |
file.file.seek(0, 2) # Seek to end
|
| 57 |
file_size = file.file.tell() # Get position (file size)
|
| 58 |
file.file.seek(0) # Reset to beginning
|
| 59 |
|
| 60 |
-
max_size =
|
| 61 |
if file_size > max_size:
|
| 62 |
raise HTTPException(
|
| 63 |
status_code=status.HTTP_400_BAD_REQUEST,
|
| 64 |
-
detail=f"File too large. Maximum size is
|
| 65 |
)
|
| 66 |
|
| 67 |
try:
|
|
@@ -93,7 +94,7 @@ async def get_supported_formats(
|
|
| 93 |
"""
|
| 94 |
return {
|
| 95 |
"supported_formats": ["mp3", "mp4", "mpeg", "mpga", "m4a", "wav", "webm"],
|
| 96 |
-
"max_file_size_mb":
|
| 97 |
"model": "whisper-1",
|
| 98 |
"languages": "Auto-detection or specify ISO-639-1 code"
|
| 99 |
}
|
|
@@ -119,7 +120,7 @@ async def transcribe_audio(
|
|
| 119 |
|
| 120 |
**Supported formats:** mp3, mp4, mpeg, mpga, m4a, wav, webm
|
| 121 |
|
| 122 |
-
**Max file size:**
|
| 123 |
|
| 124 |
Args:
|
| 125 |
file: Audio file upload
|
|
@@ -140,16 +141,16 @@ async def transcribe_audio(
|
|
| 140 |
detail=f"Unsupported file format. Supported: mp3, mp4, mpeg, mpga, m4a, wav, webm"
|
| 141 |
)
|
| 142 |
|
| 143 |
-
# Check file size (
|
| 144 |
file.file.seek(0, 2) # Seek to end
|
| 145 |
file_size = file.file.tell() # Get position (file size)
|
| 146 |
file.file.seek(0) # Reset to beginning
|
| 147 |
-
|
| 148 |
-
max_size =
|
| 149 |
if file_size > max_size:
|
| 150 |
raise HTTPException(
|
| 151 |
status_code=status.HTTP_400_BAD_REQUEST,
|
| 152 |
-
detail=f"File too large. Maximum size is
|
| 153 |
)
|
| 154 |
|
| 155 |
try:
|
|
|
|
| 1 |
"""Transcription routes for audio to text conversion."""
|
| 2 |
from fastapi import APIRouter, UploadFile, File, HTTPException, status, Depends, Query
|
| 3 |
from typing import Optional
|
| 4 |
+
from config import settings
|
| 5 |
from core.security import get_current_user
|
| 6 |
from domain.models import TranscriptionResponse, ErrorResponse
|
| 7 |
from services.transcription_service import transcription_service, meeting_transcription_service
|
|
|
|
| 32 |
|
| 33 |
**Supported formats:** mp3, mp4, mpeg, mpga, m4a, wav, webm
|
| 34 |
|
| 35 |
+
**Max file size:** configurable (default 500 MB; files are chunked automatically if > 25 MB)
|
| 36 |
|
| 37 |
Args:
|
| 38 |
file: Meeting audio file upload
|
|
|
|
| 53 |
detail="Unsupported file format. Supported: mp3, mp4, mpeg, mpga, m4a, wav, webm",
|
| 54 |
)
|
| 55 |
|
| 56 |
+
# Check file size (configurable limit; service chunks files > 25 MB)
|
| 57 |
file.file.seek(0, 2) # Seek to end
|
| 58 |
file_size = file.file.tell() # Get position (file size)
|
| 59 |
file.file.seek(0) # Reset to beginning
|
| 60 |
|
| 61 |
+
max_size = settings.max_upload_mb_audio * 1024 * 1024
|
| 62 |
if file_size > max_size:
|
| 63 |
raise HTTPException(
|
| 64 |
status_code=status.HTTP_400_BAD_REQUEST,
|
| 65 |
+
detail=f"File too large. Maximum size is {settings.max_upload_mb_audio} MB, got {file_size / (1024 * 1024):.2f} MB",
|
| 66 |
)
|
| 67 |
|
| 68 |
try:
|
|
|
|
| 94 |
"""
|
| 95 |
return {
|
| 96 |
"supported_formats": ["mp3", "mp4", "mpeg", "mpga", "m4a", "wav", "webm"],
|
| 97 |
+
"max_file_size_mb": settings.max_upload_mb_audio,
|
| 98 |
"model": "whisper-1",
|
| 99 |
"languages": "Auto-detection or specify ISO-639-1 code"
|
| 100 |
}
|
|
|
|
| 120 |
|
| 121 |
**Supported formats:** mp3, mp4, mpeg, mpga, m4a, wav, webm
|
| 122 |
|
| 123 |
+
**Max file size:** configurable (default 500 MB; files are chunked automatically if > 25 MB)
|
| 124 |
|
| 125 |
Args:
|
| 126 |
file: Audio file upload
|
|
|
|
| 141 |
detail=f"Unsupported file format. Supported: mp3, mp4, mpeg, mpga, m4a, wav, webm"
|
| 142 |
)
|
| 143 |
|
| 144 |
+
# Check file size (configurable limit; service chunks files > 25 MB)
|
| 145 |
file.file.seek(0, 2) # Seek to end
|
| 146 |
file_size = file.file.tell() # Get position (file size)
|
| 147 |
file.file.seek(0) # Reset to beginning
|
| 148 |
+
|
| 149 |
+
max_size = settings.max_upload_mb_audio * 1024 * 1024
|
| 150 |
if file_size > max_size:
|
| 151 |
raise HTTPException(
|
| 152 |
status_code=status.HTTP_400_BAD_REQUEST,
|
| 153 |
+
detail=f"File too large. Maximum size is {settings.max_upload_mb_audio} MB, got {file_size / (1024 * 1024):.2f} MB"
|
| 154 |
)
|
| 155 |
|
| 156 |
try:
|
config/settings.py
CHANGED
|
@@ -43,6 +43,8 @@ class Settings(BaseSettings):
|
|
| 43 |
|
| 44 |
# Upload & chunking (PDF ingestion)
|
| 45 |
max_upload_mb_pdf: int = 50
|
|
|
|
|
|
|
| 46 |
chunk_size: int = 1000
|
| 47 |
chunk_overlap: int = 100
|
| 48 |
doc_default_type: str = "project_doc"
|
|
|
|
| 43 |
|
| 44 |
# Upload & chunking (PDF ingestion)
|
| 45 |
max_upload_mb_pdf: int = 50
|
| 46 |
+
# Max audio upload size for transcription (service chunks internally; OpenAI limit is 25 MB per chunk)
|
| 47 |
+
max_upload_mb_audio: int = 500
|
| 48 |
chunk_size: int = 1000
|
| 49 |
chunk_overlap: int = 100
|
| 50 |
doc_default_type: str = "project_doc"
|