mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-11-27 23:58:47 +00:00
Some checks failed
CI and Release / Docker / Build and test / amd64 (push) Has been cancelled
CI and Release / Docker / Build and test / arm64 (push) Has been cancelled
Security / CodeQL / Analyze python (push) Has been cancelled
CI / Python quality / Pre-commit (push) Has been cancelled
CI / Python tests / Unit Tests - py3.12 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.13 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.14 (push) Has been cancelled
CI / Python packages / Build and verify distributions (push) Has been cancelled
CI / Python quality / GitHub Actions (push) Has been cancelled
CI / Python tests / Hermes embedded - ubuntu-latest (push) Has been cancelled
CI / Python tests / Hermes embedded - windows-latest (push) Has been cancelled
CI / Python tests / Unit Tests - py3.11 (push) Has been cancelled
CI / ReMe Studio / Studio checks (push) Has been cancelled
Deploy / Documentation / Build documentation (push) Has been cancelled
CI / Windows / CLI smoke - py3.11 (push) Has been cancelled
Security / CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI and Release / Docker / Publish multi-platform tags (push) Has been cancelled
Deploy / Documentation / deploy (push) Has been cancelled
* refactor(core): reorganize the ReMe runtime and shared helpers * test(status): import the base component from its canonical module * test: remove redundant unit checks * refactor(core): use canonical runtime imports and shared CLI discovery Restore evolve behavior to the base branch and update its imports. Use Application as the runtime entry point and encode SSE in the HTTP service. * fix(cli): honor caller config when service replay is incomplete Use partial startup overrides for port probes and resolve named configs before requesting the service process working directory.
48 lines
1.8 KiB
Python
48 lines
1.8 KiB
Python
"""Speech synthesis and recognition Steps sharing in-memory audio."""
|
|
|
|
import base64
|
|
|
|
from ..base_step import BaseStep, Ref
|
|
from ...core.registry import R
|
|
from ...components.asr import BaseASR
|
|
from ...components.tts import BaseTTS
|
|
from ...enumeration import ComponentEnum
|
|
|
|
|
|
@R.register("tts_step")
|
|
class TTSStep(BaseStep):
|
|
"""Synthesize text and publish audio for the next Step or a JSON client."""
|
|
|
|
tts = Ref(BaseTTS, ComponentEnum.TTS)
|
|
|
|
async def execute(self):
|
|
assert self.context is not None
|
|
result = await self.tts.synthesize(self.context.get("text"))
|
|
self.context.data.update(audio=result.audio, audio_format=result.format, sample_rate=result.sample_rate)
|
|
metadata = result.model_dump(exclude={"audio"})
|
|
metadata["size_bytes"] = len(result.audio)
|
|
self.context.response.metadata["tts"] = metadata
|
|
self.context.response.answer = {**metadata, "audio": base64.b64encode(result.audio).decode("ascii")}
|
|
return self.context.response
|
|
|
|
|
|
@R.register("asr_step")
|
|
class ASRStep(BaseStep):
|
|
"""Transcribe raw audio from a preceding Step or Base64 from a client."""
|
|
|
|
asr = Ref(BaseASR, ComponentEnum.ASR)
|
|
|
|
async def execute(self):
|
|
assert self.context is not None
|
|
audio = self.context.get("audio")
|
|
if isinstance(audio, str):
|
|
audio = base64.b64decode(audio, validate=True)
|
|
result = await self.asr.transcribe(
|
|
audio,
|
|
audio_format=self.context.get("audio_format", "wav"),
|
|
sample_rate=self.context.get("sample_rate"),
|
|
)
|
|
self.context.data["transcription"] = result.text
|
|
self.context.response.answer = result.text
|
|
self.context.response.metadata["asr"] = result.model_dump(exclude={"raw"})
|
|
return self.context.response
|