Skip to content

Commit 94ee19d

Browse files
authored
feat: Support more params for create room (#237)
1 parent c5e56f7 commit 94ee19d

File tree

1 file changed

+58
-13
lines changed

1 file changed

+58
-13
lines changed

cozepy/audio/rooms/__init__.py

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,36 @@
22

33
from cozepy.model import CozeModel
44
from cozepy.request import Requester
5-
from cozepy.util import remove_url_trailing_slash
5+
from cozepy.util import remove_none_values, remove_url_trailing_slash
6+
7+
8+
class RoomAudioConfig(CozeModel):
9+
# 房间音频编码格式,支持设置为:
10+
# AACLC: AAC-LC 编码格式。
11+
# G711A: G711A 编码格式。
12+
# OPUS: (默认)Opus 编码格式。
13+
# G722: G.722 编码格式。
14+
codec: Optional[str]
15+
16+
17+
class RoomVideoConfig(CozeModel):
18+
# 房间视频编码格式,支持设置为:
19+
# H264:(默认)H264 编码格式。
20+
# BYTEVC1: 火山引擎自研的视频编码格式。
21+
codec: Optional[str]
22+
# 房间视频流类型, 支持 main 和 screen。
23+
# main: 主流,包括通过摄像头/麦克风的内部采集机制获取的流,以及通过自定义采集方式获取的流。
24+
# screen: 屏幕流,用于屏幕共享或屏幕录制的视频流。
25+
stream_video_type: Optional[str]
26+
27+
28+
class RoomConfig(CozeModel):
29+
# The audio config of the room.
30+
audio_config: Optional[RoomAudioConfig]
31+
# The video config of the room.
32+
video_config: Optional[RoomVideoConfig]
33+
# 自定义开场白
34+
prologue_content: Optional[str]
635

736

837
class CreateRoomResp(CozeModel):
@@ -32,6 +61,8 @@ def create(
3261
voice_id: Optional[str] = None,
3362
conversation_id: Optional[str] = None,
3463
uid: Optional[str] = None,
64+
workflow_id: Optional[str] = None,
65+
config: Optional[RoomConfig] = None,
3566
) -> CreateRoomResp:
3667
"""
3768
create rtc room
@@ -40,15 +71,21 @@ def create(
4071
:param voice_id: The voice id of the voice.
4172
:param conversation_id: The id of the conversation.
4273
:param uid: The id of the user. if not provided, it will be generated by the server.
74+
:param workflow_id: The id of the workflow.
75+
:param config: The config of the room.
4376
:return: create room result
4477
"""
4578
url = f"{self._base_url}/v1/audio/rooms"
46-
body = {
47-
"bot_id": bot_id,
48-
"voice_id": voice_id,
49-
"conversation_id": conversation_id,
50-
"uid": uid,
51-
}
79+
body = remove_none_values(
80+
{
81+
"bot_id": bot_id,
82+
"voice_id": voice_id,
83+
"conversation_id": conversation_id,
84+
"uid": uid,
85+
"workflow_id": workflow_id,
86+
"config": config.model_dump() if config else None,
87+
}
88+
)
5289
return self._requester.request("post", url, stream=False, cast=CreateRoomResp, body=body)
5390

5491

@@ -68,6 +105,8 @@ async def create(
68105
voice_id: Optional[str] = None,
69106
conversation_id: Optional[str] = None,
70107
uid: Optional[str] = None,
108+
workflow_id: Optional[str] = None,
109+
config: Optional[RoomConfig] = None,
71110
) -> CreateRoomResp:
72111
"""
73112
create rtc room
@@ -76,13 +115,19 @@ async def create(
76115
:param voice_id: The voice id of the voice.
77116
:param conversation_id: The id of the conversation.
78117
:param uid: The id of the user. if not provided, it will be generated by the server.
118+
:param workflow_id: The id of the workflow.
119+
:param config: The config of the room.
79120
:return: create room result
80121
"""
81122
url = f"{self._base_url}/v1/audio/rooms"
82-
body = {
83-
"bot_id": bot_id,
84-
"voice_id": voice_id,
85-
"conversation_id": conversation_id,
86-
"uid": uid,
87-
}
123+
body = remove_none_values(
124+
{
125+
"bot_id": bot_id,
126+
"voice_id": voice_id,
127+
"conversation_id": conversation_id,
128+
"uid": uid,
129+
"workflow_id": workflow_id,
130+
"config": config.model_dump() if config else None,
131+
}
132+
)
88133
return await self._requester.arequest("post", url, stream=False, cast=CreateRoomResp, body=body)

0 commit comments

Comments
 (0)