# Fix "ModuleNotFoundError: No module named 'audioop'" on Python 3.13

Yes. An agent finds what your code used audioop for, replaces it with a backport or a few lines of NumPy, and proves the audio samples come out identical.

[Run this on Rush](https://cloud.getrush.ai/run/fix-no-module-named-audioop/audioop/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

Python 3.13 removed `audioop`, the module of small routines for raw audio samples. The agent starts by measuring how much of it the code uses, because that decides the fix. MycroftAI/mimic3 is a common case: a large module brought down by one call. `mimic3_tts/tts.py` has `import audioop` on line 17, at the top of the file that holds the whole synthesis class, and the only use is line 543, `audioop.mul(audio_bytes, 2, settings.volume / 100.0)`, inside a check that the volume setting differs from `DEFAULT_VOLUME`. Volume scaling is an optional step that the default setting skips. On 3.13 none of that matters, since the import fails first and nothing in the file can be loaded. The project's README says it is no longer actively maintained, which is the usual state of code that hits this error: it works, people still run it, and nobody was watching the deprecation.

The agent reproduces the failure on 3.13 and records the warning 3.12 prints for the same import, `'audioop' is deprecated and slated for removal in Python 3.13`. Then it weighs two fixes. The backport package `audioop-lts` restores the module for 3.13 and later with the import unchanged. The alternative is to drop the dependency: the audio is already a NumPy array one line earlier, where the code calls `audio.tobytes()`, so the scaling can happen on the array before it is turned into bytes.

That second option has a trap the agent tests for. `audioop.mul` multiplies each 16-bit sample, rounds down, and clips to the valid range. The natural NumPy line, multiply and convert with `astype(np.int16)`, rounds toward zero instead. The agent builds a buffer of 48,000 random samples plus the extreme values, runs it through the original function on 3.12, and compares. Truncation differs from the original on about a quarter of the samples at a factor of 0.5, each by one unit, all of them negative values. With `np.floor` before the conversion and `np.clip` to the 16-bit range, every sample matches at each factor tried, including one above 1.0 where clipping applies. The backport on 3.13 matches too. One unit is inaudible, but this repository checks audio by hash: `tests/sample_hashes.txt` stores a SHA-256 per voice and `test.sh` diffs against it. Those samples are made at the default volume and never reach this line, yet they show the standard the project holds its output to, which is exact bytes.

With the numbers in hand the agent picks one fix and says why. It also moves or removes the top-level import, so an optional feature can no longer take the module down. It then tries the remaining installation on 3.13 and reports what else blocks it, without fixing those in the same pull request. Here `requirements.txt` holds `numpy<2.0` and an `onnxruntime` range, and `setup.py` lists classifiers only up to Python 3.9.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "This project fails on Python 3.13 with \"ModuleNotFoundError: No module named 'audioop'\". Find every import of audioop and every function of it the code calls, with the sample width and arguments used, and say for each call whether it runs always or only for an optional setting. Reproduce the import error on Python 3.13 and save the traceback, and record the deprecation warning on Python 3.12. Then compare two fixes: adding the audioop-lts backport as a dependency for Python 3.13 and later, or replacing the calls with NumPy or plain Python and removing the dependency. For any replacement you write, prove it is sample-for-sample identical to the original: generate a buffer of at least 48,000 random samples that includes the minimum and maximum values, run the original audioop function on Python 3.12 and your replacement on the same bytes for several factors or parameters, and report the number of differing samples, which must be zero. Pay attention to rounding of negative values and to clipping. If the project compares audio output by hash or exact bytes anywhere, say so and treat any difference as a failure. Make sure a missing optional feature can no longer stop the whole module from importing. Then try to install the project on Python 3.13 and list any other dependency that prevents it, without fixing those here. Open a pull request with the traceback, the comparison table, the tests you ran and what you left alone.",
  "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 a few lines of `mimic3_tts/tts.py` and, for the backport route, one line of `requirements.txt` with a marker for Python 3.13 and later. The description carries the comparison as a table: for each factor, how many of the 48,000 samples differ between the original function and each candidate. The rejected candidate stays in the table with its count, because the reason for adding a floor to the arithmetic is otherwise invisible in the diff.

A reviewer checks that the count for the chosen fix is zero at every factor, that a factor above 1.0 is among them, and that the import no longer sits where it can fail unconditionally. They also read the section on what else blocks 3.13. The agent does not claim the application now runs there. Synthesis needs voices and a model runtime that this job does not exercise, and the description says the proof covers the scaling step and the import, not speech output.

## Run it on every service that fails to start after a Python upgrade

A text-to-speech or telephony service that dies at import produces one traceback when its container or host image moves to Python 3.13. Most error trackers sign their own webhook deliveries and cannot send the `Authorization: Bearer` header a Rush `webhook` trigger requires, so place a small handler on your server between them. It keeps events whose message contains `No module named 'audioop'` and posts the traceback to the trigger's URL with the trigger's secret. The body is placed after the saved prompt as event text.

The top frame of that traceback tells the agent whether the import is in your code or in a dependency. When it is a dependency, the result is a version bump to a release that no longer needs the module, or the backport added to your own requirements. A crash loop repeats the alert, so keep the automation's max runs per hour at one or two.

## Why run it on Rush?

The proof here is a comparison across interpreters: the original function exists only on 3.12 and earlier, and the failure exists only on 3.13. The agent installs both in its sandbox, generates the test buffer once, and runs each candidate against the reference. The commands and their counts are kept with the session, so the zero in the pull request can be traced to the run that produced it.

Audio code is also where a nearly right answer passes casual review. A replacement that sounds the same and differs in a quarter of its samples would be merged by ear and then break a hash check or a golden file weeks later. Asking for sample-level equality, and getting it from a run instead of an argument, removes that class of surprise.

## Frequently asked questions

### What replaces audioop in Python 3.13?

The `audioop-lts` package provides the same module for Python 3.13 and later, so `import audioop` keeps working once it is installed. If you use only one or two functions, a few lines of NumPy can replace them and remove the dependency. The agent compares both against the original output before choosing.

### Is a NumPy multiply the same as audioop.mul?

Not by default. `audioop.mul` rounds each product down and clips it to the sample width, while converting a float array with `astype` rounds toward zero, so negative samples can differ by one. Apply `np.floor` and `np.clip` before the conversion to get identical bytes.

### The traceback points at a library such as an audio toolkit, not my code. What then?

The agent does not patch installed packages. It identifies which requirement imports `audioop`, checks whether a newer release has dropped it or declares the backport, and proposes that upgrade. If none exists it adds `audioop-lts` to your requirements for 3.13 and later and says why.

### Does adding audioop-lts change behaviour on older Pythons?

It should not be installed there. The agent adds it with an environment marker so that interpreters before 3.13 keep using the standard-library module, and it runs the comparison on both sides of that line.

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

- [Fix "ModuleNotFoundError: No module named 'cgi'" on Python 3.13](https://getrush.ai/run/fix-no-module-named-cgi/python/)
- [Fix "ModuleNotFoundError: No module named 'crypt'" on Python 3.13](https://getrush.ai/run/fix-no-module-named-crypt/crypt/)
- [Fix "ModuleNotFoundError: No module named 'dash_core_components'"](https://getrush.ai/run/fix-no-module-named-dash-core-components/dash/)
- [Fix "ModuleNotFoundError: No module named 'fabric.api'" by Porting a fabfile to Fabric 3](https://getrush.ai/run/fix-no-module-named-fabric-api/fabric/)
- [Fix "ModuleNotFoundError: No module named 'imghdr'" on Python 3.13](https://getrush.ai/run/fix-no-module-named-imghdr/imghdr/)
- [Fix ModuleNotFoundError: No module named 'imp' on Python 3.12](https://getrush.ai/run/fix-no-module-named-imp/imp/)

## 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/)
