feat: add DashScope bidirectional streaming TTS adapter
This commit is contained in:
@@ -55,6 +55,8 @@ async def test_model_resource(
|
||||
values: dict,
|
||||
secrets: dict,
|
||||
) -> ModelResourceTestResult:
|
||||
if interface_type == "dashscope-tts":
|
||||
return await _test_dashscope_tts(values, secrets)
|
||||
if interface_type.startswith("xfyun-"):
|
||||
return ModelResourceTestResult(
|
||||
ok=True,
|
||||
@@ -231,3 +233,35 @@ async def _test_realtime_websocket(
|
||||
message=f"无法连接到 {provider} Realtime",
|
||||
detail=detail[:300],
|
||||
)
|
||||
|
||||
|
||||
async def _test_dashscope_tts(values: dict, secrets: dict) -> ModelResourceTestResult:
|
||||
from services.pipecat.dashscope_tts import SynthesisSession
|
||||
|
||||
started = time.perf_counter()
|
||||
session = None
|
||||
try:
|
||||
session = SynthesisSession(
|
||||
str(values.get("apiUrl") or ""), str(secrets.get("apiKey") or ""),
|
||||
str(values.get("modelId") or ""), str(values.get("voice") or ""),
|
||||
)
|
||||
async with asyncio.timeout(TEST_TIMEOUT_SECONDS):
|
||||
await session.start()
|
||||
await session.text("你好,这是语音合成测试。")
|
||||
await session.finish()
|
||||
async for _ in session.audio():
|
||||
pass
|
||||
return ModelResourceTestResult(
|
||||
ok=True, message="百炼 TTS 合成成功",
|
||||
detail="已收到 PCM 音频及 task-finished",
|
||||
latency_ms=round((time.perf_counter() - started) * 1000),
|
||||
)
|
||||
except Exception as exc:
|
||||
detail = "合成测试超时" if isinstance(exc, TimeoutError) else str(exc)
|
||||
for secret in secrets.values():
|
||||
if secret:
|
||||
detail = detail.replace(str(secret), "***")
|
||||
return ModelResourceTestResult(ok=False, message="百炼 TTS 合成失败", detail=detail[:300])
|
||||
finally:
|
||||
if session:
|
||||
await session.close()
|
||||
|
||||
Reference in New Issue
Block a user