convert_audio_properties
Transform audio files by converting formats, adjusting bitrate, sample rate, and channels for precise customization in audio editing workflows.
Instructions
Converts audio file format and ALL specified properties like bitrate, sample rate, and channels.
Args: input_audio_path: Path to the source audio file. output_audio_path: Path to save the converted audio file. target_format: Desired output audio format (e.g., 'mp3', 'wav', 'aac'). bitrate: Target audio bitrate (e.g., '128k', '192k'). Optional. sample_rate: Target audio sample rate in Hz (e.g., 44100, 48000). Optional. channels: Number of audio channels (1 for mono, 2 for stereo). Optional. Returns: A status message indicating success or failure.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bitrate | No | ||
| channels | No | ||
| input_audio_path | Yes | ||
| output_audio_path | Yes | ||
| sample_rate | No | ||
| target_format | Yes |
Implementation Reference
- server.py:76-111 (handler)The primary handler function implementing the 'convert_audio_properties' tool logic using FFmpeg to adjust audio format, bitrate, sample rate, and channels. The @mcp.tool() decorator handles both implementation and registration in FastMCP, with type hints providing the input schema.@mcp.tool() def convert_audio_properties(input_audio_path: str, output_audio_path: str, target_format: str, bitrate: str = None, sample_rate: int = None, channels: int = None) -> str: """Converts audio file format and ALL specified properties like bitrate, sample rate, and channels. Args: input_audio_path: Path to the source audio file. output_audio_path: Path to save the converted audio file. target_format: Desired output audio format (e.g., 'mp3', 'wav', 'aac'). bitrate: Target audio bitrate (e.g., '128k', '192k'). Optional. sample_rate: Target audio sample rate in Hz (e.g., 44100, 48000). Optional. channels: Number of audio channels (1 for mono, 2 for stereo). Optional. Returns: A status message indicating success or failure. """ try: stream = ffmpeg.input(input_audio_path) kwargs = {} if bitrate: kwargs['audio_bitrate'] = bitrate if sample_rate: kwargs['ar'] = sample_rate if channels: kwargs['ac'] = channels kwargs['format'] = target_format output_stream = stream.output(output_audio_path, **kwargs) output_stream.run(capture_stdout=True, capture_stderr=True) return f"Audio converted successfully to {output_audio_path} with format {target_format} and specified properties." except ffmpeg.Error as e: error_message = e.stderr.decode('utf8') if e.stderr else str(e) return f"Error converting audio properties: {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)}"