Skip to main content
Glama

add_audio_keyframe

Add volume keyframes to audio segments in JianYing video projects to control audio levels at specific timestamps for dynamic sound adjustments.

Instructions

为音频片段添加音量关键帧

Args: audio_segment_id: 音频片段ID,通过add_audio_segment获得 time_offset: 关键帧的时间偏移量,格式如 "0s", "1.5s", "500ms" volume: 音量在time_offset处的值,范围通常0.0-1.0,也可以大于1.0实现增益效果

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
audio_segment_idYes
time_offsetYes
volumeYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataNo
messageYes
successYes

Implementation Reference

  • The MCP tool handler for 'add_audio_keyframe', decorated with @mcp.tool(). Validates inputs (audio_segment_id, time_offset, volume), retrieves draft_id and track_name from index_manager, and delegates to add_audio_keyframe_service.
    @mcp.tool()
    def add_audio_keyframe(
            audio_segment_id: str,
            time_offset: str,
            volume: float
    ) -> ToolResponse:
        """
        为音频片段添加音量关键帧
    
        Args:
            audio_segment_id: 音频片段ID,通过add_audio_segment获得
            time_offset: 关键帧的时间偏移量,格式如 "0s", "1.5s", "500ms"
            volume: 音量在time_offset处的值,范围通常0.0-1.0,也可以大于1.0实现增益效果
        """
        # 参数验证
        if not time_offset:
            return ToolResponse(
                success=False,
                message="时间偏移量不能为空"
            )
    
        if volume < 0.0:
            return ToolResponse(
                success=False,
                message=f"音量值不能为负数,当前值: {volume}"
            )
    
        # 时间格式验证
        def validate_time_offset(time_offset: str) -> bool:
            """验证时间偏移量格式是否正确"""
            if not time_offset:
                return False
            # 检查是否以s或ms结尾
            if not (time_offset.endswith('s') or time_offset.endswith('ms')):
                return False
            # 检查数字部分
            try:
                if time_offset.endswith('ms'):
                    float(time_offset[:-2])
                else:
                    float(time_offset[:-1])
                return True
            except ValueError:
                return False
    
        if not validate_time_offset(time_offset):
            return ToolResponse(
                success=False,
                message=f"无效的时间偏移量格式: {time_offset},正确格式如 '1.5s', '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_keyframe_service(
            draft_id=draft_id,
            audio_segment_id=audio_segment_id,
            time_offset=time_offset,
            volume=volume,
            track_name=track_name
        )
    
        return result
  • Service layer implementation add_audio_keyframe_service. Instantiates AudioSegment(draft_id, audio_segment_id=audio_segment_id), calls its add_keyframe(time_offset, volume) method, handles exceptions, and constructs ToolResponse.
    def add_audio_keyframe_service(
        draft_id: str,
        audio_segment_id: str,
        time_offset: str,
        volume: float,
        track_name: Optional[str] = None
    ) -> ToolResponse:
        """
        音频关键帧添加服务 - 为音频片段添加音量关键帧
    
        Args:
            draft_id: 草稿ID
            audio_segment_id: 音频片段ID
            time_offset: 关键帧的时间偏移量,格式如 "0s"、"1.5s"
            volume: 音量在time_offset处的值,范围通常0.0-1.0
            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_keyframe(
                time_offset=time_offset,
                volume=volume
            )
    
            # 构建返回数据
            response_data = {
                "audio_segment_id": audio_segment_id,
                "draft_id": draft_id,
                "time_offset": time_offset,
                "volume": volume,
                "add_keyframe": result_data
            }
    
            # 添加可选参数到返回数据
            if track_name:
                response_data["track_name"] = track_name
    
            return ToolResponse(
                success=True,
                message=f"音频关键帧添加成功: 时间{time_offset}, 音量{volume}",
                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 add_audio_keyframe_service from services.audio_service, required for the tool handler.
    add_audio_fade_service, add_audio_keyframe_service
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states the action ('添加' - add) which implies a write/mutation operation, but doesn't disclose any behavioral traits like whether this requires specific permissions, if it's idempotent, what happens on invalid inputs, or how it interacts with existing keyframes. The description adds minimal context beyond the basic function, leaving significant gaps for a mutation tool.

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

Conciseness4/5

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

The description is well-structured with a clear purpose statement followed by parameter explanations. Each sentence earns its place by providing essential information. However, the Chinese formatting with 'Args:' and parameter explanations could be slightly more integrated, and there's some redundancy in stating parameter names that are already in the schema.

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 that this is a mutation tool with no annotations but with an output schema (which handles return values), the description is moderately complete. It covers the basic purpose and parameter semantics well, but lacks important behavioral context for a write operation. The presence of an output schema means the description doesn't need to explain return values, but it should still address mutation-specific concerns like side effects or error conditions.

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

Parameters5/5

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

With 0% schema description coverage, the description fully compensates by providing clear semantic explanations for all 3 parameters. It explains that 'audio_segment_id' comes from 'add_audio_segment', specifies the format for 'time_offset' with examples ('0s', '1.5s', '500ms'), and describes 'volume' with its typical range (0.0-1.0) and special case (>1.0 for gain). This adds substantial value beyond the bare schema.

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 action ('添加音量关键帧' - add volume keyframe) and the target resource ('音频片段' - audio segment), which is specific and unambiguous. It distinguishes from siblings like 'add_audio_effect' or 'add_audio_fade' by focusing specifically on volume keyframes rather than effects, fades, or segments. However, it doesn't explicitly contrast with 'add_video_keyframe' which might have similar functionality for video.

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 from 'add_audio_segment', which is a prerequisite but not usage context. There's no indication of when to choose this over other audio manipulation tools like 'add_audio_effect' or 'add_audio_fade', nor does it specify scenarios where volume keyframes are appropriate.

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