### Install PyTSMod Source: https://github.com/kaist-maclab/pytsmod/blob/main/README.md Installation commands for PyTSMod using pip or poetry. ```bash $ pip install pytsmod ``` ```bash $ poetry build ``` -------------------------------- ### Install PyTSMod Source: https://context7.com/kaist-maclab/pytsmod/llms.txt Installs the PyTSMod library using pip. ```bash pip install pytsmod ``` -------------------------------- ### Check PEP8 Compliance Source: https://github.com/kaist-maclab/pytsmod/blob/main/CONTRIBUTING.md Use this command to install and run pep8 to check your Python code for PEP8 style guide compliance. Ensure you have pip installed. ```shell $ pip install pep8 $ pep8 path/code_to_check.py ``` -------------------------------- ### Initialize Phase Vocoder for Integer Stretching Source: https://context7.com/kaist-maclab/pytsmod/llms.txt Setup for using the phase vocoder specifically optimized for integer stretching factors. ```python import numpy as np import pytsmod as tsm import soundfile as sf # Load audio x, sr = sf.read('input.wav') x = x.T ``` -------------------------------- ### Get Help for Specific Commands Source: https://context7.com/kaist-maclab/pytsmod/llms.txt Displays help information for the tsmod tool and its specific commands. ```bash tsmod --help ``` ```bash tsmod wsola --help ``` ```bash tsmod pv --help ``` -------------------------------- ### Use OLA, WSOLA, and PV-TSM Source: https://github.com/kaist-maclab/pytsmod/blob/main/README.md Example of using WSOLA for time stretching with fixed factors or anchor points. ```python import numpy as np import pytsmod as tsm import soundfile as sf # you can use other audio load packages. x, sr = sf.read('/FILEPATH/AUDIOFILE.wav') x = x.T x_length = x.shape[-1] # length of the audio sequence x. s_fixed = 1.3 # stretch the audio signal 1.3x times. s_ap = np.array([[0, x_length / 2, x_length], [0, x_length, x_length * 1.5]]) # double the first half of the audio only and preserve the other half. x_s_fixed = tsm.wsola(x, s_fixed) x_s_ap = tsm.wsola(x, s_ap) ``` -------------------------------- ### Use TD-PSOLA Source: https://github.com/kaist-maclab/pytsmod/blob/main/README.md Example of using TD-PSOLA for time stretching and pitch shifting, requiring pitch information. ```python import numpy as np import pytsmod as tsm import crepe # you can use other pitch tracking algorithms. import soundfile as sf # you can use other audio load packages. x, sr = sf.read('/FILEPATH/AUDIOFILE.wav') _, f0_crepe, _, _ = crepe.predict(x, sr, viterbi=True, step_size=10) x_double_stretched = tsm.tdpsola(x, sr, f0_crepe, alpha=2, p_hop_size=441, p_win_size=1470) # hop_size and frame_length for CREPE step_size=10 with sr=44100 x_3keyup = tsm.tdpsola(x, sr, f0_crepe, beta=pow(2, 3/12), p_hop_size=441, p_win_size=1470) x_3keydown = tsm.tdpsola(x, sr, f0_crepe, tgt_f0=f0_crepe * pow(2, -3/12), p_hop_size=441, p_win_size=1470) ``` -------------------------------- ### WSOLA with Custom Window Settings Source: https://context7.com/kaist-maclab/pytsmod/llms.txt Applies WSOLA time stretching with custom window type, size, synthesis hop size, and tolerance. ```bash tsmod wsola input.wav output.wav 1.2 \ --win_type hann \ --win_size 2048 \ --syn_hop_size 512 \ --tolerance 256 ``` -------------------------------- ### Phase Vocoder with All Options Source: https://context7.com/kaist-maclab/pytsmod/llms.txt Applies Phase Vocoder time stretching with all available custom options. ```bash tsmod pv input.wav output.wav 1.4 \ --win_type sin \ --win_size 2048 \ --syn_hop_size 512 \ --zero_pad 1024 \ --restore_energy \ --fft_shift \ --phase_lock ``` -------------------------------- ### Basic WSOLA Time Stretching Source: https://context7.com/kaist-maclab/pytsmod/llms.txt Performs basic WSOLA time stretching to make audio 1.3x slower. ```bash tsmod wsola input.wav output.wav 1.3 ``` -------------------------------- ### OLA Time Stretching Source: https://context7.com/kaist-maclab/pytsmod/llms.txt Performs OLA time stretching to speed up audio by 0.8x. ```bash tsmod ola input.wav output.wav 0.8 ``` -------------------------------- ### STFT and ISTFT Utilities Source: https://context7.com/kaist-maclab/pytsmod/llms.txt Low-level STFT and ISTFT functions for custom audio analysis. Supports fixed or variable hop sizes, different window types, and returning time/frequency axes. ```python import numpy as np from pytsmod.utils import stft, istft import soundfile as sf # Load audio x, sr = sf.read('input.wav') ``` ```python # Compute STFT with fixed hop size spec = stft( x, ana_hop=512, # Analysis hop size win_type='hann', # Window type win_size=2048, # Window size zero_pad=0, # Zero padding fft_shift=False ) ``` ```python # STFT with variable analysis positions frame_positions = np.array([0, 512, 1100, 1700, 2400]) # Custom positions spec_var = stft(x, ana_hop=frame_positions, win_type='hann', win_size=2048) ``` ```python # STFT with time and frequency output spec, t, f = stft( x, ana_hop=512, win_size=2048, sr=sr, time_frequency_out=True # Return time and frequency axes ) ``` -------------------------------- ### Phase Vocoder for Integer Stretching Source: https://context7.com/kaist-maclab/pytsmod/llms.txt Performs integer time stretching using the Phase Vocoder algorithm. ```bash tsmod pv_int input.wav output.wav 2 ``` -------------------------------- ### Phase Vocoder with Custom Parameters Source: https://context7.com/kaist-maclab/pytsmod/llms.txt Applies Phase Vocoder time stretching with custom window size and phase lock enabled. ```bash tsmod pv input.wav output.wav 1.5 --win_size 4096 --phase_lock ``` -------------------------------- ### Run time-scale modification via CLI Source: https://github.com/kaist-maclab/pytsmod/blob/main/README.md Executes the tsmod tool to apply a specific algorithm to an input audio file with a defined stretching factor. ```shell $ tsmod wsola input.wav output.wav 1.3 # ola, wsola, pv, pv_int are available. ``` -------------------------------- ### Perform WSOLA Time-Scale Modification Source: https://context7.com/kaist-maclab/pytsmod/llms.txt Applies Waveform-Similarity Overlap-Add to stretch or compress audio. Supports both fixed rates and non-linear stretching using anchor points. ```python import numpy as np import pytsmod as tsm import soundfile as sf # Load audio file x, sr = sf.read('input.wav') x = x.T # Transpose to (channels, samples) format # Fixed rate time stretching - stretch audio to 1.5x duration x_stretched = tsm.wsola(x, s=1.5) # s > 1 slows down, s < 1 speeds up # Compress audio to half duration (2x playback speed) x_compressed = tsm.wsola(x, s=0.5) # Non-linear time stretching using anchor points # Format: [[input_samples], [output_samples]] x_length = x.shape[-1] anchor_points = np.array([ [0, x_length / 2, x_length], # input sample positions [0, x_length, x_length * 1.5] # output sample positions ]) # This doubles the first half, preserves the second half duration x_nonlinear = tsm.wsola(x, s=anchor_points) # Custom window parameters for fine-tuning x_custom = tsm.wsola( x, s=1.3, win_type='hann', # Window type: 'hann' or 'sin' win_size=1024, # Window size in samples syn_hop_size=512, # Synthesis hop size tolerance=512 # Search tolerance for optimal overlap ) # Save output sf.write('output_stretched.wav', x_stretched.T, sr) ``` -------------------------------- ### Reconstruct Audio with ISTFT Source: https://context7.com/kaist-maclab/pytsmod/llms.txt Reconstructs audio from a spectrogram using the Inverse Short-Time Fourier Transform (ISTFT). Allows modification of the spectrogram magnitude before reconstruction to alter volume. ```python y = istft( spec, syn_hop=512, win_type='hann', win_size=2048, zero_pad=0, num_iter=1, original_length=len(x), fft_shift=False, restore_energy=False ) ``` ```python magnitude = np.abs(spec) phase = np.angle(spec) modified_spec = magnitude * 0.5 * np.exp(1j * phase) y_modified = istft(modified_spec, syn_hop=512, win_type='hann', win_size=2048, original_length=len(x)) ``` ```python sf.write('output_reconstructed.wav', y, sr) ``` -------------------------------- ### Time-Domain Pitch-Synchronous Overlap-Add (TD-PSOLA) Source: https://context7.com/kaist-maclab/pytsmod/llms.txt TD-PSOLA is suitable for monophonic speech and singing. It requires pitch tracking data and can perform time stretching, pitch shifting, or both simultaneously. Ensure correct pitch tracker hop and window sizes are provided. ```python import numpy as np import pytsmod as tsm import soundfile as sf # Pitch tracking library (crepe, pyin, or similar) import crepe # Load audio x, sr = sf.read('voice.wav') # Extract pitch using CREPE (or another pitch tracker) # step_size=10ms with sr=44100 gives hop_size=441 samples _, f0, _, _ = crepe.predict(x, sr, viterbi=True, step_size=10) ``` ```python # Time stretching only (preserve pitch) x_stretched = tsm.tdpsola( x, sr, src_f0=f0, alpha=2.0, # Double the duration p_hop_size=441, # Pitch tracker hop size in samples p_win_size=1470 # Pitch tracker window size in samples ) ``` ```python # Pitch shifting only (preserve duration) # Shift up by 3 semitones x_pitch_up = tsm.tdpsola( x, sr, src_f0=f0, alpha=1, # No time stretching beta=pow(2, 3/12), # 3 semitones up p_hop_size=441, p_win_size=1470 ) ``` ```python # Shift down by 5 semitones x_pitch_down = tsm.tdpsola( x, sr, src_f0=f0, alpha=1, beta=pow(2, -5/12), # 5 semitones down p_hop_size=441, p_win_size=1470 ) ``` ```python # Combined time stretching and pitch shifting x_combined = tsm.tdpsola( x, sr, src_f0=f0, alpha=1.5, # 1.5x duration beta=pow(2, 2/12), # 2 semitones up p_hop_size=441, p_win_size=1470 ) ``` ```python # Target pitch contour (pitch correction/conversion) target_f0 = f0 * 1.2 # Raise all pitches by 20% x_target = tsm.tdpsola( x, sr, src_f0=f0, tgt_f0=target_f0, # Target pitch contour alpha=1, p_hop_size=441, p_win_size=1470 ) ``` ```python sf.write('output_tdpsola.wav', x_stretched, sr) sf.write('output_pitch_shifted.wav', x_pitch_up, sr) ``` -------------------------------- ### Integer Stretching with Phase Vocoder Source: https://context7.com/kaist-maclab/pytsmod/llms.txt Use phase_vocoder_int for integer time-scale modification. Customize parameters like window type, size, and hop size for advanced control. ```python x_double = tsm.phase_vocoder_int(x, s=2) # Double the duration x_triple = tsm.phase_vocoder_int(x, s=3) # Triple the duration ``` ```python x_int_custom = tsm.phase_vocoder_int( x, s=2, win_type='hann', win_size=2048, syn_hop_size=512, zero_pad=None, # Auto-calculated based on stretching factor restore_energy=False, fft_shift=True ) ``` -------------------------------- ### Perform OLA Time-Scale Modification Source: https://context7.com/kaist-maclab/pytsmod/llms.txt Applies the Overlap-Add algorithm for time stretching. Best suited for signals with slowly varying characteristics. ```python import numpy as np import pytsmod as tsm import soundfile as sf # Load audio x, sr = sf.read('input.wav') x = x.T # Basic OLA time stretching x_ola = tsm.ola(x, s=1.5) # 1.5x longer duration # OLA with custom parameters x_ola_custom = tsm.ola( x, s=0.8, # Speed up by 1.25x win_type='hann', # Window function type win_size=1024, # Analysis/synthesis window size syn_hop_size=512 # Synthesis hop size (typically win_size/2) ) # Non-linear time stretching with anchor points x_length = x.shape[-1] anchor_points = np.array([ [0, x_length // 4, x_length], [0, x_length // 2, x_length * 2] ]) x_ola_nonlinear = tsm.ola(x, s=anchor_points) sf.write('output_ola.wav', x_ola.T, sr) ``` -------------------------------- ### Perform Phase Vocoder Time-Scale Modification Source: https://context7.com/kaist-maclab/pytsmod/llms.txt Applies frequency-domain time-scale modification using STFT. Phase locking is recommended for improved transient handling. ```python import numpy as np import pytsmod as tsm import soundfile as sf # Load audio x, sr = sf.read('input.wav') x = x.T # Basic phase vocoder TSM x_pv = tsm.phase_vocoder(x, s=1.5) # Phase vocoder with phase locking (recommended for better quality) x_pv_locked = tsm.phase_vocoder( x, s=1.3, win_type='sin', # 'sin' or 'hann' window win_size=2048, # FFT window size syn_hop_size=512, # Synthesis hop size zero_pad=0, # Zero padding for FFT restore_energy=False, # Energy restoration fft_shift=False, # Circular shift for STFT phase_lock=True # Enable phase locking ) # Non-linear stretching with anchor points x_length = x.shape[-1] anchor_points = np.array([ [0, x_length / 2, x_length], [0, x_length * 0.75, x_length * 1.5] ]) x_pv_nonlinear = tsm.phase_vocoder(x, s=anchor_points, phase_lock=True) sf.write('output_pv.wav', x_pv_locked.T, sr) ``` -------------------------------- ### Harmonic-Percussive Time-Scale Modification (HPTSM) Source: https://context7.com/kaist-maclab/pytsmod/llms.txt HPTSM is a hybrid method for mixed audio content. Customize Harmonic/Percussive Separation (HPSS) and Phase Vocoder/OLA parameters for fine-tuning. Supports non-linear stretching using anchor points. ```python import numpy as np import pytsmod as tsm import soundfile as sf # Load audio (works well with mixed content like drums + melody) x, sr = sf.read('music.wav') x = x.T ``` ```python # Basic HPTSM x_hp = tsm.hptsm(x, s=1.5) ``` ```python # HPTSM with customized parameters x_hp_custom = tsm.hptsm( x, s=1.3, # HPSS parameters hp_len_harm=10, # Median filter length for harmonic hp_len_perc=10, # Median filter length for percussive hp_mask_mode='binary', # 'binary' or 'relative' masking hp_win_type='hann', hp_win_size=1024, hp_hop_size=256, hp_zero_pad=0, hp_fft_shift=False, # Phase vocoder parameters (for harmonic component) pv_win_type='hann', pv_win_size=2048, pv_syn_hop_size=512, pv_zero_pad=0, pv_restore_energy=False, pv_fft_shift=False, pv_phase_lock=True, # OLA parameters (for percussive component) ola_win_type='hann', ola_win_size=256, ola_syn_hop_size=128 ) ``` ```python # Non-linear stretching with anchor points x_length = x.shape[-1] anchor_points = np.array([ [0, x_length / 2, x_length], [0, x_length * 0.8, x_length * 1.5] ]) x_hp_nonlinear = tsm.hptsm(x, s=anchor_points) ``` ```python sf.write('output_hptsm.wav', x_hp_custom.T, sr) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.