set_audio_channels
Modify audio channel configuration by setting mono (1 channel) or stereo (2 channels) layouts for an audio file, ensuring compatibility with specific playback or editing requirements.
Instructions
Sets the number of channels for an audio file (1 for mono, 2 for stereo). Args: input_audio_path: Path to the source audio file. output_audio_path: Path to save the audio file with the new channel layout. channels: Number of audio channels (1 for mono, 2 for stereo). Returns: A status message indicating success or failure.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channels | Yes | ||
| input_audio_path | Yes | ||
| output_audio_path | Yes |
Implementation Reference
- server.py:309-328 (handler)Handler function for the 'set_audio_channels' MCP tool. Uses FFmpeg to change the number of audio channels (mono/stereo) in an audio file and returns a success/error message.@mcp.tool() def set_audio_channels(input_audio_path: str, output_audio_path: str, channels: int) -> str: """Sets the number of channels for an audio file (1 for mono, 2 for stereo). Args: input_audio_path: Path to the source audio file. output_audio_path: Path to save the audio file with the new channel layout. channels: Number of audio channels (1 for mono, 2 for stereo). Returns: A status message indicating success or failure. """ try: ffmpeg.input(input_audio_path).output(output_audio_path, ac=channels).run(capture_stdout=True, capture_stderr=True) return f"Audio channels set to {channels} and saved to {output_audio_path}" except ffmpeg.Error as e: error_message = e.stderr.decode('utf8') if e.stderr else str(e) return f"Error setting audio channels: {error_message}" except FileNotFoundError: return f"Error: Input audio file not found at {input_audio_path}" except Exception as e: return f"An unexpected error occurred: {str(e)}"