Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Add MISTRAL_ENABLE_CHUNKING for app-side chunking of long Voxtral recordings

Murtaza Nasirf75372964938
diff --git a/src/services/transcription/connectors/mistral.py b/src/services/transcription/connectors/mistral.py
index 6d36d4dc..3d2b348c 100644
--- a/src/services/transcription/connectors/mistral.py
+++ b/src/services/transcription/connectors/mistral.py
@@ -7,6 +7,7 @@ Particularly strong for French and multilingual audio.
"""
import logging
+import os
import re
import httpx
from typing import Dict, Any, Set, List, Optional
@@ -34,12 +35,14 @@ class MistralTranscriptionConnector(BaseTranscriptionConnector):
}
PROVIDER_NAME = "mistral"
- # Voxtral supports up to 3 hours per request, no app-level chunking needed
+ # Default class-level spec assumes no chunking — Voxtral handles up to 3
+ # hours natively. Instances can override this in __init__ when
+ # MISTRAL_ENABLE_CHUNKING=true (issue #267).
SPECIFICATIONS = ConnectorSpecifications(
max_file_size_bytes=None,
- max_duration_seconds=None, # No hard limit for chunking decisions
+ max_duration_seconds=None,
handles_chunking_internally=True,
- recommended_chunk_seconds=0, # Disable — Mistral handles up to 3hrs natively
+ recommended_chunk_seconds=0,
)
def __init__(self, config: Dict[str, Any]):
@@ -68,6 +71,28 @@ class MistralTranscriptionConnector(BaseTranscriptionConnector):
verify=True,
)
+ # Optional app-side chunking for very long recordings. Voxtral times
+ # out near its 3-hour limit on cloud inference; chunking lets users
+ # process longer meetings reliably. Diarization is per-chunk (Mistral
+ # doesn't return voice embeddings), so speakers will be remapped at
+ # chunk boundaries.
+ if os.environ.get('MISTRAL_ENABLE_CHUNKING', 'false').lower() == 'true':
+ try:
+ max_seconds = int(os.environ.get('MISTRAL_MAX_DURATION_SECONDS', '7200'))
+ except (ValueError, TypeError):
+ max_seconds = 7200
+ recommended_chunk = int(max_seconds * 0.8)
+ self.SPECIFICATIONS = ConnectorSpecifications(
+ max_file_size_bytes=None,
+ max_duration_seconds=max_seconds,
+ handles_chunking_internally=False,
+ recommended_chunk_seconds=recommended_chunk,
+ )
+ logger.info(
+ f"Mistral chunking enabled: max_duration={max_seconds}s, "
+ f"recommended_chunk={recommended_chunk}s"
+ )
+
def _validate_config(self) -> None:
"""Validate required configuration."""
if not self.config.get('api_key'):
diff --git a/tests/test_mistral_connector.py b/tests/test_mistral_connector.py
index 31bada6c..a9ee8d11 100644
--- a/tests/test_mistral_connector.py
+++ b/tests/test_mistral_connector.py
@@ -664,6 +664,24 @@ def test_chunking_behavior():
os.environ.pop('CHUNK_LIMIT', None)
run_test("Mistral specs disable app-level chunking", t1)
+ def t2():
+ # MISTRAL_ENABLE_CHUNKING=true should opt the connector into app-side chunking.
+ os.environ['MISTRAL_ENABLE_CHUNKING'] = 'true'
+ os.environ['MISTRAL_MAX_DURATION_SECONDS'] = '3600'
+ try:
+ connector = MistralTranscriptionConnector({'api_key': 'test'})
+ specs = connector.SPECIFICATIONS
+ assert specs.handles_chunking_internally is False, \
+ f"Chunking should be opt-in but got handles_chunking_internally={specs.handles_chunking_internally}"
+ assert specs.max_duration_seconds == 3600, f"got max_duration_seconds={specs.max_duration_seconds}"
+ # 80% of max duration as the recommended chunk size.
+ assert specs.recommended_chunk_seconds == 2880, \
+ f"got recommended_chunk_seconds={specs.recommended_chunk_seconds}"
+ finally:
+ os.environ.pop('MISTRAL_ENABLE_CHUNKING', None)
+ os.environ.pop('MISTRAL_MAX_DURATION_SECONDS', None)
+ run_test("MISTRAL_ENABLE_CHUNKING=true opts in to app-side chunking", t2)
+
# =============================================================================
# Main