Skip to content

scaper prefers soxbindings on Linux, and generate_from_jams() can return corrupted audio; falling back to pysox fixes it #157

@aviad-kardome

Description

@aviad-kardome

Summary

On Linux, if soxbindings is installed, scaper imports it in preference to the regular sox Python package (pysox):

try:
    import soxbindings as sox
except:
    import sox

In my environment, that leads to corrupted audio reconstruction from scaper.generate_from_jams(...).

The same code works correctly if soxbindings is removed and scaper falls back to pysox.

Environment

  • OS: Linux
  • Observed on:
    • WSL2 Ubuntu
    • GCP / GCS Linux VM
  • Python: 3.9
  • scaper: 1.6.5
  • sox: 1.4.0
  • soxbindings: 1.2.3

Expected behavior

scaper.generate_from_jams(...) should reconstruct normal event audio from the JAMS annotations.

Actual behavior

With soxbindings installed on Linux, the reconstructed event audio can be corrupted:

  • constant-valued background
  • ramp-like foregrounds
  • target no longer resembles speech

This happens before any downstream model processing.

Minimal reproduction

This is the smallest reproduction I found that shows the backend issue directly:

python - <<'PY'
import numpy as np
import scaper.core as core

print("scaper backend:", core.sox, getattr(core.sox, "__file__", "n/a"))

tfm = core.sox.Transformer()
tfm.set_output_format(rate=16000, channels=1)

x = np.array([0.1, 0.2, -0.3, 0.4, -0.5], dtype=np.float64)
y = np.asarray(tfm.build_array(input_array=x, sample_rate_in=16000)).reshape(-1)

print("input :", x.tolist())
print("output:", y.tolist())
PY

Expected output

The output should approximately match the input:

input : [0.1, 0.2, -0.3, 0.4, -0.5]
output: [0.1, 0.2, -0.3, 0.4, -0.5]

Actual output with soxbindings

scaper backend: <module 'soxbindings' ...>
input : [0.1, 0.2, -0.3, 0.4, -0.5]
output: [0.1, 0.1, 0.1, 0.1, 0.1]

So soxbindings.Transformer.build_array(input_array=...) appears to repeat the first sample across the output buffer.

Effect on Scaper

In a real scaper.generate_from_jams(...) workload, this backend issue causes corrupted event stems.

After removing soxbindings and letting Scaper fall back to pysox, the exact same workload returns sane audio again.

Workaround

Uninstall soxbindings so that scaper falls back to pysox:

python -m pip uninstall -y soxbindings

After doing that, the backend check above produces the correct output, and generate_from_jams(...) also returns sane audio.

Request

Could Scaper either:

  1. avoid preferring soxbindings by default on Linux, or
  2. provide a way to force pysox, or
  3. at least document that soxbindings may be unsafe in this path?

I realize the low-level bug may live in soxbindings, but Scaper currently prefers that backend automatically, so it is easy to hit this issue without realizing it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions