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.
| Goal | Use |
|---|---|
| Measure a clean impulse response | analyze_impulse_response(...) |
| Estimate room decay from ordinary audio | detect_acoustic(...) |
| Fit a practical room model from audio | estimate_room(...) |
| Create a mono room impulse response from dimensions | synthesize_rir(...) |
| Add a target-room character as an effect | room_morph(...) |
| Add the same character to a stereo recording, heard at two spaced receivers | room_morph_stereo(...) |
# 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.
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)Keep these cautions in mind:
estimate_room(...)returns an equivalent room, not guaranteed real geometry; inspectconfidence.synthesize_rir(...)raisesSonareValueErrorfor 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 returnedRirResultcarries only warnings ondiagnostics.material_preset("none"by default, or"concrete","wood","curtain","carpet","glass") and theestimate_roommode("auto"by default,"blind","impulseResponse") take names only: a number is aTypeError, an unknown name aSonareValueError.room_geometry_from_estimate(estimate, *, source=None, listener=None)returns aRoomGeometrydict ofsynthesize_rirkeyword arguments:length_m,width_m,height_m,sourceandlistener(the default placement scaled into the estimated room, replaced by anysource/listeneryou pass), plusabsorption(mean of the finite bands) andband_absorptionwhen the estimate converged on them. An estimate with unmeasured dimensions (None) raisesSonareValueError.room_morph(...)is a creative effect, not dereverberation.room_morph_stereo(...)takes everyroom_morphkeyword plusreceiver_spacing_min (0, 4] m (None: 0.5 m where the pair fits around the listener, otherwise the largest spacing that fits the room) and returns aRoomMorphStereoResultwithleft,right,sample_rateanddiagnostics. An explicit spacing that puts a receiver outside the room, a spacing outside that range, or NaN raisesSonareValueError.
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.
# 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: ...| Function | Description |
|---|---|
analyze_impulse_response | Room acoustics from an impulse response (RT60/EDT/C50/C80); min_decay_db controls the decay-fit threshold |
detect_acoustic | Blind room-acoustic estimation |
estimate_room | Equivalent-room estimate with volume, dimensions, DRR, absorption bands, RT60 bands, and confidence |
synthesize_rir | Mono room impulse response from shoebox geometry |
room_morph | Offline creative morph toward a target room; read morphed samples from .audio, with .sample_rate and .diagnostics alongside them |