# Fix "TypeError: mfcc() takes 0 positional arguments but 2 were given" in librosa

Yes. An agent finds every positional librosa call that 0.10 made keyword-only, rewrites them, and runs the feature code on real audio under the old and new releases.

[Run this on Rush](https://cloud.getrush.ai/run/fix-librosa-mfcc-takes-0-positional-arguments/librosa/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

librosa 0.10 made the arguments of most of its functions keyword-only. On 0.11.0, `librosa.feature.mfcc(y, sr)` raises `TypeError: mfcc() takes 0 positional arguments but 2 were given`, and the same shape of error comes from `melspectrogram(y, sr)`, `load(path, sr)`, `resample(y, sr, new_sr)`, `effects.time_stretch(y, factor)`, `effects.pitch_shift(y, sr, n_steps=...)`, `util.fix_length(y, n)` and `time_to_samples(t, sr)`. The same calls with `y=`, `sr=`, `rate=`, `size=`, `orig_sr=` and `target_sr=` work. The release before, 0.9.2, accepts the positional form and prints `FutureWarning: Pass y=..., sr=... as keyword args. From version 0.10 passing these as positional arguments will result in an error`; 0.8.1 accepts it without that warning. `librosa.feature.spectral.rms` is gone too: on 0.11.0 reaching `librosa.feature.spectral` raises `AttributeError`, while `librosa.feature.rms` works.

jrgillick/laughter-detection is a PyTorch model that finds laughter in an audio file, with a CLI in `segment_laughter.py`. `requirements.txt` pins `librosa==0.8.1` and `torch==1.3.1`, and the README says the code was tested with those. The torch pin has no wheel for a current Python, so a new environment either keeps an old interpreter or lifts the pins, and lifting librosa past 0.10 breaks `utils/audio_utils.py` in several places: `featurize_mfcc` calls `librosa.feature.spectral.rms(S=S)` on line 192 and `librosa.feature.mfcc(y,sr,n_mfcc=13, ...)` on line 193; `featurize_melspec` calls `librosa.feature.melspectrogram(y, sr, hop_length=hop_length)` on line 228; both call `librosa.core.time_to_samples(offset,sr)` on lines 186 and 222; and the augmentation helpers use `librosa.core.resample(y,sr,new_sr)` on line 370, `librosa.effects.time_stretch(y, factor)` on line 378, `librosa.effects.pitch_shift(y, sr, n_steps=steps, ...)` on line 386 and `librosa.util.fix_length(new_y, len(y))` on line 361. The `librosa.load` calls, lines 24, 26, 181 and 217 among others, already pass `sr=` by keyword and keep working.

`configs.py` wires `featurize_melspec` into the `resnet_with_augmentation` config that `segment_laughter.py` loads by default, and `utils/data_loaders.py` line 191 calls that feature function on the loaded signal, so the CLI fails on its first audio file before the model runs. The agent lists every librosa call in the repository with its argument style, then checks each one against the installed 0.11.0 by calling it on a short synthetic signal rather than reading a changelog, because the keyword names are not uniform: `resample` wants `orig_sr` and `target_sr`, `time_stretch` wants `rate`, `fix_length` wants `size`. It rewrites each call with keywords, which 0.8.1 and 0.9.2 also accept, replaces `feature.spectral.rms` with `feature.rms`, and moves the pin to a 0.10 or later release.

The test runs the two feature functions on a real file. The agent generates a few seconds of audio with a tone and silence, calls `featurize_mfcc` and `featurize_melspec` on it under the new release and asserts the frame counts and feature widths the model expects, 44 frames by 40 features in the `mlp_mfcc` config's `linear_layer_size`, and runs the augmentation helpers once each. It repeats the test under 0.9.2 to show the keyword form is accepted there, and reports whether 0.8.1 installs on the sandbox's Python at all. The model checkpoints under `checkpoints/` are not loaded and no training data is downloaded.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "This project fails with TypeError: mfcc() takes 0 positional arguments but 2 were given after librosa was upgraded. Read requirements.txt and report the librosa and torch pins and whether each installs on the current Python (try it). Find every librosa call in the repository with file, line and whether its arguments are positional, including feature, effects, core and util functions and librosa.load. Install the current librosa and, for each positional call, run that function on a short synthetic signal to confirm the keyword names it now requires; do not take them from memory. Rewrite each call with keywords, replace any librosa.feature.spectral.* attribute that no longer exists with its current name, and leave calls that already use keywords alone. Update the librosa pin. Write a test that generates a few seconds of audio, runs the project's feature functions and augmentation helpers, and asserts the output shapes; run it on the current librosa and on 0.9.2. Do not load model checkpoints and do not download datasets. Open a pull request listing every changed call, the install results for the old pins, and the test output on both releases.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

A pull request that changes about ten lines in `utils/audio_utils.py`, adds a test, and moves the librosa pin. Its description is a table: each librosa call by file and line, the positional form it had, the keyword form it has now, and the release at which the positional form started to fail, as observed in the sandbox rather than quoted from a changelog.

The session's record holds the install attempts for the old pins with the resolver's messages, the per-function checks against the installed release, and the test output on both releases with the feature shapes printed. That is what tells a reviewer that `featurize_melspec` still produces the frame layout the trained checkpoints expect.

Before merging, a reviewer runs `segment_laughter.py` once on a known clip with the checkpoint, which the sandbox was told not to load, and compares the detected segments with a previous run. The pull request also notes that the torch pin is as old as the librosa one and raises it as a separate change.

## Run it on every failed install on a new machine

Research code breaks when someone new sets it up, and the signal is an install or a first run that fails. A small script on your side sends this request with `POST /o/{org}/sessions`, the repository in `resources` and the failing command's output appended to `input`, with a `request_id` that is a UUID v5 of the failure's log id so a retry returns the run it already started.

A lab with several audio projects pinned to the same librosa line sends one request per repository; each is its own sandbox, and runs past the key's `max_concurrent` limit wait in the queue and start as slots free. The key's webhook posts `run.completed` for each with the session URL, and a repository whose old pins cannot install at all gets a pull request that says so, with the resolver's output, instead of a half-finished port.

## Why run it on Rush?

A librosa port is a list of small renames that each need checking, and the only trustworthy check is to run the function on the installed release. The agent does that for every call in a sandbox where it can install three librosa releases and an old torch without touching the lab's shared environment, and the checks are kept with the run.

The pull request is reviewable by someone who did not write the code: the table of calls comes from the search, the keyword names from the package, and the shapes from the test, with the model and its data left out so the run finishes in minutes. The parts that need the checkpoint are named for the reviewer rather than skipped quietly.

## Frequently asked questions

### Which librosa release broke positional arguments?

0.10. On 0.9.2 `mfcc(y, sr)` runs with a `FutureWarning` that names 0.10 as the release where it becomes an error, and on 0.10.0 and 0.11.0 it raises the `TypeError`. The keyword form works on all of them.

### Are the keyword names the same for every function?

No, which is why the agent checks each one. `mfcc` and `melspectrogram` take `y=` and `sr=`, `resample` takes `orig_sr=` and `target_sr=`, `time_stretch` takes `rate=`, `fix_length` takes `size=`, and `time_to_samples` takes `sr=`. Guessing them from the old positional order gives a second round of errors.

### What happened to librosa.feature.spectral.rms?

On 0.11.0 `librosa.feature.spectral` is no longer an attribute, so the call on line 192 fails before the `mfcc` call on the next line gets a chance to. `librosa.feature.rms(S=S)` is the current name and the pull request uses it.

### Can I keep librosa 0.8.1 and torch 1.3.1?

Only on an old Python: the torch pin has no wheel for a current interpreter, and the pull request reports what the librosa pin did on the sandbox's Python. Keyword arguments work on 0.8.1 too, so the port does not force the upgrade; it makes the code work on either side of it.

### Does the agent run the laughter model?

No. The test exercises the feature and augmentation functions on generated audio and asserts shapes. Running the checkpoint on a real clip and comparing segments is left to the reviewer and named in the pull request.

## More jobs like this: Fix a bug from an alert

- [Fix "SetuptoolsDeprecationWarning: License classifiers are deprecated" and "project.license as a TOML table is deprecated"](https://getrush.ai/run/fix-license-classifiers-are-deprecated/setuptools/)
- [Fix "AttributeError: module 'locale' has no attribute 'format'" on Python 3.12](https://getrush.ai/run/fix-locale-format-attribute-error/locale/)
- [Fix "warning: Logger.warn/1 is deprecated. Use Logger.warning/2 instead" in an Elixir Library](https://getrush.ai/run/fix-logger-warn-is-deprecated/elixir/)
- [Fix "module declares its path as: github.com/sirupsen/logrus" in a Go Project](https://getrush.ai/run/fix-logrus-module-path-mismatch/logrus/)
- [Fix "ImportError: lxml.html.clean module is now a separate project lxml_html_clean"](https://getrush.ai/run/fix-lxml-html-clean-separate-project-import-error/lxml/)
- [Fix "TypeError: marked is not a function" After Upgrading marked](https://getrush.ai/run/fix-marked-is-not-a-function/marked/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
