Skip to content

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

Python

Add AUDIO_UNSUPPORTED_CODECS config to exclude codecs from supported list

Murtaza Nasir8381d2c565f8
diff --git a/config/env.asr.example b/config/env.asr.example
index a588c15e..baa63e79 100644
--- a/config/env.asr.example
+++ b/config/env.asr.example
@@ -95,6 +95,12 @@ AUDIO_CODEC=mp3
# Bitrate for lossy codecs (ignored for FLAC)
AUDIO_BITRATE=128k
+# Unsupported codecs - comma-separated list of codecs to exclude from supported list
+# Use this if your transcription service doesn't support certain codecs
+# Supported codecs by default: pcm_s16le, pcm_s24le, pcm_f32le, mp3, flac, opus, vorbis, aac
+# Example: AUDIO_UNSUPPORTED_CODECS=opus,vorbis
+# AUDIO_UNSUPPORTED_CODECS=
+
# --- Admin User (created on first run) ---
ADMIN_USERNAME=admin
diff --git a/config/env.whisper.example b/config/env.whisper.example
index 69396c52..fef817ca 100644
--- a/config/env.whisper.example
+++ b/config/env.whisper.example
@@ -97,6 +97,12 @@ AUDIO_CODEC=mp3
# Bitrate for lossy codecs (ignored for FLAC)
AUDIO_BITRATE=128k
+# Unsupported codecs - comma-separated list of codecs to exclude from supported list
+# Use this if your transcription service doesn't support certain codecs
+# Supported codecs by default: pcm_s16le, pcm_s24le, pcm_f32le, mp3, flac, opus, vorbis, aac
+# Example: AUDIO_UNSUPPORTED_CODECS=opus,vorbis
+# AUDIO_UNSUPPORTED_CODECS=
+
# --- Admin User (created on first run) ---
ADMIN_USERNAME=admin
diff --git a/src/config/app_config.py b/src/config/app_config.py
index e86376d7..e6e65520 100644
--- a/src/config/app_config.py
+++ b/src/config/app_config.py
@@ -48,6 +48,12 @@ AUDIO_COMPRESS_UPLOADS = os.environ.get('AUDIO_COMPRESS_UPLOADS', 'true').lower(
AUDIO_CODEC = os.environ.get('AUDIO_CODEC', 'mp3').lower() # mp3, flac, opus
AUDIO_BITRATE = os.environ.get('AUDIO_BITRATE', '128k') # For lossy codecs
+# Unsupported codecs - comma-separated list of codecs to exclude from the default supported list
+# Useful when your transcription service doesn't support certain codecs (e.g., vllm doesn't support opus)
+# Example: AUDIO_UNSUPPORTED_CODECS=opus,vorbis
+_unsupported_codecs_str = os.environ.get('AUDIO_UNSUPPORTED_CODECS', '')
+AUDIO_UNSUPPORTED_CODECS = {c.strip().lower() for c in _unsupported_codecs_str.split(',') if c.strip()}
+
# Create chunking service at module level so it can be imported by processing.py
chunking_service = AudioChunkingService(CHUNK_SIZE_MB, CHUNK_OVERLAP_SECONDS) if ENABLE_CHUNKING else None
diff --git a/src/utils/audio_conversion.py b/src/utils/audio_conversion.py
index 343de38f..c96efcfe 100644
--- a/src/utils/audio_conversion.py
+++ b/src/utils/audio_conversion.py
@@ -17,7 +17,7 @@ from typing import Optional, Tuple, Set, Dict, Any
from src.utils.ffprobe import get_codec_info, is_lossless_audio, FFProbeError
from src.utils.ffmpeg_utils import compress_audio, extract_audio_from_video, FFmpegError, FFmpegNotFoundError
-from src.config.app_config import AUDIO_COMPRESS_UPLOADS, AUDIO_CODEC, AUDIO_BITRATE
+from src.config.app_config import AUDIO_COMPRESS_UPLOADS, AUDIO_CODEC, AUDIO_BITRATE, AUDIO_UNSUPPORTED_CODECS
logger = logging.getLogger(__name__)
@@ -71,14 +71,23 @@ def get_supported_codecs(needs_chunking: bool = False) -> Set[str]:
needs_chunking: If True, return only codecs that work well with chunking
Returns:
- Set of supported codec names
+ Set of supported codec names (minus any excluded via AUDIO_UNSUPPORTED_CODECS)
"""
if needs_chunking:
# For chunking: only support codecs that work well with chunking
- return {'pcm_s16le', 'pcm_s24le', 'pcm_f32le', 'mp3', 'flac'}
+ base_codecs = {'pcm_s16le', 'pcm_s24le', 'pcm_f32le', 'mp3', 'flac'}
else:
# For direct transcription: support more codecs including WebM/Opus
- return {'pcm_s16le', 'pcm_s24le', 'pcm_f32le', 'mp3', 'flac', 'opus', 'vorbis', 'aac'}
+ base_codecs = {'pcm_s16le', 'pcm_s24le', 'pcm_f32le', 'mp3', 'flac', 'opus', 'vorbis', 'aac'}
+
+ # Remove any user-specified unsupported codecs
+ if AUDIO_UNSUPPORTED_CODECS:
+ excluded = base_codecs & AUDIO_UNSUPPORTED_CODECS
+ if excluded:
+ logger.info(f"Excluding codecs from supported list (via AUDIO_UNSUPPORTED_CODECS): {excluded}")
+ return base_codecs - AUDIO_UNSUPPORTED_CODECS
+
+ return base_codecs
def convert_if_needed(