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.
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
"""Abstract component for speech synthesis."""
|
|
|
|
from abc import abstractmethod
|
|
from collections.abc import AsyncIterator
|
|
from contextlib import aclosing
|
|
|
|
from ..base import BaseComponent
|
|
from ...enumeration import ComponentEnum
|
|
from ...schema.speech import TTSResult
|
|
|
|
|
|
class BaseTTS(BaseComponent):
|
|
"""Synthesize audio without owning playback or file access."""
|
|
|
|
component_type = ComponentEnum.TTS
|
|
|
|
async def synthesize(self, text: str, **kwargs) -> TTSResult:
|
|
"""Collect the same stream used by incremental consumers."""
|
|
audio, result = [], None
|
|
async with aclosing(self.stream(text, **kwargs)) as stream:
|
|
async for chunk in stream:
|
|
audio.append(chunk.audio)
|
|
result = chunk
|
|
if chunk.is_last:
|
|
break
|
|
if result is None or not result.is_last:
|
|
raise RuntimeError("TTS stream ended without completion")
|
|
payload = b"".join(audio)
|
|
if not payload:
|
|
raise RuntimeError("TTS completed without audio")
|
|
return result.model_copy(update={"audio": payload})
|
|
|
|
@abstractmethod
|
|
def stream(self, text: str, **kwargs) -> AsyncIterator[TTSResult]:
|
|
"""Yield encoded audio fragments and a final completion result.
|
|
|
|
Consumers that stop early must close the iterator, e.g. with aclosing.
|
|
"""
|