wangzhibo
10 天以前 220e4fab27b7f419b3e89e2f2d28ae789aac09d7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from typing import TYPE_CHECKING
 
from plugins_func.register import register_function, ToolType, ActionResponse, Action
 
if TYPE_CHECKING:
    from core.connection import ConnectionHandler
 
start_repeater_function_desc = {
    "type": "function",
    "function": {
        "name": "start_repeater",
        "description": "打开泛听。省略课文时播放家长上次即时/计划任务下发的课文;还没有下发过时会提示先在家长端选一课。不要再用测试清单。name 与 self.mp3.get_list 的 files[].name 一致。repeat 是整首循环次数。speed 是播放倍率 0.5~2.0。不要用 play_music。播放期间不会聊天。",
        "parameters": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string",
                    "description": "可选。SD 卡 MP3 文件名,必须与 get_list 的 files[].name 一致;省略则播家长上次下发的课文",
                },
                "repeat": {
                    "type": "integer",
                    "description": "整首循环次数,默认 1。大于 1 且配置了 repeat_speeds 时,每一遍可以用不同倍速",
                },
                "speed": {
                    "type": "number",
                    "description": "可选。播放倍率 0.5~2.0,省略则按熟悉天数自动选择",
                },
                "power_off_after": {
                    "type": "boolean",
                    "description": "播完后是否软关机,默认 false",
                },
            },
            "required": [],
        },
    },
}
 
 
@register_function("start_repeater", start_repeater_function_desc, ToolType.SYSTEM_CTL)
async def start_repeater(
    conn: "ConnectionHandler",
    name: str = "",
    repeat: int = 1,
    power_off_after: bool = False,
    speed: float = None,
):
    from core.app_runtime.runtime import start_app_task
 
    try:
        repeat_n = int(repeat or 1)
    except (TypeError, ValueError):
        repeat_n = 1
    if repeat_n < 1:
        repeat_n = 1
 
    params = {
        "name": name,
        "repeat": repeat_n,
        "power_off_after": bool(power_off_after),
    }
    if speed is not None and speed != "":
        params["speed"] = speed
 
    result = await start_app_task(
        conn,
        "english_learning",
        "repeater",
        params,
        source="voice",
    )
    if result.action in (Action.ERROR, Action.RESPONSE):
        return ActionResponse(
            action=Action.RESPONSE,
            result=result.result,
            response=result.response or "无法开始泛听",
        )
    return ActionResponse(
        action=Action.NONE,
        result=result.result,
        response=result.response,
    )