Skip to content

Python Room Acoustics API ​

Room-acoustics measurement and synthesis in the libsonare Python package; the other audio effects are on Python Effects API. The same calls for the browser are on JavaScript/TypeScript Room Acoustics API, and interpretation notes are on Room Acoustics.

Room Acoustics ​

Use these functions for the room or playback space, not for song structure.

GoalUse
Measure a clean impulse responseanalyze_impulse_response(...)
Estimate room decay from ordinary audiodetect_acoustic(...)
Fit a practical room model from audioestimate_room(...)
Create a mono room impulse response from dimensionssynthesize_rir(...)
Add a target-room character as an effectroom_morph(...)
Add the same character to a stereo recording, heard at two spaced receiversroom_morph_stereo(...)
python
# Morph a stereo recording toward a target room heard by two receivers.
def room_morph_stereo(
    left: Sequence[float] | list[float],
    right: Sequence[float] | list[float],
    sample_rate: int,
    length_m: float,
    width_m: float,
    height_m: float,
    *,
    receiver_spacing_m: float | None = None,
    source: tuple[float, float, float] | None = None,
    listener: tuple[float, float, float] | None = None,
    absorption: float = 0.2,
    band_absorption: Sequence[float] | None = None,
    band_scattering: Sequence[float] | None = None,
    material_preset: MaterialPresetName = 'none',
    source_tail_suppression: float = 0.5,
    wet: float = 0.5,
    ism_order: int = 3,
    prefer_eyring: bool = True,
    seed: int | None = None,
    max_sec: float | None = None,
    mixing_time_ms: float | None = None,
    crossfade_ms: float | None = None,
    air_absorption_enabled: bool = True,
    air_temperature_c: float | None = None,
    air_humidity_percent: float | None = None,
) -> RoomMorphStereoResult: ...

Defaults and terms

analyze_impulse_response(...) and detect_acoustic(...) return AcousticResult with RT60, EDT, C50, C80, D50, per-band arrays, confidence, and is_blind. Both take sample_rate as a required argument. RIR means room impulse response. RT60 is the reverberation time — how long a tail takes to decay by 60 dB — while C50 and C80 are clarity ratios between early and late energy.

python
ir = sonare.analyze_impulse_response(ir_samples, sample_rate, n_octave_bands=6, min_decay_db=30.0)
print(ir.rt60, ir.edt, ir.c50, ir.c80, ir.confidence)

blind = sonare.detect_acoustic(
    room_recording,
    sample_rate,
    n_octave_bands=6,
    n_third_octave_subbands=24,
    min_decay_db=30.0,
    noise_floor_margin_db=10.0,
)
print(blind.is_blind, blind.rt60_bands)

estimate = sonare.estimate_room(room_recording, sample_rate, n_octave_bands=6)
print(estimate.volume, estimate.length_m, estimate.width_m, estimate.height_m)
print(estimate.drr_db, estimate.confidence, estimate.band_absorption)

rir = sonare.synthesize_rir(7.0, 5.0, 3.0, absorption=0.2, sample_rate=sample_rate)
print(rir.sample_rate, len(rir.rir), rir.diagnostics)  # warnings only

# Re-synthesize the estimated room: positions are the only thing to add.
geometry = sonare.room_geometry_from_estimate(estimate, source=(1, 1, 1.2), listener=(2, 1.5, 1.5))
rir = sonare.synthesize_rir(**geometry, sample_rate=sample_rate, material_preset="none")

morphed = sonare.room_morph(room_recording, sample_rate, 12.0, 9.0, 4.0, wet=0.6)
ROOM · IMPULSE RESPONSEIDLE
Impulse response — how a room decays

A room impulse response synthesized from shoebox dimensions, shown as its energy decay in dB. Enlarge the room or lower the absorption and the tail stretches — the RT60 (time to fall 60 dB) climbs with it. Press play to hear a clap in the room.

Room size
7 m
Absorption
0.16

