### SRMR Command-Line Interface Source: https://github.com/jfsantos/srmrpy/blob/master/README.md The SRMR toolbox can be invoked from the command line. The wrapper accepts a path to audio files or a folder, along with several optional arguments to customize the SRMR calculation. ```APIDOC ## SRMR Command-Line Usage ### Description This command-line interface allows users to process audio files or entire folders to calculate the Speech-to-Reverberation Modulation Energy Ratio (SRMR). ### Arguments #### Positional Arguments - **path** (string) - Required - Path of the file or files to be processed. Can also be a folder. #### Optional Arguments - **-h, --help** - show this help message and exit - **-f, --fast** - Use the faster version based on the gammatonegram - **-n, --norm** - Use modulation spectrum energy normalization - **--ncochlearfilters N_COCHLEAR_FILTERS** - Number of filters in the acoustic filterbank - **--mincf MIN_CF** - Center frequency of the first modulation filter - **--maxcf MAX_CF** - Center frequency of the last modulation filter ``` -------------------------------- ### Build and Apply Modulation Filters Source: https://context7.com/jfsantos/srmrpy/llms.txt Creates a bank of IIR bandpass filters and applies them to a signal's amplitude envelope. Use `modulation_filterbank` to build the filters and `modfilt` to apply them for modulation analysis. ```python import numpy as np from srmrpy.modulation_filters import compute_modulation_cfs, modulation_filterbank, modfilt fs_mod = 400 # modulation sampling rate used in fast mode mf = compute_modulation_cfs(min_cf=4, max_cf=128, n=8) # Build 8 bandpass IIR filters with Q=2 MF = modulation_filterbank(mf, fs_mod, Q=2) print(f"Number of filters: {len(MF)}") # 8 print(f"Filter coefficients (b, a): {MF[0][0].shape}, {MF[0][1].shape}") # Apply filterbank to a gammatone envelope (simulated here) rng = np.random.default_rng(42) envelope = np.abs(rng.standard_normal(4000)) # 10 s at 400 Hz mod_output = modfilt(MF, envelope) print(f"Modulation output shape: {mod_output.shape}") # Modulation output shape: (8, 4000) # Each row is the envelope passed through one modulation band ``` -------------------------------- ### srmr CLI — Batch process WAV files from the command line Source: https://context7.com/jfsantos/srmrpy/llms.txt The `srmr` console script wraps the Python API with an argument parser, enabling single-file and multi-file batch processing. When multiple files are provided, it uses `multiprocessing.Pool` with all available CPU cores for parallel computation. ```APIDOC ## srmr CLI — Batch process WAV files from the command line ### Description The `srmr` console script wraps the Python API with an argument parser, enabling single-file and multi-file batch processing. When multiple files are provided, it uses `multiprocessing.Pool` with all available CPU cores for parallel computation. ### Usage ```bash # Install the package (registers the 'srmr' console script) python setup.py install # Compute SRMR for a single WAV file (slow mode, default settings) srmr speech_reverb.wav # Output: speech_reverb.wav: 0.8731 # Fast mode using FFT-based gammatonegram srmr --fast speech_reverb.wav # Output: speech_reverb.wav: 0.8802 # Normalized metric (recommended for cochlear implant evaluation) srmr --fast --norm --maxcf 30 speech_reverb.wav # Output: speech_reverb.wav: 1.2043 # Batch process an entire folder of WAV files (runs in parallel) srmr --fast /path/to/wav/folder/*.wav # Output: # /path/to/wav/folder/file1.wav: 0.9012 # /path/to/wav/folder/file2.wav: 0.7654 # /path/to/wav/folder/file3.wav: 1.1023 # All available options srmr --help # positional arguments: # path Path of the file or files to be processed. # optional arguments: # -f, --fast Use the faster gammatonegram-based version # -n, --norm Use modulation spectrum energy normalization # --ncochlearfilters N Number of filters in the acoustic filterbank (default: 23) # --mincf MIN_CF Center frequency of the first modulation filter (default: 4.0) # --maxcf MAX_CF Center frequency of the last modulation filter (default: 128.0) ``` ``` -------------------------------- ### Compute SRMR metric using CLI Source: https://context7.com/jfsantos/srmrpy/llms.txt Batch process WAV files using the 'srmr' console script. Supports single files, multiple files, and parallel processing. Use flags like --fast and --norm for different computation modes. ```bash # Install the package (registers the 'srmr' console script) python setup.py install # Compute SRMR for a single WAV file (slow mode, default settings) srmr speech_reverb.wav # Output: speech_reverb.wav: 0.8731 # Fast mode using FFT-based gammatonegram srmr --fast speech_reverb.wav # Output: speech_reverb.wav: 0.8802 # Normalized metric (recommended for cochlear implant evaluation) srmr --fast --norm --maxcf 30 speech_reverb.wav # Output: speech_reverb.wav: 1.2043 # Batch process an entire folder of WAV files (runs in parallel) srmr --fast /path/to/wav/folder/*.wav # Output: # /path/to/wav/folder/file1.wav: 0.9012 # /path/to/wav/folder/file2.wav: 0.7654 # /path/to/wav/folder/file3.wav: 1.1023 # All available options srmr --help # positional arguments: # path Path of the file or files to be processed. # optional arguments: # -f, --fast Use the faster gammatonegram-based version # -n, --norm Use modulation spectrum energy normalization # --ncochlearfilters N Number of filters in the acoustic filterbank (default: 23) # --mincf MIN_CF Center frequency of the first modulation filter (default: 4.0) # --maxcf MAX_CF Center frequency of the last modulation filter (default: 128.0) ``` -------------------------------- ### Compute SRMR metric using Python API Source: https://context7.com/jfsantos/srmrpy/llms.txt Load a WAV file and compute SRMR using the srmr function. Supports original, fast, and normalized variants, as well as custom filterbank parameters. Ensure audio is normalized to float [-1, 1] and select a single channel if stereo. ```python import numpy as np from scipy.io.wavfile import read as readwav from srmrpy import srmr # Load a 16 kHz WAV file fs, s = readwav("speech.wav") # Normalize integer PCM to float [-1, 1] if np.issubdtype(s.dtype, np.integer): s = s.astype("float") / np.iinfo(s.dtype).max # Use stereo channel 0 if multi-channel if s.ndim > 1: s = s[:, 0] # --- Original SRMR (slow, time-domain gammatone filterbank) --- ratio, energy = srmr(s, fs, fast=False) print(f"Original SRMR ratio: {ratio:.4f}") # Example output: Original SRMR ratio: 0.8731 # --- Fast SRMR (FFT-based gammatonegram, default) --- ratio_fast, energy_fast = srmr(s, fs, fast=True) print(f"Fast SRMR ratio: {ratio_fast:.4f}") # --- Normalized SRMR (reduced variability, max_cf=30 for CI users) --- ratio_norm, energy_norm = srmr(s, fs, fast=True, norm=True, max_cf=30) print(f"Normalized SRMR ratio: {ratio_norm:.4f}") # --- Custom filterbank parameters --- ratio_custom, energy_custom = srmr( s, fs, n_cochlear_filters=23, # number of gammatone filters low_freq=125, # lowest center frequency (Hz) min_cf=4, # lowest modulation filter CF (Hz) max_cf=128, # highest modulation filter CF (Hz) fast=True, norm=False ) print(f"Custom SRMR ratio: {ratio_custom:.4f}") # Inspect energy array: shape is (n_cochlear_filters, 8, n_frames) print(f"Energy array shape: {energy_custom.shape}") # Example output: Energy array shape: (23, 8, 47) ``` -------------------------------- ### SRMRpy Command-Line Wrapper Arguments Source: https://github.com/jfsantos/srmrpy/blob/master/README.md Arguments for the `srmr` command-line wrapper. Use `-f` for the faster version and `-n` for normalization. ```bash positional arguments: path Path of the file or files to be processed. Can also be a folder. optional arguments: -h, --help show this help message and exit -f, --fast Use the faster version based on the gammatonegram -n, --norm Use modulation spectrum energy normalization --ncochlearfilters N_COCHLEAR_FILTERS Number of filters in the acoustic filterbank --mincf MIN_CF Center frequency of the first modulation filter --maxcf MAX_CF Center frequency of the last modulation filter ``` -------------------------------- ### modulation_filterbank and modfilt Source: https://context7.com/jfsantos/srmrpy/llms.txt Builds a bank of modulation filters and applies them to a signal. `modulation_filterbank` creates the filters, and `modfilt` applies them to an input signal, typically an amplitude envelope. ```APIDOC ## modulation_filterbank and modfilt — Build and apply modulation filters `modulation_filterbank` creates a bank of 2nd-order IIR bandpass filters centered at the provided modulation frequencies. `modfilt` applies this filterbank to a 1D signal (the amplitude envelope of a gammatone channel), returning the filtered output for each modulation band. These two functions together form the core modulation analysis stage. ### Usage ```python import numpy as np from srmrpy.modulation_filters import compute_modulation_cfs, modulation_filterbank, modfilt fs_mod = 400 # modulation sampling rate used in fast mode mf = compute_modulation_cfs(min_cf=4, max_cf=128, n=8) # Build 8 bandpass IIR filters with Q=2 MF = modulation_filterbank(mf, fs_mod, Q=2) # Apply filterbank to a gammatone envelope (simulated here) rng = np.random.default_rng(42) envelope = np.abs(rng.standard_normal(4000)) # 10 s at 400 Hz mod_output = modfilt(MF, envelope) ``` ### Parameters * **modulation_filterbank**: * **mf** (array-like) - Array of center frequencies for the filters. * **fs_mod** (int) - The modulation sampling rate. * **Q** (float, optional) - The quality factor for the bandpass filters. Defaults to 2. * **modfilt**: * **MF** (list of tuples) - The filterbank coefficients generated by `modulation_filterbank`. * **envelope** (array-like) - The 1D signal (e.g., amplitude envelope) to filter. ``` -------------------------------- ### Compute Modulation Filter Center Frequencies Source: https://context7.com/jfsantos/srmrpy/llms.txt Generates logarithmically-spaced center frequencies for modulation filters. Useful for defining the range and number of filters for temporal envelope analysis. ```python from srmrpy.modulation_filters import compute_modulation_cfs # Default configuration: 8 filters from 4 to 128 Hz cfs = compute_modulation_cfs(min_cf=4, max_cf=128, n=8) print(cfs) # [ 4. 5.6568... 8. 11.3137... 16. 22.627... 32. 128. ] # CI-tailored configuration: narrower range up to 30 Hz cfs_ci = compute_modulation_cfs(min_cf=4, max_cf=30, n=8) print(cfs_ci) # [ 4. 5.159... 6.653... 8.579... 11.066... 14.272... 18.406... 30. ] ``` -------------------------------- ### Compute Analytic Signal using Hilbert Transform Source: https://context7.com/jfsantos/srmrpy/llms.txt Computes the analytic signal by zeroing the negative frequency spectrum. The FFT length is rounded up to the next multiple of 16 for performance. Used to extract instantaneous envelopes. ```python import numpy as np from srmrpy.hilbert import hilbert # Synthetic AM signal: 1 kHz carrier, 10 Hz modulation fs = 16000 t = np.arange(fs) / fs carrier = np.sin(2 * np.pi * 1000 * t) modulator = 0.5 * (1 + np.sin(2 * np.pi * 10 * t)) am_signal = modulator * carrier # Recover the envelope via Hilbert transform analyic = hilbert(am_signal) envelope = np.abs(analytic) print(f"Analytic signal dtype : {analytic.dtype}") # complex128 print(f"Envelope peak : {envelope.max():.4f}") # ≈ 1.0 print(f"Envelope mean : {envelope.mean():.4f}") # ≈ 0.5 ``` -------------------------------- ### srmr — Compute the SRMR metric for a speech signal Source: https://context7.com/jfsantos/srmrpy/llms.txt The primary entry point of the library. Accepts a NumPy array of speech samples and a sampling rate, then returns the SRMR ratio (a scalar quality score) along with the full 3D modulation energy array. Higher ratio values generally indicate better speech quality and intelligibility. Setting `fast=True` uses an FFT-based gammatonegram instead of the time-domain filterbank for faster processing; `norm=True` applies modulation spectrum energy normalization for reduced variability and improved CI (cochlear implant) intelligibility estimation. ```APIDOC ## srmr — Compute the SRMR metric for a speech signal ### Description The primary entry point of the library. Accepts a NumPy array of speech samples and a sampling rate, then returns the SRMR ratio (a scalar quality score) along with the full 3D modulation energy array. Higher ratio values generally indicate better speech quality and intelligibility. Setting `fast=True` uses an FFT-based gammatonegram instead of the time-domain filterbank for faster processing; `norm=True` applies modulation spectrum energy normalization for reduced variability and improved CI (cochlear implant) intelligibility estimation. ### Parameters - **s** (numpy.ndarray) - Speech samples. - **fs** (int) - Sampling rate. - **fast** (bool, optional) - Use the faster gammatonegram-based version. Defaults to `False`. - **norm** (bool, optional) - Use modulation spectrum energy normalization. Defaults to `False`. - **n_cochlear_filters** (int, optional) - Number of filters in the acoustic filterbank. Defaults to 23. - **low_freq** (int, optional) - Lowest center frequency (Hz) for the acoustic filterbank. Defaults to 125. - **min_cf** (int, optional) - Center frequency of the first modulation filter (Hz). Defaults to 4. - **max_cf** (int, optional) - Center frequency of the last modulation filter (Hz). Defaults to 128. ### Returns - **ratio** (float) - The SRMR ratio (a scalar quality score). - **energy** (numpy.ndarray) - The full 3D modulation energy array with shape (n_cochlear_filters, 8, n_frames). ### Request Example ```python import numpy as np from scipy.io.wavfile import read as readwav from srmrpy import srmr # Load a 16 kHz WAV file fs, s = readwav("speech.wav") # Normalize integer PCM to float [-1, 1] if np.issubdtype(s.dtype, np.integer): s = s.astype("float") / np.iinfo(s.dtype).max # Use stereo channel 0 if multi-channel if s.ndim > 1: s = s[:, 0] # --- Original SRMR (slow, time-domain gammatone filterbank) --- ratio, energy = srmr(s, fs, fast=False) print(f"Original SRMR ratio: {ratio:.4f}") # --- Fast SRMR (FFT-based gammatonegram, default) --- ratio_fast, energy_fast = srmr(s, fs, fast=True) print(f"Fast SRMR ratio: {ratio_fast:.4f}") # --- Normalized SRMR (reduced variability, max_cf=30 for CI users) --- ratio_norm, energy_norm = srmr(s, fs, fast=True, norm=True, max_cf=30) print(f"Normalized SRMR ratio: {ratio_norm:.4f}") # --- Custom filterbank parameters --- ratio_custom, energy_custom = srmr( s, fs, n_cochlear_filters=23, # number of gammatone filters low_freq=125, # lowest center frequency (Hz) min_cf=4, # lowest modulation filter CF (Hz) max_cf=128, # highest modulation filter CF (Hz) fast=True, norm=False ) print(f"Custom SRMR ratio: {ratio_custom:.4f}") # Inspect energy array: shape is (n_cochlear_filters, 8, n_frames) print(f"Energy array shape: {energy_custom.shape}") ``` ### Response Example ```json { "ratio": 0.8731, "energy": [[[...]]] } ``` ``` -------------------------------- ### Segment Signal Array into Overlapping Frames Source: https://context7.com/jfsantos/srmrpy/llms.txt A memory-efficient utility to create overlapping segments (frames) from a signal array without copying data. Supports different end-handling strategies like 'cut', 'pad', and 'wrap'. ```python import numpy as np from srmrpy.segmentaxis import segment_axis signal = np.arange(20, dtype=float) # 4-sample frames with 2-sample overlap, discard trailing samples frames_cut = segment_axis(signal, length=4, overlap=2, end='cut') print(frames_cut) # [[ 0. 1. 2. 3.] # [ 2. 3. 4. 5.] # [ 4. 5. 6. 7.] # ... # [16. 17. 18. 19.]] # Pad the last frame with zeros to retain all samples frames_pad = segment_axis(signal, length=4, overlap=2, end='pad', endvalue=0) print(f"Padded frame count: {frames_pad.shape[0]}") # Use with a real modulation output channel for energy computation from scipy.signal.windows import hamming wLength, wInc = 102, 25 # samples at 400 Hz ≈ 256 ms / 64 ms w = hamming(wLength + 1)[:-1] # periodic Hamming window mod_channel = np.random.default_rng(0).standard_normal(4000) framed = segment_axis(mod_channel, wLength, overlap=wLength - wInc, end='pad') energy_per_frame = np.sum((w * framed) ** 2, axis=1) print(f"Energy frames shape: {energy_per_frame.shape}") ``` -------------------------------- ### Energy-based Voice Activity Detection (VAD) Source: https://context7.com/jfsantos/srmrpy/llms.txt Performs frame-level VAD using energy thresholds relative to peak frame energy. Returns voiced samples and a boolean mask, useful for preprocessing to exclude silence before SRMR computation. ```python import numpy as np from scipy.io.wavfile import read as readwav from srmrpy.vad import simple_energy_vad from srmrpy import srmr fs, s = readwav("speech.wav") s = s.astype("float") / np.iinfo(s.dtype).max # Apply VAD: keep only frames within 30 dB of peak energy # and above an absolute floor of -55 dB s_voiced, vad_mask = simple_energy_vad( s, fs, framelen=0.02, # 20 ms frames theta_main=30, # dynamic range threshold (dB) theta_min=-55 # absolute energy floor (dB) ) print(f"Original samples : {len(s)}") print(f"Voiced samples : {len(s_voiced)}") print(f"Speech proportion: {vad_mask.mean()*100:.1f}%") # Compute SRMR only on voiced segments ratio, energy = srmr(s_voiced, fs, fast=True) print(f"SRMR (voiced only): {ratio:.4f}") ``` -------------------------------- ### SRMR Python Function Source: https://github.com/jfsantos/srmrpy/blob/master/README.md The core SRMR functionality is exposed as a Python function, `srmr`, which accepts a NumPy array representing the audio signal and its sampling rate, along with various optional parameters for customization. ```APIDOC ## srmr(x, fs, n_cochlear_filters=23, low_freq=125, min_cf=4, max_cf=128, fast=True, norm=False) ### Description Calculates the Speech-to-Reverberation Modulation Energy Ratio (SRMR) for a given audio signal. ### Parameters - **x** (numpy.ndarray) - Required - A Numpy array containing the audio signal. - **fs** (int) - Required - The sampling rate of the audio signal. - **n_cochlear_filters** (int) - Optional - Number of filters in the acoustic filterbank. Defaults to 23. - **low_freq** (int) - Optional - Center frequency of the first modulation filter. Defaults to 125 Hz. - **min_cf** (int) - Optional - Center frequency of the first modulation filter. Defaults to 4. - **max_cf** (int) - Optional - Center frequency of the last modulation filter. Defaults to 128. - **fast** (bool) - Optional - Use the faster version based on the gammatonegram. Defaults to True. - **norm** (bool) - Optional - Use modulation spectrum energy normalization. Defaults to False. ``` -------------------------------- ### simple_energy_vad Source: https://context7.com/jfsantos/srmrpy/llms.txt Performs energy-based Voice Activity Detection (VAD) to identify voiced speech segments. It returns the voiced speech samples and a boolean mask indicating speech activity. ```APIDOC ## simple_energy_vad — Energy-based Voice Activity Detection A simple frame-level VAD that identifies voiced speech regions using energy thresholds relative to the peak frame energy. Returns only the speech-active samples and a boolean mask. Based on the benchmark method described by Kinnunen and Rajan (ICASSP 2013). Useful for preprocessing before SRMR computation to exclude silence. ### Usage ```python import numpy as np from scipy.io.wavfile import read as readwav from srmrpy.vad import simple_energy_vad from srmrpy import srmr fs, s = readwav("speech.wav") s = s.astype("float") / np.iinfo(s.dtype).max # Apply VAD: keep only frames within 30 dB of peak energy # and above an absolute floor of -55 dB s_voiced, vad_mask = simple_energy_vad( s, fs, framelen=0.02, # 20 ms frames theta_main=30, # dynamic range threshold (dB) theta_min=-55 # absolute energy floor (dB) ) # Compute SRMR only on voiced segments ratio, energy = srmr(s_voiced, fs, fast=True) ``` ### Parameters * **signal** (array-like) - The input audio signal. * **fs** (int) - The sampling rate of the signal. * **framelen** (float, optional) - The duration of each analysis frame in seconds. Defaults to 0.02. * **theta_main** (float, optional) - The dynamic range threshold in dB. Frames with energy below `peak_energy - theta_main` are considered silence. Defaults to 30. * **theta_min** (float, optional) - The absolute minimum energy threshold in dB. Frames with energy below this are considered silence. Defaults to -55. ``` -------------------------------- ### SRMRpy Function API Source: https://github.com/jfsantos/srmrpy/blob/master/README.md The `srmr` function accepts a Numpy array `x` and sampling rate `fs`. Optional arguments control filter counts, frequency ranges, speed, and normalization. ```python srmr(x, fs, n_cochlear_filters=23, low_freq=125, min_cf=4, max_cf=128, fast=True, norm=False) ``` -------------------------------- ### segment_axis Source: https://context7.com/jfsantos/srmrpy/llms.txt Chops a signal array into overlapping frames or segments. This utility is memory-efficient and supports various strategies for handling the end of the array. ```APIDOC ## segment_axis — Chop a signal array into overlapping frames A memory-efficient framing utility that creates a view of the input array as overlapping segments without copying data (unless required by the end-handling mode). Supports `'cut'`, `'pad'`, `'wrap'`, and `'delay'` strategies for handling the last partial frame. ### Usage ```python import numpy as np from srmrpy.segmentaxis import segment_axis signal = np.arange(20, dtype=float) # 4-sample frames with 2-sample overlap, discard trailing samples frames_cut = segment_axis(signal, length=4, overlap=2, end='cut') # Pad the last frame with zeros to retain all samples frames_pad = segment_axis(signal, length=4, overlap=2, end='pad', endvalue=0) # Example with modulation output from scipy.signal.windows import hamming wLength, wInc = 102, 25 # samples at 400 Hz ≈ 256 ms / 64 ms w = hamming(wLength + 1)[:-1] # periodic Hamming window mod_channel = np.random.default_rng(0).standard_normal(4000) framed = segment_axis(mod_channel, wLength, overlap=wLength - wInc, end='pad') energy_per_frame = np.sum((w * framed) ** 2, axis=1) ``` ### Parameters * **signal** (array-like) - The input signal array. * **length** (int) - The desired length of each frame. * **overlap** (int) - The number of samples of overlap between consecutive frames. * **end** (str, optional) - Strategy for handling the end of the signal. Options: `'cut'`, `'pad'`, `'wrap'`, `'delay'`. Defaults to `'cut'`. * **endvalue** (float, optional) - The value to use for padding if `end='pad'`. Defaults to 0. ``` -------------------------------- ### compute_modulation_cfs Source: https://context7.com/jfsantos/srmrpy/llms.txt Generates logarithmically-spaced center frequencies for modulation filters. These frequencies are used to define the modulation filterbank for analyzing temporal envelope fluctuations. ```APIDOC ## compute_modulation_cfs — Compute logarithmically-spaced modulation filter center frequencies Generates `n` center frequencies spaced geometrically between `min_cf` and `max_cf`. These frequencies define the modulation filterbank used to analyze temporal envelope fluctuations in each gammatone channel. By default, 8 filters are created between 4 Hz and 128 Hz. ### Usage ```python from srmrpy.modulation_filters import compute_modulation_cfs # Default configuration: 8 filters from 4 to 128 Hz cfs = compute_modulation_cfs(min_cf=4, max_cf=128, n=8) print(cfs) # CI-tailored configuration: narrower range up to 30 Hz cfs_ci = compute_modulation_cfs(min_cf=4, max_cf=30, n=8) print(cfs_ci) ``` ### Parameters * **min_cf** (float) - The minimum center frequency. * **max_cf** (float) - The maximum center frequency. * **n** (int) - The number of center frequencies to generate. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.