Commit 8160091

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-05-13 18:05:45
feat(asr): add model_id parameter to Gemini ASR
1 parent a681218
Changed files (1)
src/asr/gemini_asr.py
@@ -25,6 +25,7 @@ async def gemini_stream_asr(
     message: Message,
     path: str | Path,
     voice_format: str,
+    model_id: str | None = None,
     prompt: str = "请转录这段音频",
     *,
     silent: bool = False,
@@ -70,9 +71,11 @@ Notes:
     path = Path(path)
     status = None if silent else kwargs.get("progress")
     api_keys = shuffle_keys(GEMINI.API_KEYS)
+    if model_id is None:
+        model_id = GEMINI.ASR_MODEL
     for api_key in api_keys.split(","):
         try:
-            logger.debug(f"ASR via {GEMINI.ASR_MODEL}: {path.as_posix()} , proxy={GEMINI.PROXY}")
+            logger.debug(f"ASR via {model_id}: {path.as_posix()} , proxy={GEMINI.PROXY}")
             http_options = HttpOptions(base_url=GEMINI.BASR_URL, async_client_args={"proxy": GEMINI.PROXY})
             http_options = hook_gemini_httpoptions(http_options, message)
             app = genai.Client(api_key=api_key, http_options=http_options)
@@ -88,7 +91,7 @@ Notes:
             if GEMINI.ASR_USE_GROUNDING:
                 genconfig |= {"tools": [Tool(google_search=GoogleSearch())]}
             contents = [prompt, uploaded_audio] if prompt else [uploaded_audio]
-            params = {"model": GEMINI.ASR_MODEL, "contents": contents, "config": GenerateContentConfig(**genconfig)}
+            params = {"model": model_id, "contents": contents, "config": GenerateContentConfig(**genconfig)}
             res = await gemini_stream(
                 client,
                 message,