-
Notifications
You must be signed in to change notification settings - Fork 51.9k
fix: Feishu voice messages routed to VOICE for STT; .ogg added to nat… #38299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,8 +99,8 @@ def _safe_find_spec(module_name: str) -> bool: | |
| XAI_STT_BASE_URL = os.getenv("XAI_STT_BASE_URL", "https://api.x.ai/v1") | ||
| ELEVENLABS_STT_BASE_URL = os.getenv("ELEVENLABS_STT_BASE_URL", "https://api.elevenlabs.io/v1") | ||
|
|
||
| SUPPORTED_FORMATS = {".mp3", ".mp4", ".mpeg", ".mpga", ".m4a", ".wav", ".webm", ".ogg", ".aac", ".flac"} | ||
| LOCAL_NATIVE_AUDIO_FORMATS = {".wav", ".aiff", ".aif"} | ||
| SUPPORTED_FORMATS = {".mp3", ".mp4", ".mpeg", ".mpga", ".m4a", ".wav", ".webm", ".ogg", ".aac", ".flac", ".silk"} | ||
| LOCAL_NATIVE_AUDIO_FORMATS = {".wav", ".aiff", ".aif", ".ogg"} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding |
||
| MAX_FILE_SIZE = 25 * 1024 * 1024 # 25 MB | ||
|
|
||
| # Known model sets for auto-correction | ||
|
|
@@ -1132,29 +1132,35 @@ def _transcribe_local(file_path: str, model_name: str) -> Dict[str, Any]: | |
| if _forced_lang: | ||
| transcribe_kwargs["language"] = _forced_lang | ||
|
|
||
| try: | ||
| segments, info = _local_model.transcribe(file_path, **transcribe_kwargs) | ||
| transcript = " ".join(segment.text.strip() for segment in segments) | ||
| except Exception as exc: | ||
| # CUDA runtime libs sometimes only fail at dlopen-on-first-use, | ||
| # AFTER the model loaded successfully. Evict the broken cached | ||
| # model, reload on CPU, retry once. Without this the module- | ||
| # global `_local_model` is poisoned and every subsequent voice | ||
| # message on this process fails identically until restart. | ||
| if not _looks_like_cuda_lib_error(exc): | ||
| raise | ||
| logger.warning( | ||
| "faster-whisper CUDA runtime failed mid-transcribe (%s) — " | ||
| "evicting cached model and retrying on CPU (int8).", | ||
| exc, | ||
| ) | ||
| _local_model = None | ||
| _local_model_name = None | ||
| from faster_whisper import WhisperModel | ||
| _local_model = WhisperModel(model_name, device="cpu", compute_type="int8") | ||
| _local_model_name = model_name | ||
| segments, info = _local_model.transcribe(file_path, **transcribe_kwargs) | ||
| transcript = " ".join(segment.text.strip() for segment in segments) | ||
| # Convert non-native formats (e.g. WeChat .silk) before passing to Whisper | ||
| with tempfile.TemporaryDirectory(prefix="hermes-stt-") as work_dir: | ||
| prepared_input, prep_error = _prepare_local_audio(file_path, work_dir) | ||
| if prep_error: | ||
| return {"success": False, "transcript": "", "error": prep_error} | ||
|
|
||
| try: | ||
| segments, info = _local_model.transcribe(prepared_input, **transcribe_kwargs) | ||
| transcript = " ".join(segment.text.strip() for segment in segments) | ||
| except Exception as exc: | ||
| # CUDA runtime libs sometimes only fail at dlopen-on-first-use, | ||
| # AFTER the model loaded successfully. Evict the broken cached | ||
| # model, reload on CPU, retry once. Without this the module- | ||
| # global `_local_model` is poisoned and every subsequent voice | ||
| # message on this process fails identically until restart. | ||
| if not _looks_like_cuda_lib_error(exc): | ||
| raise | ||
| logger.warning( | ||
| "faster-whisper CUDA runtime failed mid-transcribe (%s) — " | ||
| "evicting cached model and retrying on CPU (int8).", | ||
| exc, | ||
| ) | ||
| _local_model = None | ||
| _local_model_name = None | ||
| from faster_whisper import WhisperModel | ||
| _local_model = WhisperModel(model_name, device="cpu", compute_type="int8") | ||
| _local_model_name = model_name | ||
| segments, info = _local_model.transcribe(prepared_input, **transcribe_kwargs) | ||
| transcript = " ".join(segment.text.strip() for segment in segments) | ||
|
|
||
| logger.info( | ||
| "Transcribed %s via local whisper (%s, lang=%s, %.1fs audio)", | ||
|
|
@@ -1174,6 +1180,17 @@ def _prepare_local_audio(file_path: str, work_dir: str) -> tuple[Optional[str], | |
| if audio_path.suffix.lower() in LOCAL_NATIVE_AUDIO_FORMATS: | ||
| return file_path, None | ||
|
|
||
| # Handle WeChat .silk format via pilk (pure Python SILK decoder, no ffmpeg needed) | ||
| if audio_path.suffix.lower() == ".silk": | ||
| try: | ||
| import pilk | ||
| converted_path = os.path.join(work_dir, f"{audio_path.stem}.wav") | ||
| pilk.silk_to_wav(file_path, converted_path, rate=24000) | ||
| return converted_path, None | ||
| except Exception as e: | ||
| logger.error("pilk .silk decode failed for %s: %s", file_path, e) | ||
| return None, f"Failed to decode .silk audio: {e}" | ||
|
|
||
| ffmpeg = _find_ffmpeg_binary() | ||
| if not ffmpeg: | ||
| return None, "Local STT fallback requires ffmpeg for non-WAV inputs, but ffmpeg was not found" | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please retain a discriminator here rather than classifying every Feishu
audioevent asVOICE: current gateway routing deliberately keepsMessageType.AUDIOattachments out of STT (gateway/run.py:10414-10422). This needs coverage for both a native voice note and an ordinary audio-file attachment.