### Install midi2audio via pip Source: https://github.com/bzamecnik/midi2audio/blob/master/README.md Standard installation command for the midi2audio package using pip. ```bash pip install midi2audio ``` -------------------------------- ### Install midi2audio for Development Source: https://github.com/bzamecnik/midi2audio/blob/master/README.md Installs the midi2audio package in editable mode, allowing code changes to take effect without reinstallation. ```bash git clone https://github.com/bzamecnik/midi2audio pip install -e midi2audio ``` -------------------------------- ### Install FluidSynth on OS X Source: https://github.com/bzamecnik/midi2audio/blob/master/README.md Command to install FluidSynth with libsndfile support on macOS using Homebrew. ```bash brew install fluidsynth --with-libsndfile ``` -------------------------------- ### Convert MIDI to Audio using midi_to_audio Source: https://context7.com/bzamecnik/midi2audio/llms.txt Use the midi_to_audio method for non-realtime synthesis of MIDI files into various audio formats. Supports WAV, FLAC, and others if libsndfile is installed. Set verbose=False to suppress FluidSynth output. ```python from midi2audio import FluidSynth fs = FluidSynth() # Basic conversion to WAV fs.midi_to_audio('input.mid', 'output.wav') # Convert to FLAC (lossless compression, recommended) fs.midi_to_audio('input.mid', 'output.flac') # Silent conversion (suppress FluidSynth output) fs.midi_to_audio('input.mid', 'output.wav', verbose=False) # Batch processing example import os midi_files = ['song1.mid', 'song2.mid', 'song3.mid'] for midi_file in midi_files: output_file = os.path.splitext(midi_file)[0] + '.flac' fs.midi_to_audio(midi_file, output_file) print(f"Converted {midi_file} to {output_file}") ``` -------------------------------- ### Initialize FluidSynth Class Source: https://context7.com/bzamecnik/midi2audio/llms.txt Instantiate the FluidSynth class with default or custom sound font, sample rate, and gain settings. ```python from midi2audio import FluidSynth # Initialize with default settings (uses ~/.fluidsynth/default_sound_font.sf2) fs = FluidSynth() # Initialize with custom sound font fs = FluidSynth('path/to/soundfont.sf2') # Initialize with custom sample rate (default is 44100 Hz) fs = FluidSynth(sample_rate=22050) # Initialize with custom gain (default is 0.2) fs = FluidSynth(gain=0.5) # Full customization fs = FluidSynth( sound_font='/usr/share/soundfonts/FluidR3_GM.sf2', sample_rate=48000, gain=0.3 ) ``` -------------------------------- ### Python Interface for FluidSynth Source: https://github.com/bzamecnik/midi2audio/blob/master/README.md Demonstrates the basic Python interface for FluidSynth, showing how to instantiate the class and call the midi_to_audio method. ```python from midi2audio import FluidSynth FluidSynth().midi_to_audio('input.mid', 'output.wav') ``` -------------------------------- ### FluidSynth Class Initialization Source: https://context7.com/bzamecnik/midi2audio/llms.txt Initialize the FluidSynth class with various configuration options for sound font, sample rate, and gain. ```APIDOC ## FluidSynth Class Initialization ### Description Initialize the FluidSynth class with default or custom settings for sound font, sample rate, and gain. ### Method `FluidSynth()` ### Parameters - **sound_font** (str) - Optional - Path to the sound font file. Defaults to `~/.fluidsynth/default_sound_font.sf2`. - **sample_rate** (int) - Optional - The sample rate for audio output. Defaults to 44100 Hz. - **gain** (float) - Optional - The gain level for audio output. Defaults to 0.2. ### Request Example ```python from midi2audio import FluidSynth # Initialize with default settings fs = FluidSynth() # Initialize with custom sound font fs = FluidSynth('path/to/soundfont.sf2') # Initialize with custom sample rate fs = FluidSynth(sample_rate=22050) # Initialize with custom gain fs = FluidSynth(gain=0.5) # Full customization fs = FluidSynth( sound_font='/usr/share/soundfonts/FluidR3_GM.sf2', sample_rate=48000, gain=0.3 ) ``` ``` -------------------------------- ### Basic FluidSynth CLI Usage Source: https://github.com/bzamecnik/midi2audio/blob/master/README.md This is the standard command-line usage for FluidSynth, demonstrating its parameters for input MIDI, output audio, and sample rate. ```bash fluidsynth -ni sound_font.sf2 input.mid -F output.wav -r 44100 ``` -------------------------------- ### Initialize FluidSynth with Custom Sound Font Source: https://github.com/bzamecnik/midi2audio/blob/master/README.md Initializes the FluidSynth synthesizer with a specific sound font file. ```python # use a custom sound font FluidSynth('sound_font.sf2') ``` -------------------------------- ### Initialize FluidSynth with Custom Sample Rate Source: https://github.com/bzamecnik/midi2audio/blob/master/README.md Initializes the FluidSynth synthesizer with a custom sample rate. ```python # use a custom sample rate FluidSynth(sample_rate=22050) ``` -------------------------------- ### midi2audio CLI Usage Comparison Source: https://github.com/bzamecnik/midi2audio/blob/master/README.md Compares the verbose FluidSynth CLI command with the simplified midi2audio commands for playing and synthesizing MIDI files. ```bash midiplay input.mid ``` ```bash midi2audio input.mid output.wav ``` -------------------------------- ### Synthesize MIDI with Custom Sample Rate via CLI Source: https://github.com/bzamecnik/midi2audio/blob/master/README.md Command-line usage for synthesizing MIDI to audio with a specified sample rate. ```bash # custom sample rate $ midi2audio -r 22050 input.mid output.flac ``` -------------------------------- ### midi2audio Command-Line Tool Source: https://context7.com/bzamecnik/midi2audio/llms.txt Command-line utility for converting MIDI files to audio with options for sound font and sample rate. ```APIDOC ## midi2audio Command-Line Tool ### Description Command-line utility for converting MIDI files to audio. Supports custom sound fonts and sample rates via command-line arguments. ### Usage `midi2audio [OPTIONS] ` ### Parameters - **-s, --soundfont** (str) - Path to the sound font file. - **-r, --samplerate** (int) - Sample rate for the audio output. - **input_midi_file** (str) - Required - Path to the input MIDI file. - **output_audio_file** (str) - Required - Path for the output audio file (e.g., `.wav`, `.flac`). ### Request Example ```bash # Basic MIDI to WAV conversion midi2audio input.mid output.wav # Convert to FLAC format midi2audio input.mid output.flac # Use custom sound font midi2audio -s /path/to/soundfont.sf2 input.mid output.wav # Use custom sample rate midi2audio -r 22050 input.mid output.wav # Combine options midi2audio -s custom.sf2 -r 48000 input.mid output.flac # Batch conversion using shell for f in *.mid; do midi2audio "$f" "${f%.mid}.flac" done ``` ``` -------------------------------- ### Configure Default Sound Font Source: https://context7.com/bzamecnik/midi2audio/llms.txt Set up the default sound font for automatic detection by midi2audio. This involves creating the ~/.fluidsynth directory and symlinking your preferred sound font. ```bash # Create the FluidSynth config directory mkdir -p ~/.fluidsynth # Symlink your preferred sound font as the default ln -s /usr/share/soundfonts/FluidR3_GM.sf2 ~/.fluidsynth/default_sound_font.sf2 # macOS: Install FluidSynth with sound fonts using the provided script ./install_fluidsynth_with_soundfonts_osx.sh # macOS: Manual installation with Homebrew brew install fluidsynth --with-libsndfile ``` -------------------------------- ### Sound Font Configuration Source: https://context7.com/bzamecnik/midi2audio/llms.txt Instructions for setting up the default sound font for midi2audio. ```APIDOC ## Sound Font Configuration ### Description Instructions for setting up the default sound font location for automatic detection by midi2audio and midiplay. ### Steps 1. **Create Configuration Directory**: ```bash mkdir -p ~/.fluidsynth ``` 2. **Symlink Default Sound Font**: Create a symbolic link to your preferred sound font file named `default_sound_font.sf2` inside the `~/.fluidsynth/` directory. ```bash ln -s /usr/share/soundfonts/FluidR3_GM.sf2 ~/.fluidsynth/default_sound_font.sf2 ``` ### macOS Specific Instructions **Option 1: Using Provided Script**: If available, use the provided script to install FluidSynth with sound fonts. ```bash ./install_fluidsynth_with_soundfonts_osx.sh ``` **Option 2: Manual Installation with Homebrew**: Install FluidSynth using Homebrew, ensuring `libsndfile` is included. ```bash brew install fluidsynth --with-libsndfile ``` ``` -------------------------------- ### play_midi Method Source: https://context7.com/bzamecnik/midi2audio/llms.txt Play a MIDI file in real-time through the audio output. ```APIDOC ## play_midi Method ### Description Plays a MIDI file in real-time using FluidSynth's interactive mode. ### Method `play_midi(midi_file: str)` ### Parameters - **midi_file** (str) - Required - Path to the MIDI file to play. ### Request Example ```python from midi2audio import FluidSynth # Play with default sound font fs = FluidSynth() fs.play_midi('input.mid') # Play with custom sound font and sample rate fs = FluidSynth( sound_font='/usr/share/soundfonts/GeneralUser_GS.sf2', sample_rate=48000, gain=0.5 ) fs.play_midi('music.mid') ``` ``` -------------------------------- ### midiplay Command-Line Tool Source: https://context7.com/bzamecnik/midi2audio/llms.txt Command-line utility for playing MIDI files directly without creating an output file. ```APIDOC ## midiplay Command-Line Tool ### Description Command-line utility for playing MIDI files directly through the audio output without creating an intermediate audio file. ### Usage `midiplay [OPTIONS] ` ### Parameters - **-s, --soundfont** (str) - Path to the sound font file. - **-r, --samplerate** (int) - Sample rate for the audio output. - **input_midi_file** (str) - Required - Path to the MIDI file to play. ### Request Example ```bash # Play a MIDI file with default sound font midiplay input.mid # Play with custom sound font midiplay -s /path/to/soundfont.sf2 input.mid # Play with custom sample rate midiplay -r 48000 input.mid ``` ``` -------------------------------- ### Play MIDI Files in Real-time Source: https://context7.com/bzamecnik/midi2audio/llms.txt Utilize the play_midi method for real-time playback of MIDI files through the system's audio output. Supports custom sound fonts and sample rates. ```python from midi2audio import FluidSynth # Play with default sound font fs = FluidSynth() fs.play_midi('input.mid') # Play with custom sound font and sample rate fs = FluidSynth( sound_font='/usr/share/soundfonts/GeneralUser_GS.sf2', sample_rate=48000, gain=0.5 ) fs.play_midi('music.mid') ``` -------------------------------- ### Synthesize MIDI with Custom Sound Font via CLI Source: https://github.com/bzamecnik/midi2audio/blob/master/README.md Command-line usage for synthesizing MIDI to audio using a specified sound font file. ```bash # custom sound font $ midi2audio -s sound_font.sf2 input.mid output.flac ``` -------------------------------- ### Synthesize MIDI to Audio via CLI Source: https://github.com/bzamecnik/midi2audio/blob/master/README.md Command-line usage for synthesizing a MIDI file to an audio file (WAV or FLAC). ```bash # synthesize MIDI to audio $ midi2audio input.mid output.wav # also to FLAC $ midi2audio input.mid output.flac ``` -------------------------------- ### midi2audio Command-Line Tool Usage Source: https://context7.com/bzamecnik/midi2audio/llms.txt Convert MIDI files to audio formats like WAV and FLAC directly from the command line. Options include specifying custom sound fonts (-s) and sample rates (-r). ```bash # Basic MIDI to WAV conversion midi2audio input.mid output.wav # Convert to FLAC format midi2audio input.mid output.flac # Use custom sound font midi2audio -s /path/to/soundfont.sf2 input.mid output.wav # Use custom sample rate midi2audio -r 22050 input.mid output.wav # Combine options midi2audio -s custom.sf2 -r 48000 input.mid output.flac # Batch conversion using shell for f in *.mid; midi2audio "$f" "${f%.mid}.flac" done ``` -------------------------------- ### midiplay Command-Line Tool Usage Source: https://context7.com/bzamecnik/midi2audio/llms.txt Play MIDI files in real-time directly from the command line without generating an audio file. Supports custom sound fonts (-s) and sample rates (-r). ```bash # Play a MIDI file with default sound font midiplay input.mid # Play with custom sound font midiplay -s /path/to/soundfont.sf2 input.mid # Play with custom sample rate midiplay -r 48000 input.mid ``` -------------------------------- ### Play MIDI file using Python Source: https://github.com/bzamecnik/midi2audio/blob/master/README.md Python code to play a MIDI file directly using the FluidSynth class. ```python from midi2audio import FluidSynth FluidSynth().play_midi('input.mid') ``` -------------------------------- ### Synthesize MIDI to WAV with Custom Gain Source: https://github.com/bzamecnik/midi2audio/blob/master/README.md Synthesizes a MIDI file to a WAV audio file using a custom gain value. ```python # using the default sound font in 44100 Hz sample rate fs = FluidSynth() fs.midi_to_audio('input.mid', 'output.wav') # optional third argument to control gain (defaults to 0.2) fs.midi_to_audio('input.mid', 'output.wav', gain=0.75) ``` -------------------------------- ### midi_to_audio Method Source: https://context7.com/bzamecnik/midi2audio/llms.txt Convert a MIDI file to an audio file using non-realtime synthesis. Supports various output formats. ```APIDOC ## midi_to_audio Method ### Description Converts a MIDI file to an audio file using non-realtime synthesis. The output format is determined by the file extension. Supports WAV, FLAC, and other formats compatible with libsndfile. ### Method `midi_to_audio(midi_file: str, output_file: str, verbose: bool = True)` ### Parameters - **midi_file** (str) - Required - Path to the input MIDI file. - **output_file** (str) - Required - Path for the output audio file. The format is inferred from the extension (e.g., `.wav`, `.flac`). - **verbose** (bool) - Optional - If True, FluidSynth output is shown. Defaults to True. ### Request Example ```python from midi2audio import FluidSynth fs = FluidSynth() # Basic conversion to WAV fs.midi_to_audio('input.mid', 'output.wav') # Convert to FLAC (lossless compression) fs.midi_to_audio('input.mid', 'output.flac') # Silent conversion fs.midi_to_audio('input.mid', 'output.wav', verbose=False) # Batch processing example import os midi_files = ['song1.mid', 'song2.mid', 'song3.mid'] for midi_file in midi_files: output_file = os.path.splitext(midi_file)[0] + '.flac' fs.midi_to_audio(midi_file, output_file) print(f"Converted {midi_file} to {output_file}") ``` ``` -------------------------------- ### Synthesize MIDI to FLAC Source: https://github.com/bzamecnik/midi2audio/blob/master/README.md Synthesizes a MIDI file to a FLAC audio file, a lossless codec recommended for quality. ```python # FLAC, a lossless codec, is supported as well (and recommended to be used) fs.midi_to_audio('input.mid', 'output.flac') ``` -------------------------------- ### Link Default Sound Font on OS X Source: https://github.com/bzamecnik/midi2audio/blob/master/README.md Creates a symbolic link for the default sound font in the .fluidsynth directory on macOS. ```bash mkdir -p ~/.fluidsynth ln -s /path/to/my/sound_font.sf2 ~/.fluidsynth/default_sound_font.sf2 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.