Skip to main content
Glama

add_audio_fade

Apply fade-in and fade-out effects to audio segments in JianYing video projects to create smooth audio transitions at specified durations.

Instructions

为音频片段添加淡入淡出效果

Args: audio_segment_id: 音频片段ID,通过add_audio_segment获得 in_duration: 音频淡入时长,格式如 "1s", "500ms", "0.5s" out_duration: 音频淡出时长,格式如 "1s", "500ms", "0.5s"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
audio_segment_idYes
in_durationYes
out_durationYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataNo
messageYes
successYes

Implementation Reference

  • MCP tool handler for 'add_audio_fade': input validation, index lookup, delegates to service.
    @mcp.tool()
    def add_audio_fade(
            audio_segment_id: str,
            in_duration: str,
            out_duration: str
    ) -> ToolResponse:
        """
        为音频片段添加淡入淡出效果
    
        Args:
            audio_segment_id: 音频片段ID,通过add_audio_segment获得
            in_duration: 音频淡入时长,格式如 "1s", "500ms", "0.5s"
            out_duration: 音频淡出时长,格式如 "1s", "500ms", "0.5s"
        """
        # 参数验证
        if not in_duration or not out_duration:
            return ToolResponse(
                success=False,
                message="淡入时长和淡出时长不能为空"
            )
    
        # 简单的时间格式验证
        def validate_duration(duration: str) -> bool:
            """验证时间格式是否正确"""
            if not duration:
                return False
            # 检查是否以s或ms结尾
            if not (duration.endswith('s') or duration.endswith('ms')):
                return False
            # 检查数字部分
            try:
                if duration.endswith('ms'):
                    float(duration[:-2])
                else:
                    float(duration[:-1])
                return True
            except ValueError:
                return False
    
        if not validate_duration(in_duration):
            return ToolResponse(
                success=False,
                message=f"无效的淡入时长格式: {in_duration},正确格式如 '1s', '500ms'"
            )
    
        if not validate_duration(out_duration):
            return ToolResponse(
                success=False,
                message=f"无效的淡出时长格式: {out_duration},正确格式如 '1s', '500ms'"
            )
    
        # 通过audio_segment_id获取相关信息
        draft_id = index_manager.get_draft_id_by_audio_segment_id(audio_segment_id)
        track_info = index_manager.get_track_info_by_audio_segment_id(audio_segment_id)
    
        if not draft_id:
            return ToolResponse(
                success=False,
                message=f"未找到音频片段ID对应的草稿: {audio_segment_id}"
            )
    
        if not track_info:
            return ToolResponse(
                success=False,
                message=f"未找到音频片段ID对应的轨道信息: {audio_segment_id}"
            )
    
        track_name = track_info.get("track_name")
    
        # 调用服务层处理业务逻辑
        result = add_audio_fade_service(
            draft_id=draft_id,
            audio_segment_id=audio_segment_id,
            in_duration=in_duration,
            out_duration=out_duration,
            track_name=track_name
        )
    
        return result
  • Helper service implementing the core logic: creates AudioSegment instance and calls add_fade method.
    def add_audio_fade_service(
        draft_id: str,
        audio_segment_id: str,
        in_duration: str,
        out_duration: str,
        track_name: Optional[str] = None
    ) -> ToolResponse:
        """
        音频淡入淡出添加服务 - 为音频片段添加淡入淡出效果
    
        Args:
            draft_id: 草稿ID
            audio_segment_id: 音频片段ID
            in_duration: 音频淡入时长,格式如 "1s"、"500ms"
            out_duration: 音频淡出时长,格式如 "1s"、"500ms"
            track_name: 轨道名称(可选)
    
        Returns:
            ToolResponse: 包含操作结果的响应对象
        """
        try:
            # 创建AudioSegment实例,传入audio_segment_id
            audio_segment = AudioSegment(draft_id, audio_segment_id=audio_segment_id, track_name=track_name)
    
            # 调用音频淡入淡出添加方法
            result_data = audio_segment.add_fade(
                in_duration=in_duration,
                out_duration=out_duration
            )
    
            # 构建返回数据
            response_data = {
                "audio_segment_id": audio_segment_id,
                "draft_id": draft_id,
                "in_duration": in_duration,
                "out_duration": out_duration,
                "add_fade": result_data
            }
    
            # 添加可选参数到返回数据
            if track_name:
                response_data["track_name"] = track_name
    
            return ToolResponse(
                success=True,
                message=f"音频淡入淡出添加成功: 淡入{in_duration}, 淡出{out_duration}",
                data=response_data
            )
    
        except ValueError as e:
            # 处理参数错误
            return ToolResponse(
                success=False,
                message=f"参数错误: {str(e)}"
            )
    
        except NameError as e:
            # 处理轨道不存在错误
            return ToolResponse(
                success=False,
                message=f"轨道错误: {str(e)}"
            )
    
        except Exception as e:
            # 处理其他未预期的错误
            return ToolResponse(
                success=False,
                message=f"音频淡入淡出添加失败: {str(e)}"
            )
  • Import of the service functions used by the audio tools, including add_audio_fade_service.
    from jianyingdraft.services.audio_service import add_audio_segment_service, add_audio_effect_service, \
        add_audio_fade_service, add_audio_keyframe_service
  • Type hints and docstring defining input schema for the tool.
    def add_audio_fade(
            audio_segment_id: str,
            in_duration: str,
            out_duration: str
    ) -> ToolResponse:
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It states the tool adds effects, implying mutation, but doesn't disclose behavioral traits like whether it modifies the original audio segment in-place, creates a new version, requires specific permissions, has rate limits, or what the output looks like. The description is minimal and lacks crucial operational context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is highly concise and well-structured: a one-sentence purpose statement followed by a bullet-point list of parameters with clear explanations. Every sentence earns its place with no wasted words, and key information is front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 3 parameters with 0% schema coverage and no annotations, the description does a decent job explaining parameters but lacks behavioral context. The presence of an output schema (not shown) means return values might be documented elsewhere, reducing the burden. However, for a mutation tool with no safety annotations, more operational details would be helpful.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It adds significant semantic value by explaining all three parameters: 'audio_segment_id' is sourced from 'add_audio_segment', and 'in_duration'/'out_duration' specify formats like '1s' or '500ms'. This clarifies usage beyond the bare schema, though it doesn't cover edge cases or units beyond seconds/milliseconds.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '为音频片段添加淡入淡出效果' (add fade-in and fade-out effects to an audio segment). It specifies the verb (add) and resource (audio segment), but doesn't explicitly differentiate from sibling tools like 'add_audio_effect' or 'add_audio_keyframe' that might also modify audio segments.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It mentions that 'audio_segment_id' is obtained via 'add_audio_segment', which is a prerequisite but not a usage guideline. There's no mention of when fade effects are appropriate or when other audio tools might be better suited.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/hey-jian-wei/jianying-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server