Organize config

This commit is contained in:
Xin Wang
2026-02-25 15:52:55 +08:00
parent 2b2193557d
commit 8b9064f6e6
12 changed files with 1248 additions and 92 deletions

View File

@@ -6,6 +6,7 @@ API: https://docs.siliconflow.cn/cn/api-reference/audio/create-audio-transcripti
import asyncio
import io
import os
import wave
from typing import AsyncIterator, Optional, Callable, Awaitable
from loguru import logger
@@ -46,7 +47,8 @@ class OpenAICompatibleASRService(BaseASRService):
def __init__(
self,
api_key: str,
api_key: Optional[str] = None,
api_url: Optional[str] = None,
model: str = "FunAudioLLM/SenseVoiceSmall",
sample_rate: int = 16000,
language: str = "auto",
@@ -59,6 +61,7 @@ class OpenAICompatibleASRService(BaseASRService):
Args:
api_key: Provider API key
api_url: Provider API URL (defaults to SiliconFlow endpoint)
model: ASR model name or alias
sample_rate: Audio sample rate (16000 recommended)
language: Language code (auto for automatic detection)
@@ -71,7 +74,8 @@ class OpenAICompatibleASRService(BaseASRService):
if not AIOHTTP_AVAILABLE:
raise RuntimeError("aiohttp is required for OpenAICompatibleASRService")
self.api_key = api_key
self.api_key = api_key or os.getenv("ASR_API_KEY") or os.getenv("SILICONFLOW_API_KEY")
self.api_url = api_url or os.getenv("ASR_API_URL") or self.API_URL
self.model = self.MODELS.get(model.lower(), model)
self.interim_interval_ms = interim_interval_ms
self.min_audio_for_interim_ms = min_audio_for_interim_ms
@@ -96,6 +100,8 @@ class OpenAICompatibleASRService(BaseASRService):
async def connect(self) -> None:
"""Connect to the service."""
if not self.api_key:
raise ValueError("ASR API key not provided. Configure agent.asr.api_key in YAML.")
self._session = aiohttp.ClientSession(
headers={
"Authorization": f"Bearer {self.api_key}"
@@ -180,7 +186,7 @@ class OpenAICompatibleASRService(BaseASRService):
)
form_data.add_field('model', self.model)
async with self._session.post(self.API_URL, data=form_data) as response:
async with self._session.post(self.api_url, data=form_data) as response:
if response.status == 200:
result = await response.json()
text = result.get("text", "").strip()