Keep these cautions in mind:

  • estimate_room(...) returns an equivalent room, not guaranteed real geometry; inspect confidence.
  • synthesize_rir(...) raises SonareValueError for an unusable geometry, such as a source or listener outside the room; the message names the refused value and the range it must lie in (for a 7 m long room, source.x must be finite and in [0, 7]). A returned RirResult carries only warnings on diagnostics.
  • material_preset ("none" by default, or "concrete", "wood", "curtain", "carpet", "glass") and the estimate_room mode ("auto" by default, "blind", "impulseResponse") take names only: a number is a TypeError, an unknown name a SonareValueError.
  • room_geometry_from_estimate(estimate, *, source=None, listener=None) returns a RoomGeometry dict of synthesize_rir keyword arguments: length_m, width_m, height_m, source and listener (the default placement scaled into the estimated room, replaced by any source/listener you pass), plus absorption (mean of the finite bands) and band_absorption when the estimate converged on them. An estimate with unmeasured dimensions (None) raises SonareValueError.
  • room_morph(...) is a creative effect, not dereverberation.
  • room_morph_stereo(...) takes every room_morph keyword plus receiver_spacing_m in (0, 4] m (None: 0.5 m where the pair fits around the listener, otherwise the largest spacing that fits the room) and returns a RoomMorphStereoResult with left, right, sample_rate and diagnostics. An explicit spacing that puts a receiver outside the room, a spacing outside that range, or NaN raises SonareValueError.

See Room Acoustics for interpretation notes and when a blind estimate is appropriate.

Room acoustics functions ​

Signatures for the functions in the goal table above. Blind analysis returns None for unmeasured EDT and clarity.

python
# Analyze RT60, EDT, and clarity metrics from an impulse response.
def analyze_impulse_response(
    samples: Sequence[float] | list[float],
    sample_rate: int,
    n_octave_bands: int = 6,
    min_decay_db: float = 30.0,
) -> AcousticResult: ...

# Estimate blind RT60 from ordinary audio (EDT and clarity are None).
def detect_acoustic(
    samples: Sequence[float] | list[float],
    sample_rate: int,
    n_octave_bands: int = 6,
    n_third_octave_subbands: int = 24,
    min_decay_db: float = 30.0,
    noise_floor_margin_db: float = 10.0,
) -> AcousticResult: ...

# Estimate an equivalent room from a recording (or impulse response).
def estimate_room(
    samples: Sequence[float] | list[float],
    sample_rate: int,
    *,
    aspect_hint_lw: float = 1.0,
    aspect_hint_lh: float = 1.0,
    reference_absorption: float | None = None,
    prefer_eyring: bool = True,
    n_octave_bands: int | None = None,
    mode: AcousticModeName = 'auto',
    min_decay_db: float | None = None,
    noise_floor_margin_db: float | None = None,
) -> RoomEstimate: ...

# Synthesize a room impulse response from shoebox geometry.
def synthesize_rir(
    length_m: float = 7.0,
    width_m: float = 5.0,
    height_m: float = 3.0,
    *,
    source: tuple[float, float, float] | None = None,
    listener: tuple[float, float, float] | None = None,
    absorption: float = 0.2,
    band_absorption: Sequence[float] | None = None,
    band_scattering: Sequence[float] | None = None,
    material_preset: MaterialPresetName = 'none',
    sample_rate: int,
    ism_order: int = 3,
    prefer_eyring: bool = True,
    seed: int | None = None,
    max_sec: float | None = None,
    mixing_time_ms: float | None = None,
    crossfade_ms: float | None = None,
    air_absorption_enabled: bool = True,
    air_temperature_c: float | None = None,
    air_humidity_percent: float | None = None,
) -> RirResult: ...

# Morph a recording's reverberation toward a target room (creative FX).
def room_morph(
    samples: Sequence[float] | list[float],
    sample_rate: int,
    length_m: float,
    width_m: float,
    height_m: float,
    *,
    source: tuple[float, float, float] | None = None,
    listener: tuple[float, float, float] | None = None,
    absorption: float = 0.2,
    band_absorption: Sequence[float] | None = None,
    band_scattering: Sequence[float] | None = None,
    material_preset: MaterialPresetName = 'none',
    source_tail_suppression: float = 0.5,
    wet: float = 0.5,
    ism_order: int = 3,
    prefer_eyring: bool = True,
    seed: int | None = None,
    max_sec: float | None = None,
    mixing_time_ms: float | None = None,
    crossfade_ms: float | None = None,
    air_absorption_enabled: bool = True,
    air_temperature_c: float | None = None,
    air_humidity_percent: float | None = None,
) -> RoomMorphResult: ...
FunctionDescription
analyze_impulse_responseRoom acoustics from an impulse response (RT60/EDT/C50/C80); min_decay_db controls the decay-fit threshold
detect_acousticBlind room-acoustic estimation
estimate_roomEquivalent-room estimate with volume, dimensions, DRR, absorption bands, RT60 bands, and confidence
synthesize_rirMono room impulse response from shoebox geometry
room_morphOffline creative morph toward a target room; read morphed samples from .audio, with .sample_rate and .diagnostics alongside them