Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Add opt-in chunking for ASR endpoints and simplify About page transcription display
Murtaza Nasir5e037a9c6615
diff --git a/config/env.asr.example b/config/env.asr.exampleindex fd2fd36b..a4d56d7e 100644--- a/config/env.asr.example+++ b/config/env.asr.example@@ -87,6 +87,17 @@ ASR_DIARIZE=true# ASR_MAX_SPEAKERS=5 # Hint for maximum speakers# ASR_RETURN_SPEAKER_EMBEDDINGS=false # Only enable for WhisperX ASR service+# --- ASR Chunking (for GPUs with limited memory) ---+# Self-hosted ASR services may crash on long files due to GPU memory exhaustion.+# Enable app-level chunking to split long files before sending to ASR.+# Default: false (ASR service handles files internally)+# ASR_ENABLE_CHUNKING=true++# Maximum audio duration per chunk in seconds (default: 7200 = 2 hours)+# Lower this value if your GPU runs out of memory on long files.+# Common values: 600 (10 min), 1200 (20 min), 1800 (30 min), 3600 (1 hour)+# ASR_MAX_DURATION_SECONDS=7200+# --- Application Settings ---# Set to "true" to allow user registration, "false" to disableALLOW_REGISTRATION=falsediff --git a/src/api/system.py b/src/api/system.pyindex 4dd5d348..a3429221 100644--- a/src/api/system.py+++ b/src/api/system.py@@ -152,12 +152,20 @@ def get_system_info():is_asr_connector = transcription_info.get('connector') == 'asr_endpoint'asr_enabled = is_asr_connector or USE_ASR_ENDPOINT+ # Determine the active transcription endpoint based on which connector is in use+ if asr_enabled:+ active_endpoint = ASR_BASE_URL+ else:+ active_endpoint = os.environ.get('TRANSCRIPTION_BASE_URL', 'https://api.openai.com/v1')+return jsonify({'version': version,'llm_endpoint': TEXT_MODEL_BASE_URL,'llm_model': TEXT_MODEL_NAME,- 'whisper_endpoint': os.environ.get('TRANSCRIPTION_BASE_URL', 'https://api.openai.com/v1'),+ 'transcription_endpoint': active_endpoint, # The actual endpoint being used'asr_enabled': asr_enabled,+ # Legacy fields for backwards compatibility+ 'whisper_endpoint': os.environ.get('TRANSCRIPTION_BASE_URL', 'https://api.openai.com/v1'),'asr_endpoint': ASR_BASE_URL if asr_enabled else None,'transcription': transcription_info,})diff --git a/src/config/app_config.py b/src/config/app_config.pyindex 0fa9e5b5..2f6de865 100644--- a/src/config/app_config.py+++ b/src/config/app_config.py@@ -52,6 +52,11 @@ else:ASR_MAX_SPEAKERS = NoneASR_RETURN_SPEAKER_EMBEDDINGS = False+# ASR chunking configuration - enables app-level chunking for self-hosted ASR services+# that may crash on long files due to GPU memory exhaustion+ASR_ENABLE_CHUNKING = os.environ.get('ASR_ENABLE_CHUNKING', 'false').lower() == 'true'+ASR_MAX_DURATION_SECONDS = int(os.environ.get('ASR_MAX_DURATION_SECONDS', '7200')) # 2 hours default+ENABLE_CHUNKING = os.environ.get('ENABLE_CHUNKING', 'true').lower() == 'true'CHUNK_SIZE_MB = int(os.environ.get('CHUNK_SIZE_MB', '20'))CHUNK_OVERLAP_SECONDS = int(os.environ.get('CHUNK_OVERLAP_SECONDS', '3'))diff --git a/src/services/transcription/connectors/asr_endpoint.py b/src/services/transcription/connectors/asr_endpoint.pyindex 89954c48..4dac60af 100644--- a/src/services/transcription/connectors/asr_endpoint.py+++ b/src/services/transcription/connectors/asr_endpoint.py@@ -5,7 +5,6 @@ Supports whisper-asr-webservice, WhisperX, and other compatible ASR servicesthat expose a /asr endpoint."""-import jsonimport loggingimport httpxfrom typing import Dict, Any, Set, Optional@@ -19,6 +18,7 @@ from ..base import (ConnectorSpecifications,)from ..exceptions import TranscriptionError, ConfigurationError, ProviderError+from src.config.app_config import ASR_ENABLE_CHUNKING, ASR_MAX_DURATION_SECONDSlogger = logging.getLogger(__name__)@@ -34,11 +34,12 @@ class ASREndpointConnector(BaseTranscriptionConnector):}PROVIDER_NAME = "asr_endpoint"- # Self-hosted ASR endpoints typically handle files of any size internally+ # SPECIFICATIONS is set dynamically in __init__ based on ASR_ENABLE_CHUNKING config+ # Default values here for class-level reference (overridden per-instance)SPECIFICATIONS = ConnectorSpecifications(- max_file_size_bytes=None, # Unlimited- max_duration_seconds=None, # Unlimited- handles_chunking_internally=True, # ASR service handles it+ max_file_size_bytes=None,+ max_duration_seconds=None,+ handles_chunking_internally=True,)def __init__(self, config: Dict[str, Any]):@@ -59,6 +60,30 @@ class ASREndpointConnector(BaseTranscriptionConnector):self.return_embeddings = config.get('return_speaker_embeddings', False)self.default_diarize = config.get('diarize', True)+ # Configure chunking behavior based on environment variables+ # ASR_ENABLE_CHUNKING=true enables app-level chunking for self-hosted ASR services+ # that may crash on long files due to GPU memory exhaustion+ if ASR_ENABLE_CHUNKING:+ # Calculate recommended chunk size (80% of max for safety margin)+ recommended_chunk = int(ASR_MAX_DURATION_SECONDS * 0.8)+ self.SPECIFICATIONS = ConnectorSpecifications(+ max_file_size_bytes=None, # No file size limit+ max_duration_seconds=ASR_MAX_DURATION_SECONDS,+ handles_chunking_internally=False, # App handles chunking+ recommended_chunk_seconds=recommended_chunk,+ )+ logger.info(+ f"ASR chunking enabled: max_duration={ASR_MAX_DURATION_SECONDS}s, "+ f"recommended_chunk={recommended_chunk}s"+ )+ else:+ # Default behavior: ASR service handles everything internally+ self.SPECIFICATIONS = ConnectorSpecifications(+ max_file_size_bytes=None,+ max_duration_seconds=None,+ handles_chunking_internally=True,+ )+# Add speaker embeddings capability if enabledif self.return_embeddings:self.CAPABILITIES = self.CAPABILITIES | {TranscriptionCapability.SPEAKER_EMBEDDINGS}diff --git a/templates/account.html b/templates/account.htmlindex 51879f42..259eb90c 100644--- a/templates/account.html+++ b/templates/account.html@@ -1353,18 +1353,8 @@ curl "https://your-speakr-instance.com/api/recordings?token=YOUR_TOKEN_HERE"</co</p><p class="text-[var(--text-secondary)]"><span class="font-medium" data-i18n="aboutPage.endpoint">Endpoint:</span>- <span id="whisper-endpoint" class="font-mono text-xs text-[var(--text-muted)] ml-1">Loading...</span>+ <span id="transcription-endpoint" class="font-mono text-xs text-[var(--text-muted)] ml-1">Loading...</span></p>- <p class="text-[var(--text-secondary)]">- <span class="font-medium" data-i18n="aboutPage.asrEnabled">ASR Enabled:</span>- <span id="asr-status" class="ml-1">Loading...</span>- </p>- <div id="asr-endpoint-row" style="display: none;">- <p class="text-[var(--text-secondary)]">- <span class="font-medium" data-i18n="aboutPage.asrEndpoint">ASR Endpoint:</span>- <span id="asr-endpoint" class="font-mono text-xs text-[var(--text-muted)] ml-1">-</span>- </p>- </div></div></div></div>@@ -3460,20 +3450,14 @@ curl "https://your-speakr-instance.com/api/recordings?token=YOUR_TOKEN_HERE"</co// Display model name from connector info, with fallbackconst transcriptionModel = data.transcription?.model || data.transcription?.connector || 'whisper-1';document.getElementById('transcription-model').textContent = transcriptionModel;- document.getElementById('whisper-endpoint').textContent = data.whisper_endpoint;- document.getElementById('asr-status').textContent = data.asr_enabled ? 'Yes' : 'No';-- if (data.asr_enabled && data.asr_endpoint) {- document.getElementById('asr-endpoint').textContent = data.asr_endpoint;- document.getElementById('asr-endpoint-row').style.display = 'block';- }+ // Show the active transcription endpoint (ASR or OpenAI depending on config)+ document.getElementById('transcription-endpoint').textContent = data.transcription_endpoint || data.whisper_endpoint;} catch (error) {document.getElementById('system-version').textContent = 'Failed to load';document.getElementById('llm-endpoint').textContent = 'Failed to load';document.getElementById('llm-model').textContent = 'Failed to load';document.getElementById('transcription-model').textContent = 'Failed to load';- document.getElementById('whisper-endpoint').textContent = 'Failed to load';- document.getElementById('asr-status').textContent = 'Failed to load';+ document.getElementById('transcription-endpoint').textContent = 'Failed to load';}}