Skip to main content
Glama

add_audio_effect

Add audio effects like scene sounds, tone adjustments, or speech-to-song conversion to audio segments in JianYing video projects.

Instructions

为音频片段添加特效

Args: audio_segment_id: 音频片段ID,通过add_audio_segment获得 effect_type: 特效类型,支持以下类型: - "AudioSceneEffectType": 场景音效(如雨声、风声等) - "ToneEffectType": 音调特效(如机器人、电音等) - "SpeechToSongType": 语音转歌声特效(如Lofi、流行等) effect_name: 特效名称,如 "雨声", "机器人", "Lofi", "电音", "回声" 等,可以使用find_effects_by_type工具,资源类型选择AudioSceneEffectType、ToneEffectType、SpeechToSongType,从而获取特效类型有哪些 params: 特效参数列表(可选),参数范围0-100,具体参数数量和含义取决于特效类型,一般不做修改

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
audio_segment_idYes
effect_typeYes
effect_nameYes
paramsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataNo
messageYes
successYes

Implementation Reference

  • MCP tool handler for 'add_audio_effect'. Performs parameter validation, checks if effect exists using JianYingResourceManager, retrieves draft and track info from index_manager, and calls add_audio_effect_service.
    @mcp.tool()
    def add_audio_effect(
            audio_segment_id: str,
            effect_type: str,
            effect_name: str,
            params: Optional[List[Optional[float]]] = None
    ) -> ToolResponse:
        """
        为音频片段添加特效
    
        Args:
            audio_segment_id: 音频片段ID,通过add_audio_segment获得
            effect_type: 特效类型,支持以下类型:
                - "AudioSceneEffectType": 场景音效(如雨声、风声等)
                - "ToneEffectType": 音调特效(如机器人、电音等)
                - "SpeechToSongType": 语音转歌声特效(如Lofi、流行等)
            effect_name: 特效名称,如 "雨声", "机器人", "Lofi", "电音", "回声" 等,可以使用find_effects_by_type工具,资源类型选择AudioSceneEffectType、ToneEffectType、SpeechToSongType,从而获取特效类型有哪些
            params: 特效参数列表(可选),参数范围0-100,具体参数数量和含义取决于特效类型,一般不做修改
        """
        # 参数验证
        valid_types = ["AudioSceneEffectType", "ToneEffectType", "SpeechToSongType"]
        if effect_type not in valid_types:
            return ToolResponse(
                success=False,
                message=f"无效的特效类型 '{effect_type}',支持的类型: {', '.join(valid_types)}"
            )
    
        # 验证参数范围
        if params:
            for i, param in enumerate(params):
                if param is not None and not (0.0 <= param <= 100.0):
                    return ToolResponse(
                        success=False,
                        message=f"参数{i + 1}超出范围,必须在0-100之间,当前值: {param}"
                    )
    
        # 音频特效存在性验证(音频特效使用 name 字段)
        from jianyingdraft.utils.effect_manager import JianYingResourceManager
        manager = JianYingResourceManager()
    
        effects = manager.find_by_type(
            effect_type=effect_type,
            keyword=effect_name,
            limit=1
        )
    
        # 检查是否找到完全匹配的特效
        exact_match = False
        if effects:
            for effect in effects:
                if effect.get('name') == effect_name:
                    exact_match = True
                    break
    
        if not effects or not exact_match:
            # 获取建议特效
            effect_suggestions = manager.find_by_type(effect_type, keyword=effect_name)
    
            all_suggestions = []
            for effect in effect_suggestions:
                if effect.get('name'):
                    all_suggestions.append(effect.get('name'))
    
            return ToolResponse(
                success=False,
                message=f"在 {effect_type} 中未找到特效 '{effect_name}',请确认名称是否正确,或使用相关特效: {', '.join(all_suggestions)}",
                data={
                    "error_type": "effect_not_found",
                    "effect_type": effect_type,
                    "effect_name": effect_name,
                    "suggestions": all_suggestions
                }
            )
    
        # 通过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_effect_service(
            draft_id=draft_id,
            audio_segment_id=audio_segment_id,
            effect_type=effect_type,
            effect_name=effect_name,
            params=params,
            track_name=track_name
        )
    
        return result
  • Helper service layer that creates an AudioSegment instance and invokes its add_effect method to apply the audio effect to the specified segment.
    def add_audio_effect_service(
        draft_id: str,
        audio_segment_id: str,
        effect_type: str,
        effect_name: str,
        params: Optional[List[Optional[float]]] = None,
        track_name: Optional[str] = None
    ) -> ToolResponse:
        """
        音频特效添加服务 - 为音频片段添加特效
    
        Args:
            draft_id: 草稿ID
            audio_segment_id: 音频片段ID
            effect_type: 特效类型,"AudioSceneEffectType"、"ToneEffectType"、"SpeechToSongType"
            effect_name: 特效名称,如 "雨声"、"机器人"、"Lofi" 等
            params: 特效参数列表(可选),参数范围0-100
            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_effect(
                effect_type=effect_type,
                effect_name=effect_name,
                params=params
            )
    
            # 构建返回数据
            response_data = {
                "audio_segment_id": audio_segment_id,
                "draft_id": draft_id,
                "effect_type": effect_type,
                "effect_name": effect_name,
                "add_effect": result_data
            }
    
            # 添加可选参数到返回数据
            if params:
                response_data["params"] = params
            if track_name:
                response_data["track_name"] = track_name
    
            return ToolResponse(
                success=True,
                message=f"音频特效添加成功: {effect_type}.{effect_name}",
                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)}"
            )
  • Function that registers multiple audio tools including 'add_audio_effect' with the FastMCP server instance.
    def audio_tools(mcp: FastMCP):
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions that 'params' are optional and generally not modified, but fails to describe critical behaviors such as whether this is a mutating operation, what permissions are required, how effects are applied (e.g., overlay vs. replacement), or what the output contains. The description is insufficient for a tool that modifies audio content.

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 an 'Args' section detailing each parameter. Every sentence adds value, such as explaining parameter sources or suggesting related tools. It could be slightly more concise by integrating the 'effect_type' examples more seamlessly, but overall it's efficient and 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?

The description is moderately complete given the tool's complexity and lack of annotations. It thoroughly documents parameters but omits behavioral context like mutation effects or error handling. Since an output schema exists, the description doesn't need to explain return values, but it should address how the tool interacts with the audio system (e.g., whether effects are reversible or cumulative).

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?

Given 0% schema description coverage, the description compensates fully by explaining all four parameters in detail. It clarifies that 'audio_segment_id' comes from 'add_audio_segment', enumerates the three 'effect_type' options with examples, describes 'effect_name' with specific instances and how to find more, and notes that 'params' are optional numeric values (0-100) whose meaning depends on the effect type. This adds significant 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 tool's purpose as '为音频片段添加特效' (add effects to audio segments), specifying both the verb (add) and resource (audio segments). It distinguishes from siblings like 'add_audio_fade' or 'add_audio_keyframe' by focusing on general effects rather than specific transformations. However, it doesn't explicitly differentiate from 'add_video_effect' which serves a similar purpose 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 Guidelines3/5

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

The description implies usage by mentioning that 'audio_segment_id' is obtained via 'add_audio_segment' and suggests using 'find_effects_by_type' to discover available effects. However, it lacks explicit guidance on when to use this tool versus alternatives like 'add_audio_fade' or 'add_video_effect', and doesn't mention prerequisites or exclusions.

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