mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-11-27 23:58:47 +00:00
Some checks are pending
CI / Python packages / Build and verify distributions (push) Waiting to run
CI / Python quality / GitHub Actions (push) Waiting to run
CI / Python quality / Pre-commit (push) Waiting to run
CI / Python tests / Hermes embedded - ubuntu-latest (push) Waiting to run
CI / Python tests / Hermes embedded - windows-latest (push) Waiting to run
CI / Python tests / Unit Tests - py3.11 (push) Waiting to run
CI / Python tests / Unit Tests - py3.12 (push) Waiting to run
CI / Python tests / Unit Tests - py3.13 (push) Waiting to run
CI / Python tests / Unit Tests - py3.14 (push) Waiting to run
CI / ReMe Studio / Studio checks (push) Waiting to run
CI / Windows / CLI smoke - py3.11 (push) Waiting to run
Deploy / Documentation / Build documentation (push) Waiting to run
Deploy / Documentation / deploy (push) Blocked by required conditions
Security / CodeQL / Analyze javascript-typescript (push) Waiting to run
Security / CodeQL / Analyze python (push) Waiting to run
* refactor(proactive)!: separate runtime ownership and unify delivery * refactor(proactive): finish runtime and Studio migration * test(proactive): make scheduled skip coverage deterministic * refactor(studio): unify navigation and notebook resource loading * feat(studio): edit workspace documents and update proactive task names * refactor(studio): simplify task settings and navigation * feat(studio): secure and supervise backend settings * feat(studio): unify workbench timelines and refine desktop updates Use shared timeline panes for notebook, memory, and resources. Add Todo creation ordering, persist companion visibility, and align desktop update handling and release artifacts. Recheck editor file versions at read and publication boundaries. Retry reminder detail requests from the resource view. * fix(studio): support unsigned GitHub preview releases * fix: verify container state and isolate proactive view errors Mount private supervisor state in Docker smoke tests and verify token and settings persistence. Exercise Studio startup with a loopback-only model fixture, and exclude packaged desktop output from Docker contexts. Keep Remy subscriptions and healthy tasks available when an individual task has an invalid workspace path or session history. * fix(home): align candidate Docker context exclusions * chore(deps): update openai-codex dependency to v0.172.0 - Bump openai-codex from version 0.169.0 to 0.172.0 in pyproject.toml - Keep other dependencies unchanged - Ensure compatibility with latest openai-codex features and fixes * fix(daemon): discover parent dotenv and isolate listeners Restore parent-directory environment discovery in workers while retaining system precedence. Partition the default supervisor profile and lock by the configured bind address and port.
107 lines
4 KiB
Python
107 lines
4 KiB
Python
"""Native DashScope recognition of complete audio recordings."""
|
|
|
|
import asyncio
|
|
import base64
|
|
import re
|
|
|
|
from .base_asr import BaseASR
|
|
from ...core.registry import R
|
|
from ...schema.speech import ASRResult, AudioFormat
|
|
from ...utils.dashscope_speech import DEFAULT_DASHSCOPE_BASE_URL, DashScopeSpeechClient
|
|
|
|
DEFAULT_DASHSCOPE_ASR_MODEL = "qwen-audio-3.1-asr-flash"
|
|
|
|
|
|
@R.register("dashscope")
|
|
class DashScopeASR(BaseASR):
|
|
"""Use Qwen-Audio-ASR over the native HTTP API."""
|
|
|
|
def __init__(
|
|
self,
|
|
model: str = DEFAULT_DASHSCOPE_ASR_MODEL,
|
|
parameters: dict | None = None,
|
|
api_key: str = "",
|
|
base_url: str = DEFAULT_DASHSCOPE_BASE_URL,
|
|
timeout: float = 60,
|
|
**kwargs,
|
|
):
|
|
super().__init__(**kwargs)
|
|
self.transport = DashScopeSpeechClient(api_key=api_key, base_url=base_url, timeout=timeout)
|
|
self.model = model
|
|
self.parameters = dict(parameters or {})
|
|
|
|
async def _start(self) -> None:
|
|
self.transport.start()
|
|
|
|
async def _close(self) -> None:
|
|
await self.transport.close()
|
|
|
|
async def transcribe(
|
|
self,
|
|
audio: bytes,
|
|
*,
|
|
audio_format: AudioFormat = "wav",
|
|
sample_rate: int | None = None,
|
|
**kwargs,
|
|
) -> ASRResult:
|
|
if not isinstance(audio, bytes) or not audio:
|
|
raise ValueError("audio must be non-empty bytes")
|
|
if audio_format not in ("wav", "mp3", "pcm", "opus"):
|
|
raise ValueError(f"Unsupported audio format: {audio_format}")
|
|
if sample_rate is not None and (
|
|
not isinstance(sample_rate, int) or isinstance(sample_rate, bool) or sample_rate <= 0
|
|
):
|
|
raise ValueError("sample_rate must be positive")
|
|
headers = self.transport.headers()
|
|
parameters = {**self.parameters, **kwargs, "format": audio_format}
|
|
if sample_rate is not None:
|
|
parameters["sample_rate"] = str(sample_rate)
|
|
mime = "audio/mpeg" if audio_format == "mp3" else f"audio/{audio_format}"
|
|
data = f"data:{mime};base64,{base64.b64encode(audio).decode('ascii')}"
|
|
await self.start()
|
|
assert self.transport.client is not None
|
|
async with asyncio.timeout(self.transport.options.timeout):
|
|
response = await self.transport.client.post(
|
|
"services/aigc/multimodal-generation/generation",
|
|
headers=headers,
|
|
json={
|
|
"model": self.model,
|
|
"input": {
|
|
"messages": [
|
|
{"role": "user", "content": [{"type": "input_audio", "input_audio": {"data": data}}]},
|
|
],
|
|
},
|
|
"parameters": parameters,
|
|
},
|
|
)
|
|
try:
|
|
body = response.json()
|
|
except ValueError:
|
|
await self.transport.check_response(response)
|
|
raise
|
|
# Only this explicit no-words response is a normal empty transcription.
|
|
no_words = (
|
|
response.status_code in (200, 400)
|
|
and isinstance(body, dict)
|
|
and (
|
|
body.get("code") == "ASR_RESPONSE_HAVE_NO_WORDS"
|
|
or (
|
|
body.get("code") == "CLIENT_ERROR"
|
|
and re.search(r"\bASR_RESPONSE_HAVE_NO_WORDS\b", str(body.get("message", "")))
|
|
)
|
|
)
|
|
)
|
|
if not no_words:
|
|
await self.transport.check_response(response)
|
|
self.transport.check_error(body)
|
|
output = body.get("output") or {}
|
|
text = "" if no_words else output.get("text", (output.get("sentence") or {}).get("text"))
|
|
if not isinstance(text, str):
|
|
raise RuntimeError("DashScope ASR returned no transcription text")
|
|
return ASRResult(
|
|
text=text,
|
|
model=self.model,
|
|
request_id=body.get("request_id") or "",
|
|
usage=body.get("usage") or {},
|
|
raw=body,
|
|
)
|