agentscope-runtime 0.2.0b2__py3-none-any.whl → 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentscope_runtime/adapters/__init__.py +0 -0
- agentscope_runtime/adapters/agentscope/__init__.py +0 -0
- agentscope_runtime/adapters/agentscope/long_term_memory/__init__.py +6 -0
- agentscope_runtime/adapters/agentscope/long_term_memory/_long_term_memory_adapter.py +258 -0
- agentscope_runtime/adapters/agentscope/memory/__init__.py +6 -0
- agentscope_runtime/adapters/agentscope/memory/_memory_adapter.py +152 -0
- agentscope_runtime/adapters/agentscope/message.py +535 -0
- agentscope_runtime/adapters/agentscope/stream.py +506 -0
- agentscope_runtime/adapters/agentscope/tool/__init__.py +9 -0
- agentscope_runtime/adapters/agentscope/tool/sandbox_tool.py +69 -0
- agentscope_runtime/adapters/agentscope/tool/tool.py +233 -0
- agentscope_runtime/adapters/autogen/__init__.py +0 -0
- agentscope_runtime/adapters/autogen/tool/__init__.py +7 -0
- agentscope_runtime/adapters/autogen/tool/tool.py +211 -0
- agentscope_runtime/adapters/text/__init__.py +0 -0
- agentscope_runtime/adapters/text/stream.py +29 -0
- agentscope_runtime/common/collections/redis_mapping.py +4 -1
- agentscope_runtime/common/container_clients/fc_client.py +855 -0
- agentscope_runtime/common/utils/__init__.py +0 -0
- agentscope_runtime/common/utils/lazy_loader.py +57 -0
- agentscope_runtime/engine/__init__.py +25 -18
- agentscope_runtime/engine/app/agent_app.py +161 -91
- agentscope_runtime/engine/app/base_app.py +4 -118
- agentscope_runtime/engine/constant.py +8 -0
- agentscope_runtime/engine/deployers/__init__.py +8 -0
- agentscope_runtime/engine/deployers/adapter/__init__.py +2 -0
- agentscope_runtime/engine/deployers/adapter/a2a/a2a_adapter_utils.py +0 -21
- agentscope_runtime/engine/deployers/adapter/a2a/a2a_protocol_adapter.py +28 -9
- agentscope_runtime/engine/deployers/adapter/responses/__init__.py +2 -0
- agentscope_runtime/engine/deployers/adapter/responses/response_api_adapter_utils.py +5 -2
- agentscope_runtime/engine/deployers/adapter/responses/response_api_protocol_adapter.py +1 -1
- agentscope_runtime/engine/deployers/agentrun_deployer.py +2541 -0
- agentscope_runtime/engine/deployers/cli_fc_deploy.py +1 -1
- agentscope_runtime/engine/deployers/kubernetes_deployer.py +9 -21
- agentscope_runtime/engine/deployers/local_deployer.py +47 -74
- agentscope_runtime/engine/deployers/modelstudio_deployer.py +216 -50
- agentscope_runtime/engine/deployers/utils/app_runner_utils.py +29 -0
- agentscope_runtime/engine/deployers/utils/detached_app.py +510 -0
- agentscope_runtime/engine/deployers/utils/docker_image_utils/__init__.py +1 -1
- agentscope_runtime/engine/deployers/utils/docker_image_utils/dockerfile_generator.py +1 -1
- agentscope_runtime/engine/deployers/utils/docker_image_utils/{runner_image_factory.py → image_factory.py} +121 -61
- agentscope_runtime/engine/deployers/utils/package.py +693 -0
- agentscope_runtime/engine/deployers/utils/service_utils/__init__.py +0 -5
- agentscope_runtime/engine/deployers/utils/service_utils/fastapi_factory.py +301 -282
- agentscope_runtime/engine/deployers/utils/service_utils/fastapi_templates.py +2 -4
- agentscope_runtime/engine/deployers/utils/service_utils/process_manager.py +23 -1
- agentscope_runtime/engine/deployers/utils/templates/app_main.py.j2 +84 -0
- agentscope_runtime/engine/deployers/utils/templates/runner_main.py.j2 +95 -0
- agentscope_runtime/engine/deployers/utils/{service_utils → templates}/standalone_main.py.j2 +0 -45
- agentscope_runtime/engine/deployers/utils/wheel_packager.py +119 -18
- agentscope_runtime/engine/helpers/runner.py +40 -0
- agentscope_runtime/engine/runner.py +171 -130
- agentscope_runtime/engine/schemas/agent_schemas.py +114 -3
- agentscope_runtime/engine/schemas/modelstudio_llm.py +4 -2
- agentscope_runtime/engine/schemas/oai_llm.py +23 -23
- agentscope_runtime/engine/schemas/response_api.py +65 -0
- agentscope_runtime/engine/schemas/session.py +24 -0
- agentscope_runtime/engine/services/__init__.py +0 -9
- agentscope_runtime/engine/services/agent_state/__init__.py +16 -0
- agentscope_runtime/engine/services/agent_state/redis_state_service.py +113 -0
- agentscope_runtime/engine/services/agent_state/state_service.py +179 -0
- agentscope_runtime/engine/services/memory/__init__.py +24 -0
- agentscope_runtime/engine/services/{mem0_memory_service.py → memory/mem0_memory_service.py} +17 -13
- agentscope_runtime/engine/services/{memory_service.py → memory/memory_service.py} +28 -7
- agentscope_runtime/engine/services/{redis_memory_service.py → memory/redis_memory_service.py} +1 -1
- agentscope_runtime/engine/services/{reme_personal_memory_service.py → memory/reme_personal_memory_service.py} +9 -6
- agentscope_runtime/engine/services/{reme_task_memory_service.py → memory/reme_task_memory_service.py} +2 -2
- agentscope_runtime/engine/services/{tablestore_memory_service.py → memory/tablestore_memory_service.py} +12 -18
- agentscope_runtime/engine/services/sandbox/__init__.py +13 -0
- agentscope_runtime/engine/services/{sandbox_service.py → sandbox/sandbox_service.py} +86 -71
- agentscope_runtime/engine/services/session_history/__init__.py +23 -0
- agentscope_runtime/engine/services/{redis_session_history_service.py → session_history/redis_session_history_service.py} +3 -2
- agentscope_runtime/engine/services/{session_history_service.py → session_history/session_history_service.py} +44 -34
- agentscope_runtime/engine/services/{tablestore_session_history_service.py → session_history/tablestore_session_history_service.py} +14 -19
- agentscope_runtime/engine/services/utils/tablestore_service_utils.py +2 -2
- agentscope_runtime/engine/tracing/base.py +10 -9
- agentscope_runtime/engine/tracing/message_util.py +1 -1
- agentscope_runtime/engine/tracing/tracing_util.py +7 -2
- agentscope_runtime/engine/tracing/wrapper.py +49 -31
- agentscope_runtime/sandbox/__init__.py +10 -2
- agentscope_runtime/sandbox/box/agentbay/__init__.py +4 -0
- agentscope_runtime/sandbox/box/agentbay/agentbay_sandbox.py +559 -0
- agentscope_runtime/sandbox/box/base/base_sandbox.py +12 -0
- agentscope_runtime/sandbox/box/browser/browser_sandbox.py +115 -11
- agentscope_runtime/sandbox/box/cloud/__init__.py +4 -0
- agentscope_runtime/sandbox/box/cloud/cloud_sandbox.py +254 -0
- agentscope_runtime/sandbox/box/filesystem/filesystem_sandbox.py +66 -0
- agentscope_runtime/sandbox/box/gui/gui_sandbox.py +42 -0
- agentscope_runtime/sandbox/box/mobile/__init__.py +4 -0
- agentscope_runtime/sandbox/box/mobile/box/__init__.py +0 -0
- agentscope_runtime/sandbox/box/mobile/mobile_sandbox.py +216 -0
- agentscope_runtime/sandbox/box/training_box/training_box.py +2 -2
- agentscope_runtime/sandbox/client/http_client.py +1 -0
- agentscope_runtime/sandbox/enums.py +2 -0
- agentscope_runtime/sandbox/manager/sandbox_manager.py +15 -2
- agentscope_runtime/sandbox/manager/server/app.py +12 -0
- agentscope_runtime/sandbox/manager/server/config.py +19 -0
- agentscope_runtime/sandbox/model/manager_config.py +79 -2
- agentscope_runtime/sandbox/utils.py +0 -18
- agentscope_runtime/tools/RAGs/__init__.py +0 -0
- agentscope_runtime/tools/RAGs/modelstudio_rag.py +377 -0
- agentscope_runtime/tools/RAGs/modelstudio_rag_lite.py +219 -0
- agentscope_runtime/tools/__init__.py +119 -0
- agentscope_runtime/tools/_constants.py +18 -0
- agentscope_runtime/tools/alipay/__init__.py +4 -0
- agentscope_runtime/tools/alipay/base.py +334 -0
- agentscope_runtime/tools/alipay/payment.py +835 -0
- agentscope_runtime/tools/alipay/subscribe.py +551 -0
- agentscope_runtime/tools/base.py +264 -0
- agentscope_runtime/tools/cli/__init__.py +0 -0
- agentscope_runtime/tools/cli/modelstudio_mcp_server.py +78 -0
- agentscope_runtime/tools/generations/__init__.py +75 -0
- agentscope_runtime/tools/generations/async_image_to_video.py +350 -0
- agentscope_runtime/tools/generations/async_image_to_video_wan25.py +366 -0
- agentscope_runtime/tools/generations/async_speech_to_video.py +422 -0
- agentscope_runtime/tools/generations/async_text_to_video.py +320 -0
- agentscope_runtime/tools/generations/async_text_to_video_wan25.py +334 -0
- agentscope_runtime/tools/generations/image_edit.py +208 -0
- agentscope_runtime/tools/generations/image_edit_wan25.py +193 -0
- agentscope_runtime/tools/generations/image_generation.py +202 -0
- agentscope_runtime/tools/generations/image_generation_wan25.py +201 -0
- agentscope_runtime/tools/generations/image_style_repaint.py +208 -0
- agentscope_runtime/tools/generations/image_to_video.py +233 -0
- agentscope_runtime/tools/generations/qwen_image_edit.py +205 -0
- agentscope_runtime/tools/generations/qwen_image_generation.py +214 -0
- agentscope_runtime/tools/generations/qwen_text_to_speech.py +154 -0
- agentscope_runtime/tools/generations/speech_to_text.py +260 -0
- agentscope_runtime/tools/generations/speech_to_video.py +314 -0
- agentscope_runtime/tools/generations/text_to_video.py +221 -0
- agentscope_runtime/tools/mcp_wrapper.py +215 -0
- agentscope_runtime/tools/realtime_clients/__init__.py +13 -0
- agentscope_runtime/tools/realtime_clients/asr_client.py +27 -0
- agentscope_runtime/tools/realtime_clients/azure_asr_client.py +195 -0
- agentscope_runtime/tools/realtime_clients/azure_tts_client.py +383 -0
- agentscope_runtime/tools/realtime_clients/modelstudio_asr_client.py +151 -0
- agentscope_runtime/tools/realtime_clients/modelstudio_tts_client.py +199 -0
- agentscope_runtime/tools/realtime_clients/realtime_tool.py +55 -0
- agentscope_runtime/tools/realtime_clients/tts_client.py +33 -0
- agentscope_runtime/tools/searches/__init__.py +3 -0
- agentscope_runtime/tools/searches/modelstudio_search.py +877 -0
- agentscope_runtime/tools/searches/modelstudio_search_lite.py +310 -0
- agentscope_runtime/tools/utils/__init__.py +0 -0
- agentscope_runtime/tools/utils/api_key_util.py +45 -0
- agentscope_runtime/tools/utils/crypto_utils.py +99 -0
- agentscope_runtime/tools/utils/mcp_util.py +35 -0
- agentscope_runtime/version.py +1 -1
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0.dist-info}/METADATA +240 -168
- agentscope_runtime-1.0.0.dist-info/RECORD +240 -0
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0.dist-info}/entry_points.txt +1 -0
- agentscope_runtime/engine/agents/__init__.py +0 -2
- agentscope_runtime/engine/agents/agentscope_agent.py +0 -488
- agentscope_runtime/engine/agents/agno_agent.py +0 -220
- agentscope_runtime/engine/agents/autogen_agent.py +0 -250
- agentscope_runtime/engine/agents/base_agent.py +0 -29
- agentscope_runtime/engine/agents/langgraph_agent.py +0 -59
- agentscope_runtime/engine/agents/utils.py +0 -53
- agentscope_runtime/engine/deployers/utils/package_project_utils.py +0 -1163
- agentscope_runtime/engine/deployers/utils/service_utils/service_config.py +0 -75
- agentscope_runtime/engine/deployers/utils/service_utils/service_factory.py +0 -220
- agentscope_runtime/engine/helpers/helper.py +0 -179
- agentscope_runtime/engine/schemas/context.py +0 -54
- agentscope_runtime/engine/services/context_manager.py +0 -164
- agentscope_runtime/engine/services/environment_manager.py +0 -50
- agentscope_runtime/engine/services/manager.py +0 -174
- agentscope_runtime/engine/services/rag_service.py +0 -195
- agentscope_runtime/engine/services/tablestore_rag_service.py +0 -143
- agentscope_runtime/sandbox/tools/__init__.py +0 -12
- agentscope_runtime/sandbox/tools/base/__init__.py +0 -8
- agentscope_runtime/sandbox/tools/base/tool.py +0 -52
- agentscope_runtime/sandbox/tools/browser/__init__.py +0 -57
- agentscope_runtime/sandbox/tools/browser/tool.py +0 -597
- agentscope_runtime/sandbox/tools/filesystem/__init__.py +0 -32
- agentscope_runtime/sandbox/tools/filesystem/tool.py +0 -319
- agentscope_runtime/sandbox/tools/function_tool.py +0 -321
- agentscope_runtime/sandbox/tools/gui/__init__.py +0 -7
- agentscope_runtime/sandbox/tools/gui/tool.py +0 -77
- agentscope_runtime/sandbox/tools/mcp_tool.py +0 -195
- agentscope_runtime/sandbox/tools/sandbox_tool.py +0 -104
- agentscope_runtime/sandbox/tools/tool.py +0 -238
- agentscope_runtime/sandbox/tools/utils.py +0 -68
- agentscope_runtime-0.2.0b2.dist-info/RECORD +0 -183
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0.dist-info}/WHEEL +0 -0
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0.dist-info}/licenses/LICENSE +0 -0
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# pylint:disable=arguments-renamed
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import logging
|
|
6
|
+
import time
|
|
7
|
+
from typing import Optional, Callable, Any
|
|
8
|
+
|
|
9
|
+
from dashscope.audio.tts_v2.speech_synthesizer import (
|
|
10
|
+
SpeechSynthesizer,
|
|
11
|
+
ResultCallback,
|
|
12
|
+
AudioFormat,
|
|
13
|
+
)
|
|
14
|
+
from pydantic import BaseModel
|
|
15
|
+
|
|
16
|
+
from .realtime_tool import (
|
|
17
|
+
RealtimeState,
|
|
18
|
+
)
|
|
19
|
+
from .tts_client import TtsClient
|
|
20
|
+
from ...engine.schemas.realtime import ModelstudioTtsConfig
|
|
21
|
+
|
|
22
|
+
logger = logging.getLogger(__name__)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ModelstudioTtsCallbacks(BaseModel):
|
|
26
|
+
on_open: Optional[Callable] = None
|
|
27
|
+
on_complete: Optional[Callable] = None
|
|
28
|
+
on_error: Optional[Callable] = None
|
|
29
|
+
on_close: Optional[Callable] = None
|
|
30
|
+
on_event: Optional[Callable] = None
|
|
31
|
+
on_data: Optional[Callable] = None
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ModelstudioTtsClient(TtsClient, ResultCallback):
|
|
35
|
+
def __init__(
|
|
36
|
+
self,
|
|
37
|
+
config: ModelstudioTtsConfig,
|
|
38
|
+
callbacks: ModelstudioTtsCallbacks,
|
|
39
|
+
):
|
|
40
|
+
super().__init__(config, callbacks)
|
|
41
|
+
self.tts_request_id = None
|
|
42
|
+
self.first_request_time = None
|
|
43
|
+
self.is_first_audio_data = True
|
|
44
|
+
self.data_index = 0
|
|
45
|
+
self.synthesizer = SpeechSynthesizer(
|
|
46
|
+
model=config.model,
|
|
47
|
+
voice=config.voice,
|
|
48
|
+
format=self.to_format(config.sample_rate),
|
|
49
|
+
callback=self,
|
|
50
|
+
)
|
|
51
|
+
self.callbacks = callbacks
|
|
52
|
+
self.state = RealtimeState.IDLE
|
|
53
|
+
|
|
54
|
+
logger.info(
|
|
55
|
+
f"modelstudio_tts_config: {json.dumps(self.config.model_dump())}",
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
def start(self, **kwargs: Any) -> None:
|
|
59
|
+
logger.info("tts_start")
|
|
60
|
+
self.tts_request_id = None
|
|
61
|
+
self.first_request_time = None
|
|
62
|
+
self.is_first_audio_data = True
|
|
63
|
+
self.data_index = 0
|
|
64
|
+
|
|
65
|
+
self.synthesizer.streaming_call(" ")
|
|
66
|
+
|
|
67
|
+
def stop(self, **kwargs: Any) -> None:
|
|
68
|
+
if self.state == RealtimeState.IDLE:
|
|
69
|
+
return
|
|
70
|
+
|
|
71
|
+
logger.info(f"tts_stop: tts_request_id={self.tts_request_id}")
|
|
72
|
+
|
|
73
|
+
self.synthesizer.streaming_complete()
|
|
74
|
+
|
|
75
|
+
def async_stop(self, **kwargs: Any) -> None:
|
|
76
|
+
if self.state == RealtimeState.IDLE:
|
|
77
|
+
return
|
|
78
|
+
|
|
79
|
+
logger.info(f"tts_async_stop: tts_request_id={self.tts_request_id}")
|
|
80
|
+
|
|
81
|
+
self.synthesizer.async_streaming_complete()
|
|
82
|
+
|
|
83
|
+
def close(self, **kwargs: Any) -> None:
|
|
84
|
+
self.callbacks = None
|
|
85
|
+
if self.state == RealtimeState.IDLE:
|
|
86
|
+
return
|
|
87
|
+
|
|
88
|
+
self.state = RealtimeState.IDLE
|
|
89
|
+
|
|
90
|
+
logger.info(f"tts_close: tts_request_id={self.tts_request_id}")
|
|
91
|
+
|
|
92
|
+
self.synthesizer.streaming_cancel()
|
|
93
|
+
|
|
94
|
+
def send_text_data(self, text: str) -> None:
|
|
95
|
+
if self.state == RealtimeState.IDLE:
|
|
96
|
+
return
|
|
97
|
+
|
|
98
|
+
if self.first_request_time is None:
|
|
99
|
+
self.first_request_time = int(round(time.time() * 1000))
|
|
100
|
+
|
|
101
|
+
self.synthesizer.streaming_call(text)
|
|
102
|
+
|
|
103
|
+
def on_open(self) -> None:
|
|
104
|
+
self.state = RealtimeState.RUNNING
|
|
105
|
+
|
|
106
|
+
logger.info(
|
|
107
|
+
f"tts_on_open: tts_request_id={self.tts_request_id},"
|
|
108
|
+
f" chat_id={self.config.chat_id}",
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
if self.callbacks and self.callbacks.on_open:
|
|
112
|
+
self.callbacks.on_open()
|
|
113
|
+
|
|
114
|
+
def on_complete(self) -> None:
|
|
115
|
+
self.state = RealtimeState.IDLE
|
|
116
|
+
|
|
117
|
+
logger.info(
|
|
118
|
+
f"tts_on_complete: tts_request_id={self.tts_request_id},"
|
|
119
|
+
f" chat_id={self.config.chat_id}",
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
if self.callbacks and self.callbacks.on_complete:
|
|
123
|
+
self.callbacks.on_complete(self.config.chat_id)
|
|
124
|
+
|
|
125
|
+
def on_error(self, message: str) -> None:
|
|
126
|
+
self.state = RealtimeState.IDLE
|
|
127
|
+
|
|
128
|
+
logger.error(
|
|
129
|
+
f"tts_on_on_error: tts_request_id={self.tts_request_id}, "
|
|
130
|
+
f"message={message}, chat_id={self.config.chat_id}",
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
if self.callbacks and self.callbacks.on_error:
|
|
134
|
+
self.callbacks.on_error(message)
|
|
135
|
+
|
|
136
|
+
def on_close(self) -> None:
|
|
137
|
+
self.state = RealtimeState.IDLE
|
|
138
|
+
|
|
139
|
+
logger.info(
|
|
140
|
+
f"tts_on_close: tts_request_id={self.tts_request_id},"
|
|
141
|
+
f" chat_id={self.config.chat_id}",
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
if self.callbacks and self.callbacks.on_close:
|
|
145
|
+
self.callbacks.on_close()
|
|
146
|
+
|
|
147
|
+
def on_event(self, message: str) -> None:
|
|
148
|
+
# logger.info(
|
|
149
|
+
# f"tts_on_event: tts_request_id={self.tts_request_id}, "
|
|
150
|
+
# f"message={message}, chat_id={self.config.chat_id}",
|
|
151
|
+
# )
|
|
152
|
+
|
|
153
|
+
event = json.loads(message)
|
|
154
|
+
if "header" in event and "task_id" in event["header"]:
|
|
155
|
+
tts_request_id = event["header"]["task_id"]
|
|
156
|
+
if self.tts_request_id != tts_request_id:
|
|
157
|
+
self.tts_request_id = tts_request_id
|
|
158
|
+
|
|
159
|
+
if self.callbacks and self.callbacks.on_event:
|
|
160
|
+
self.callbacks.on_event(message)
|
|
161
|
+
|
|
162
|
+
def on_data(self, data: bytes) -> None:
|
|
163
|
+
# logger.info(
|
|
164
|
+
# f"tts_on_data: tts_request_id={self.tts_request_id}, "
|
|
165
|
+
# f"data_size={len(data)}, chat_id={self.config.chat_id},
|
|
166
|
+
# data_index={self.data_index}",
|
|
167
|
+
# )
|
|
168
|
+
|
|
169
|
+
if (
|
|
170
|
+
self.is_first_audio_data is True
|
|
171
|
+
and self.first_request_time is not None
|
|
172
|
+
):
|
|
173
|
+
logger.info(
|
|
174
|
+
f"tts_first_delay: "
|
|
175
|
+
f"{int(round(time.time() * 1000)) - self.first_request_time}",
|
|
176
|
+
)
|
|
177
|
+
self.is_first_audio_data = False
|
|
178
|
+
|
|
179
|
+
if self.callbacks and self.callbacks.on_data:
|
|
180
|
+
self.callbacks.on_data(data, self.config.chat_id, self.data_index)
|
|
181
|
+
|
|
182
|
+
self.data_index += 1
|
|
183
|
+
|
|
184
|
+
@staticmethod
|
|
185
|
+
def to_format(sample_rate: int) -> AudioFormat:
|
|
186
|
+
if sample_rate == 8000:
|
|
187
|
+
return AudioFormat.PCM_8000HZ_MONO_16BIT
|
|
188
|
+
elif sample_rate == 16000:
|
|
189
|
+
return AudioFormat.PCM_16000HZ_MONO_16BIT
|
|
190
|
+
elif sample_rate == 22050:
|
|
191
|
+
return AudioFormat.PCM_22050HZ_MONO_16BIT
|
|
192
|
+
elif sample_rate == 24000:
|
|
193
|
+
return AudioFormat.PCM_24000HZ_MONO_16BIT
|
|
194
|
+
elif sample_rate == 44100:
|
|
195
|
+
return AudioFormat.PCM_44100HZ_MONO_16BIT
|
|
196
|
+
elif sample_rate == 48000:
|
|
197
|
+
return AudioFormat.PCM_48000HZ_MONO_16BIT
|
|
198
|
+
else:
|
|
199
|
+
raise ValueError("invalid sample rate")
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from abc import abstractmethod
|
|
3
|
+
from enum import Enum
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from pydantic import BaseModel
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class RealtimeState(Enum):
|
|
10
|
+
IDLE = "idle"
|
|
11
|
+
RUNNING = "running"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class RealtimeType(Enum):
|
|
15
|
+
TTS = "tts"
|
|
16
|
+
ASR = "asr"
|
|
17
|
+
VOICE_CHAT = "voice_chat"
|
|
18
|
+
VIDEO_CHAT = "video_chat"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class RealtimeComponent:
|
|
22
|
+
"""
|
|
23
|
+
Base class for realtime_client components
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
realtime_type: RealtimeType
|
|
27
|
+
config: BaseModel
|
|
28
|
+
callbacks: BaseModel
|
|
29
|
+
state: RealtimeState
|
|
30
|
+
|
|
31
|
+
def __init__(
|
|
32
|
+
self,
|
|
33
|
+
realtime_type: RealtimeType,
|
|
34
|
+
config: BaseModel,
|
|
35
|
+
callbacks: BaseModel,
|
|
36
|
+
):
|
|
37
|
+
self.realtime_type = realtime_type
|
|
38
|
+
self.config = config
|
|
39
|
+
self.callbacks = callbacks
|
|
40
|
+
self.state = RealtimeState.IDLE
|
|
41
|
+
|
|
42
|
+
@abstractmethod
|
|
43
|
+
def start(self, **kwargs: Any) -> None:
|
|
44
|
+
pass
|
|
45
|
+
|
|
46
|
+
@abstractmethod
|
|
47
|
+
def stop(self, **kwargs: Any) -> None:
|
|
48
|
+
pass
|
|
49
|
+
|
|
50
|
+
@abstractmethod
|
|
51
|
+
def close(self, **kwargs: Any) -> None:
|
|
52
|
+
pass
|
|
53
|
+
|
|
54
|
+
def get_state(self) -> RealtimeState:
|
|
55
|
+
return self.state
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from typing import Any, Optional
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel
|
|
5
|
+
|
|
6
|
+
from .realtime_tool import (
|
|
7
|
+
RealtimeComponent,
|
|
8
|
+
RealtimeType,
|
|
9
|
+
)
|
|
10
|
+
from ...engine.schemas.realtime import TtsConfig
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TtsClient(RealtimeComponent):
|
|
14
|
+
def __init__(self, config: TtsConfig, callbacks: BaseModel):
|
|
15
|
+
super().__init__(RealtimeType.TTS, config, callbacks)
|
|
16
|
+
|
|
17
|
+
def start(self, **kwargs: Any) -> None:
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
def stop(self, **kwargs: Any) -> None:
|
|
21
|
+
pass
|
|
22
|
+
|
|
23
|
+
def async_stop(self, **kwargs: Any) -> None:
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
def close(self, **kwargs: Any) -> None:
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
def send_text_data(self, data: str) -> None:
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
def set_chat_id(self, chat_id: Optional[str] = None) -> None:
|
|
33
|
+
self.config.chat_id = chat_id
|