Skip to content

feat: add MiniMax STT API provider - #10144

Open
murphys7017 wants to merge 2 commits into
AstrBotDevs:masterfrom
murphys7017:feat/minimax-stt-provider
Open

murphys7017 wants to merge 2 commits into
AstrBotDevs:masterfrom
murphys7017:feat/minimax-stt-provider

Conversation

@murphys7017

@murphys7017 murphys7017 commented Sep 19, 2026

Copy link
Copy Markdown

Summary

  • add a MiniMax speech-to-text provider using the official multipart API
  • register a MiniMax STT provider preset with optional language hints
  • support remote audio downloads and Tencent SILK/AMR conversion with cleanup

Validation

  • python -m pytest tests/test_minimax_stt_api_source.py -q (6 passed)

uff format --check astrbot/core/provider/sources/minimax_stt_api_source.py tests/test_minimax_stt_api_source.py

uff check astrbot/core/provider/sources/minimax_stt_api_source.py tests/test_minimax_stt_api_source.py

  • python -m compileall -q astrbot/core/provider/sources/minimax_stt_api_source.py
  • git diff --check

No live MiniMax API request was made because no API key is included.

Summary by Sourcery

Add MiniMax speech-to-text support with configurable language hints and robust audio preparation.

New Features:

  • Add a MiniMax speech-to-text API provider with configurable model, endpoint, API credentials, and optional language hints.
  • Support local and remote audio transcription, including Tencent SILK and AMR input conversion.

Enhancements:

  • Ensure temporary downloaded and converted audio files are cleaned up after successful or failed processing.
  • Register the MiniMax provider preset and dynamic provider loading configuration.

Documentation:

  • Document the MiniMax STT provider in the unreleased changelog.

Tests:

  • Add coverage for multipart uploads, transcription responses, audio handling, and temporary-file cleanup.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="astrbot/core/provider/sources/minimax_stt_api_source.py" line_range="61-62" />
<code_context>
+                temp_dir = Path(get_astrbot_temp_path())
+                temp_dir.mkdir(parents=True, exist_ok=True)
+                source_path = temp_dir / f"minimax_stt_{uuid.uuid4().hex[:8]}{suffix}"
+                await download_file(audio_source, str(source_path))
+                cleanup_paths.append(source_path)
+
+            if not source_path.exists():
</code_context>
<issue_to_address>
**issue (bug_risk):** If `download_file` creates a partial destination and then raises, the downloaded path is not added to `cleanup_paths` because it is appended only after the await completes, so the partial temporary file is leaked.

**Triggers:** When a remote audio download fails after writing any bytes.

**Suggested fix:** Add the destination path to `cleanup_paths` before awaiting `download_file`, or delete the destination in the download exception path.

```suggestion
                cleanup_paths.append(source_path)
                await download_file(audio_source, str(source_path))
```
</issue_to_address>

### Comment 2
<location path="astrbot/core/provider/sources/minimax_stt_api_source.py" line_range="106-108" />
<code_context>
+
+    async def get_text(self, audio_url: str) -> str:
+        audio_path, cleanup_paths = await self._prepare_audio_file(audio_url)
+        headers = {"Authorization": f"Bearer {self.chosen_api_key}"}
+        if self.language:
+            headers["language"] = self.language
+
+        try:
+            content_type = (
</code_context>
<issue_to_address>
**issue:** Configured provider `custom_headers` are never merged into the request headers, so custom authentication, routing, or gateway headers configured through the standard provider mechanism are silently omitted from every MiniMax STT request.

**Triggers:** When a MiniMax provider configuration contains `custom_headers`.

**Suggested fix:** Merge `self.request_headers` into the request headers while allowing the required Authorization and language headers to take precedence.

```suggestion
        headers = {
            **self.request_headers,
            "Authorization": f"Bearer {self.chosen_api_key}",
        }
        if self.language:
            headers["language"] = self.language
```
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and if the provider is wrong, enabled users may send audio to an unintended or malfunctioning MiniMax endpoint, and those external uploads cannot be retracted, though the impact is limited to opted-in transcription requests and reverting stops future calls. Transcriptions are not persisted by this change, so normal implementation defects can be repaired without data migration or recovery work.

Blocking findings: astrbot/core/provider/sources/minimax_stt_api_source.py:62, astrbot/core/provider/sources/minimax_stt_api_source.py:108


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread astrbot/core/provider/sources/minimax_stt_api_source.py Outdated
Comment thread astrbot/core/provider/sources/minimax_stt_api_source.py Outdated
@murphys7017

Copy link
Copy Markdown
Author

Addressed the Sourcery findings: partial remote downloads are now registered for cleanup before download starts, and standard custom headers are merged while the configured Authorization and language headers retain precedence. Added regression coverage; focused suite now passes 7 tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant