API
Stable vs Experimental
This API reference lists both stable and experimental modules.
Experimental APIs live under torchrir.experimental and may change without
notice. Prefer top-level torchrir and documented submodules for stable use.
Modules
torchrir
torchrir
TorchRIR public API.
__all__
module-attribute
__all__ = ['DynamicScene', 'Room', 'Source', 'MicrophoneArray', 'Scene', 'StaticScene', 'RIRResult', 'load', 'save']
DynamicScene
dataclass
Container for dynamic scene simulation inputs.
Examples:
scene = DynamicScene(room=room, sources=sources, mics=mics, src_traj=src_traj, mic_traj=mic_traj)
Source code in src/torchrir/models/scene.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
MicrophoneArray
dataclass
Microphone array container.
Examples:
mics = MicrophoneArray.from_positions([[2.0, 2.0, 1.5]])
Source code in src/torchrir/models/room.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
from_positions
classmethod
from_positions(positions, *, orientation=None, device=None, dtype=None)
Convert positions/orientation to tensors and build a MicrophoneArray.
Source code in src/torchrir/models/room.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
replace
replace(**kwargs)
Return a new MicrophoneArray with updated fields.
Source code in src/torchrir/models/room.py
154 155 156 | |
RIRResult
dataclass
Container for RIRs with metadata.
Examples:
from torchrir.sim import ISMSimulator
result = ISMSimulator(max_order=6, tmax=0.3).simulate(scene, config)
rirs = result.rirs
Source code in src/torchrir/models/results.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
Room
dataclass
Room geometry and acoustic parameters.
Examples:
room = Room.shoebox(size=[6.0, 4.0, 3.0], fs=16000, beta=[0.9] * 6)
Source code in src/torchrir/models/room.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
__post_init__
__post_init__()
Validate room size and reflection parameters.
Source code in src/torchrir/models/room.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
replace
replace(**kwargs)
Return a new Room with updated fields.
Source code in src/torchrir/models/room.py
59 60 61 | |
shoebox
staticmethod
shoebox(size, *, fs, c=343.0, beta=None, t60=None, device=None, dtype=None)
Create a rectangular (shoebox) room.
Examples:
room = Room.shoebox(size=[6.0, 4.0, 3.0], fs=16000, beta=[0.9] * 6)
Source code in src/torchrir/models/room.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
Scene
dataclass
Deprecated scene wrapper.
Scene is kept for backward compatibility. Prefer StaticScene and
DynamicScene to avoid ambiguous states.
Source code in src/torchrir/models/scene.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
Source
dataclass
Source container with positions and optional orientation.
Examples:
sources = Source.from_positions([[1.0, 2.0, 1.5]])
Source code in src/torchrir/models/room.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
from_positions
classmethod
from_positions(positions, *, orientation=None, device=None, dtype=None)
Convert positions/orientation to tensors and build a Source.
Source code in src/torchrir/models/room.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
replace
replace(**kwargs)
Return a new Source with updated fields.
Source code in src/torchrir/models/room.py
111 112 113 | |
StaticScene
dataclass
Container for static scene simulation inputs.
Examples:
scene = StaticScene(room=room, sources=sources, mics=mics)
Source code in src/torchrir/models/scene.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
load
load(path, *, backend=None, format=None)
Deprecated top-level loader. Use torchrir.io.load_wav/torchrir.io.load_audio.
Source code in src/torchrir/__init__.py
21 22 23 24 25 26 27 28 29 | |
save
save(path, audio, sample_rate, *, backend=None, format=None, normalize=True, peak=1.0, subtype=None)
Deprecated top-level saver. Use torchrir.io.save_wav/torchrir.io.save_audio.
Source code in src/torchrir/__init__.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
torchrir.sim
torchrir.sim
Simulation engines and configuration for RIR generation.
Includes the ISM implementation (in torchrir.sim.ism), directivity helpers,
and simulator interfaces for ISM plus placeholder ray-tracing/FDTD backends.
__all__
module-attribute
__all__ = ['ISMSimulator', 'RIRSimulator', 'directivity_gain', 'simulate_dynamic_rir', 'simulate_rir', 'split_directivity']
ISMSimulator
dataclass
ISM-based simulator using the current core implementation.
Examples:
result = ISMSimulator(max_order=6, tmax=0.3).simulate(scene, config)
Source code in src/torchrir/sim/simulators.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
RIRSimulator
Bases: Protocol
Strategy interface for RIR simulation backends.
Source code in src/torchrir/sim/simulators.py
16 17 18 19 20 21 22 | |
simulate
simulate(scene, config=None)
Run a simulation and return the result.
Source code in src/torchrir/sim/simulators.py
19 20 21 22 | |
directivity_gain
directivity_gain(pattern, cos_theta)
Compute directivity gain for a pattern given cos(theta).
Source code in src/torchrir/sim/directivity.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
simulate_dynamic_rir
simulate_dynamic_rir(*, room, src_traj, mic_traj, max_order, nb_img=None, nsample=None, tmax=None, directivity='omni', orientation=None, config=None, device=None, dtype=None)
Simulate time-varying RIRs for source/mic trajectories.
Source code in src/torchrir/sim/ism/api.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
simulate_rir
simulate_rir(*, room, sources, mics, max_order, nb_img=None, nsample=None, tmax=None, tdiff=None, directivity='omni', orientation=None, config=None, device=None, dtype=None)
Simulate a static RIR using the image source method.
Source code in src/torchrir/sim/ism/api.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
split_directivity
split_directivity(directivity)
Normalize directivity specification into (source, mic).
Source code in src/torchrir/sim/directivity.py
27 28 29 30 31 32 33 | |
torchrir.signal
torchrir.signal
Signal processing utilities for static and dynamic RIR convolution.
__all__
module-attribute
__all__ = ['DynamicConvolver', 'convolve_rir', 'fft_convolve']
DynamicConvolver
dataclass
Convolver for time-varying RIRs.
Examples:
convolver = DynamicConvolver(mode="trajectory")
y = convolver.convolve(signal, rirs)
Source code in src/torchrir/signal/dynamic.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
convolve
convolve(signal, rirs)
Convolve signals with time-varying RIRs.
Examples:
y = DynamicConvolver(mode="hop", hop=1024).convolve(signal, rirs)
Source code in src/torchrir/signal/dynamic.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
convolve_rir
convolve_rir(signal, rirs)
Convolve signals with static RIRs (supports multi-source/mic).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal
|
Tensor
|
(n_src, n_samples) or (n_samples,) tensor. |
required |
rirs
|
Tensor
|
(n_src, n_mic, rir_len) or compatible shape. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
(n_mic, n_samples + rir_len - 1) tensor or 1D for single mic. |
Examples:
y = convolve_rir(signal, rirs)
Source code in src/torchrir/signal/static.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
fft_convolve
fft_convolve(signal, rir)
Convolve a 1D signal with a 1D RIR using FFT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal
|
Tensor
|
1D signal tensor. |
required |
rir
|
Tensor
|
1D impulse response. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
1D tensor of length len(signal) + len(rir) - 1. |
Examples:
y = fft_convolve(signal, rir)
Source code in src/torchrir/signal/static.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
torchrir.geometry
torchrir.geometry
Geometry helpers for arrays, trajectories, and sampling.
Includes standard array layouts (linear, circular, polyhedron, binaural, Eigenmike) plus position sampling utilities.
__all__
module-attribute
__all__ = ['binaural_array', 'circular_array', 'clamp_positions', 'eigenmike_em32', 'eigenmike_em64', 'linear_array', 'linear_trajectory', 'polyhedron_array', 'sample_positions', 'sample_positions_min_distance']
binaural_array
binaural_array(center, *, offset=0.08, device=None, dtype=None)
Create a two-mic binaural layout around a center point.
Source code in src/torchrir/geometry/arrays.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
circular_array
circular_array(center, *, num, radius, plane='xy', normal=None, device=None, dtype=None)
Create an equally spaced circular microphone array.
Source code in src/torchrir/geometry/arrays.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
clamp_positions
clamp_positions(positions, room_size, margin=0.1)
Clamp positions to remain inside the room with a margin.
Source code in src/torchrir/geometry/sampling.py
89 90 91 92 93 94 95 | |
eigenmike_em32
eigenmike_em32(center, *, radius=0.042, azimuth_offset_deg=0.0, device=None, dtype=None)
Create the mh acoustics Eigenmike em32 geometry (3D only).
Source code in src/torchrir/geometry/arrays.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
eigenmike_em64
eigenmike_em64(center, *, radius=0.042, azimuth_offset_deg=0.0, device=None, dtype=None)
Create the mh acoustics Eigenmike em64 geometry (3D only).
Source code in src/torchrir/geometry/arrays.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
linear_array
linear_array(center, *, num, spacing, axis=0, direction=None, device=None, dtype=None)
Create an equally spaced linear microphone array.
Source code in src/torchrir/geometry/arrays.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
linear_trajectory
linear_trajectory(start, end, steps)
Create a linear trajectory between start and end.
Source code in src/torchrir/geometry/trajectories.py
9 10 11 12 13 14 | |
polyhedron_array
polyhedron_array(center, *, kind='tetrahedron', radius=0.1, device=None, dtype=None)
Create a regular polyhedron microphone array (3D only).
Source code in src/torchrir/geometry/arrays.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
sample_positions
sample_positions(*, num, room_size, rng, margin=0.5)
Sample random positions within a room with a safety margin.
Source code in src/torchrir/geometry/sampling.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
sample_positions_min_distance
sample_positions_min_distance(*, num, room_size, rng, center, min_distance, z_range=(1.5, 1.8), margin=0.5, max_attempts=1000)
Sample random positions with a minimum distance from a center point.
Source code in src/torchrir/geometry/sampling.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
torchrir.viz
torchrir.viz
Visualization helpers for scenes and trajectories.
Provides static/dynamic plotting plus GIF/MP4 animation utilities.
__all__
module-attribute
__all__ = ['animate_scene_gif', 'animate_scene_mp4', 'save_scene_gifs', 'save_scene_layout_images', 'save_scene_videos', 'save_scene_plots', 'plot_scene_dynamic', 'plot_scene_static', 'render_scene_plots']
animate_scene_gif
animate_scene_gif(*, out_path, room, sources, mics, src_traj=None, mic_traj=None, step=1, fps=None, signal_len=None, fs=None, duration_s=None, plot_2d=True, plot_3d=False, annotate_sources=True, annotation_lines=None)
Render a GIF showing source/mic trajectories.
Source code in src/torchrir/viz/animation.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
animate_scene_mp4
animate_scene_mp4(*, out_path, room, sources, mics, src_traj=None, mic_traj=None, step=1, fps=None, signal_len=None, fs=None, duration_s=None, plot_2d=True, plot_3d=False, annotate_sources=True, annotation_lines=None, mixture_path=None, mux_audio=True, audio_channels=(0, 1))
Render an MP4 showing source/mic trajectories.
When mux_audio is enabled and mixture_path is given, a stereo track
is added with ffmpeg using the requested channel indices.
The video canvas defaults to HD (1280x720).
Source code in src/torchrir/viz/animation.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
plot_scene_dynamic
plot_scene_dynamic(*, room, src_traj, mic_traj, step=1, src_pos=None, mic_pos=None, ax=None, title=None, show=False, annotate_sources=True, annotation_lines=None)
Plot source and mic trajectories within a room.
If trajectories are static, only positions are plotted.
Examples:
ax = plot_scene_dynamic(
room=[6.0, 4.0, 3.0],
src_traj=src_traj,
mic_traj=mic_traj,
)
Source code in src/torchrir/viz/scene.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
plot_scene_static
plot_scene_static(*, room, sources, mics, ax=None, title=None, show=False, annotate_sources=True, annotation_lines=None)
Plot a static room with source and mic positions.
Examples:
ax = plot_scene_static(
room=[6.0, 4.0, 3.0],
sources=[[1.0, 2.0, 1.5]],
mics=[[2.0, 2.0, 1.5]],
)
Source code in src/torchrir/viz/scene.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
render_scene_plots
render_scene_plots(*, out_dir, room, sources, mics, src_traj=None, mic_traj=None, prefix='scene', step=1, show=False, plot_2d=True, plot_3d=True, annotate_sources=True, annotation_lines=None)
Plot static and dynamic scenes and save images to disk.
Source code in src/torchrir/viz/io.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
save_scene_gifs
save_scene_gifs(*, out_dir, room, sources, mics, src_traj, mic_traj, prefix, signal_len, fs, gif_fps, logger, annotate_sources=True, annotation_lines=None)
Render trajectory GIFs.
Source code in src/torchrir/viz/io.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
save_scene_layout_images
save_scene_layout_images(*, out_dir, room, sources, mics, logger, src_traj=None, mic_traj=None, save_2d=True, save_3d=True, annotate_sources=True, annotation_lines=None, show=False)
Save static layout images with explicit 2D/3D filenames.
Source code in src/torchrir/viz/io.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
save_scene_plots
save_scene_plots(*, out_dir, room, sources, mics, src_traj=None, mic_traj=None, prefix, show, logger, plot_2d=True, plot_3d=True, annotate_sources=True, annotation_lines=None)
Plot and save scene images.
Source code in src/torchrir/viz/io.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
save_scene_videos
save_scene_videos(*, out_dir, room, sources, mics, src_traj, mic_traj, signal_len, fs, logger, mp4_fps=None, save_3d=True, mixture_path=None, mux_audio=True, annotate_sources=True, annotation_lines=None)
Render trajectory MP4 videos.
Output names follow oobss-compatible conventions:
- room_layout_2d.mp4
- room_layout_3d.mp4 (3D rooms when save_3d is enabled)
Source code in src/torchrir/viz/io.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
torchrir.models
torchrir.models
Core data models for rooms, sources, microphones, scenes, and results.
Examples:
from torchrir import DynamicScene, RIRResult
scene = DynamicScene(room=room, sources=sources, mics=mics, src_traj=src_traj, mic_traj=mic_traj)
result = RIRResult(rirs=rirs, scene=scene, config=config)
SceneLike
module-attribute
SceneLike = StaticScene | DynamicScene | Scene
__all__
module-attribute
__all__ = ['DynamicScene', 'MicrophoneArray', 'Room', 'RIRResult', 'Scene', 'SceneLike', 'StaticScene', 'Source']
DynamicScene
dataclass
Container for dynamic scene simulation inputs.
Examples:
scene = DynamicScene(room=room, sources=sources, mics=mics, src_traj=src_traj, mic_traj=mic_traj)
Source code in src/torchrir/models/scene.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
MicrophoneArray
dataclass
Microphone array container.
Examples:
mics = MicrophoneArray.from_positions([[2.0, 2.0, 1.5]])
Source code in src/torchrir/models/room.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
from_positions
classmethod
from_positions(positions, *, orientation=None, device=None, dtype=None)
Convert positions/orientation to tensors and build a MicrophoneArray.
Source code in src/torchrir/models/room.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
replace
replace(**kwargs)
Return a new MicrophoneArray with updated fields.
Source code in src/torchrir/models/room.py
154 155 156 | |
RIRResult
dataclass
Container for RIRs with metadata.
Examples:
from torchrir.sim import ISMSimulator
result = ISMSimulator(max_order=6, tmax=0.3).simulate(scene, config)
rirs = result.rirs
Source code in src/torchrir/models/results.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
Room
dataclass
Room geometry and acoustic parameters.
Examples:
room = Room.shoebox(size=[6.0, 4.0, 3.0], fs=16000, beta=[0.9] * 6)
Source code in src/torchrir/models/room.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
__post_init__
__post_init__()
Validate room size and reflection parameters.
Source code in src/torchrir/models/room.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
replace
replace(**kwargs)
Return a new Room with updated fields.
Source code in src/torchrir/models/room.py
59 60 61 | |
shoebox
staticmethod
shoebox(size, *, fs, c=343.0, beta=None, t60=None, device=None, dtype=None)
Create a rectangular (shoebox) room.
Examples:
room = Room.shoebox(size=[6.0, 4.0, 3.0], fs=16000, beta=[0.9] * 6)
Source code in src/torchrir/models/room.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
Scene
dataclass
Deprecated scene wrapper.
Scene is kept for backward compatibility. Prefer StaticScene and
DynamicScene to avoid ambiguous states.
Source code in src/torchrir/models/scene.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
Source
dataclass
Source container with positions and optional orientation.
Examples:
sources = Source.from_positions([[1.0, 2.0, 1.5]])
Source code in src/torchrir/models/room.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
from_positions
classmethod
from_positions(positions, *, orientation=None, device=None, dtype=None)
Convert positions/orientation to tensors and build a Source.
Source code in src/torchrir/models/room.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
replace
replace(**kwargs)
Return a new Source with updated fields.
Source code in src/torchrir/models/room.py
111 112 113 | |
StaticScene
dataclass
Container for static scene simulation inputs.
Examples:
scene = StaticScene(room=room, sources=sources, mics=mics)
Source code in src/torchrir/models/scene.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
torchrir.io
torchrir.io
I/O helpers for audio files and metadata serialization.
_AUDIO_BACKENDS
module-attribute
_AUDIO_BACKENDS = {'soundfile': AudioBackend(name='soundfile', load=_soundfile_load, save=_soundfile_save, info=info_audio)}
_DEFAULT_AUDIO_BACKEND
module-attribute
_DEFAULT_AUDIO_BACKEND = 'soundfile'
__all__
module-attribute
__all__ = ['AudioData', 'AudioBackend', 'build_metadata', 'get_audio_backend', 'info', 'info_audio', 'info_wav', 'list_audio_backends', 'load', 'load_audio', 'load_audio_data', 'load_wav', 'save_scene_audio', 'save_scene_metadata', 'save_audio', 'save_audio_data', 'save_metadata_json', 'save', 'save_wav', 'set_audio_backend']
AudioBackend
dataclass
Audio I/O backend definition.
Source code in src/torchrir/io/__init__.py
25 26 27 28 29 30 31 32 | |
AudioData
dataclass
Audio payload with metadata needed for explicit I/O round trips.
Source code in src/torchrir/io/audio.py
13 14 15 16 17 18 19 20 | |
AudioInfo
dataclass
Basic audio file metadata.
Source code in src/torchrir/io/audio.py
23 24 25 26 27 28 29 30 31 32 | |
_info_audio_file
_info_audio_file(path)
Return metadata for an audio file (wav/flac/other supported by soundfile).
Source code in src/torchrir/io/audio.py
206 207 208 209 210 211 212 213 214 215 216 217 218 | |
_load_audio
_load_audio(path, *, caller)
Load an audio file and return mono audio and sample rate.
Source code in src/torchrir/io/audio.py
58 59 60 61 | |
_normalize_format
_normalize_format(path, fmt)
Source code in src/torchrir/io/__init__.py
100 101 102 103 104 105 106 107 | |
_resolve_backend
_resolve_backend(name)
Source code in src/torchrir/io/__init__.py
91 92 93 94 95 96 97 | |
_save_audio
_save_audio(path, audio, sample_rate, *, normalize=True, peak=1.0, subtype=None)
Save a mono or multi-channel audio file to disk.
Source code in src/torchrir/io/audio.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
_soundfile_load
_soundfile_load(path, caller)
Source code in src/torchrir/io/__init__.py
35 36 | |
_soundfile_save
_soundfile_save(path, audio, sample_rate, normalize, peak, subtype)
Source code in src/torchrir/io/__init__.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
build_metadata
build_metadata(*, room, sources, mics, rirs, src_traj=None, mic_traj=None, timestamps=None, signal_len=None, source_info=None, extra=None)
Build JSON-serializable metadata for a simulation output.
Examples:
metadata = build_metadata(
room=room,
sources=sources,
mics=mics,
rirs=rirs,
src_traj=src_traj,
mic_traj=mic_traj,
signal_len=signal.shape[-1],
)
save_metadata_json(Path("outputs/scene_metadata.json"), metadata)
Source code in src/torchrir/io/metadata.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
get_audio_backend
get_audio_backend()
Return the current default audio backend.
Source code in src/torchrir/io/__init__.py
74 75 76 77 | |
info
info(path, *, backend=None, format=None)
Deprecated wav-only metadata lookup. Use info_wav or info_audio.
Source code in src/torchrir/io/__init__.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
info_audio
info_audio(path, *, backend=None)
Return metadata for an audio file in any backend-supported format.
Source code in src/torchrir/io/__init__.py
208 209 210 211 212 213 214 215 216 | |
info_wav
info_wav(path, *, backend=None, format=None)
Return metadata for a wav file.
This entry point is wav-only. For non-wav formats, use
torchrir.io.audio.info_audio.
Source code in src/torchrir/io/__init__.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
list_audio_backends
list_audio_backends()
Return the available audio backends.
Source code in src/torchrir/io/__init__.py
68 69 70 71 | |
load
load(path, *, backend=None, format=None)
Deprecated wav-only loader. Use load_wav or load_audio.
Source code in src/torchrir/io/__init__.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
load_audio
load_audio(path, *, backend=None)
Load an audio file in any format supported by the backend.
Source code in src/torchrir/io/__init__.py
181 182 183 184 185 186 187 188 189 | |
load_audio_data
load_audio_data(path)
Load an audio file and return audio + metadata in a stable container.
Source code in src/torchrir/io/audio.py
64 65 66 | |
load_wav
load_wav(path, *, backend=None, format=None)
Load a wav file and return mono audio and sample rate.
This entry point is wav-only. For non-wav formats, use
torchrir.io.audio.load_audio.
Source code in src/torchrir/io/__init__.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
save
save(path, audio, sample_rate, *, backend=None, format=None, normalize=True, peak=1.0, subtype=None)
Deprecated wav-only saver. Use save_wav or save_audio.
Source code in src/torchrir/io/__init__.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
save_attribution_file
save_attribution_file(*, out_dir, dataset_attribution, modifications, attribution_name='ATTRIBUTION.txt', logger=None)
Save dataset attribution and modification notes to a text file.
Source code in src/torchrir/io/outputs.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
save_audio
save_audio(path, audio, sample_rate, *, backend=None, normalize=True, peak=1.0, subtype=None)
Save an audio file in any format supported by the backend.
Source code in src/torchrir/io/__init__.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
save_audio_data
save_audio_data(path, data, *, normalize=True, peak=1.0, subtype=None)
Save audio from AudioData, optionally preserving its stored subtype.
Source code in src/torchrir/io/audio.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
save_metadata_json
save_metadata_json(path, metadata)
Save metadata as JSON to the given path.
Examples:
save_metadata_json(Path("outputs/scene_metadata.json"), metadata)
Source code in src/torchrir/io/metadata.py
138 139 140 141 142 143 144 145 146 147 148 | |
save_scene_audio
save_scene_audio(*, out_dir, audio, fs, audio_name, logger=None)
Save scene audio to the output directory.
Source code in src/torchrir/io/outputs.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
save_scene_metadata
save_scene_metadata(*, out_dir, metadata_name, room, sources, mics, rirs, src_traj=None, mic_traj=None, timestamps=None, signal_len=None, source_info=None, extra=None, logger=None)
Build and save scene metadata JSON to the output directory.
Source code in src/torchrir/io/outputs.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
save_wav
save_wav(path, audio, sample_rate, *, backend=None, format=None, normalize=True, peak=1.0, subtype=None)
Save a wav file to disk.
This entry point is wav-only. For non-wav formats, use
torchrir.io.audio.save_audio.
Source code in src/torchrir/io/__init__.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
set_audio_backend
set_audio_backend(name)
Set the default audio backend.
Source code in src/torchrir/io/__init__.py
80 81 82 83 84 85 86 87 88 | |
torchrir.logging
torchrir.logging
Logging helpers for torchrir.
__all__
module-attribute
__all__ = ['LoggingConfig', 'get_logger', 'setup_logging']
LoggingConfig
dataclass
Configuration for torchrir logging.
Examples:
config = LoggingConfig(level="INFO")
logger = setup_logging(config)
Source code in src/torchrir/logging.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
replace
replace(**kwargs)
Return a new config with updated fields.
Source code in src/torchrir/logging.py
37 38 39 | |
resolve_level
resolve_level()
Resolve level to a logging integer constant.
Source code in src/torchrir/logging.py
26 27 28 29 30 31 32 33 34 35 | |
get_logger
get_logger(name=None)
Return a torchrir logger, namespaced under the torchrir root.
Examples:
logger = get_logger("examples.static")
Source code in src/torchrir/logging.py
63 64 65 66 67 68 69 70 71 72 73 74 75 | |
setup_logging
setup_logging(config, *, name='torchrir')
Configure and return the base torchrir logger.
Examples:
logger = setup_logging(LoggingConfig(level="DEBUG"))
logger.info("ready")
Source code in src/torchrir/logging.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
torchrir.config
torchrir.config
Configuration objects for torchrir.
__all__
module-attribute
__all__ = ['SimulationConfig', 'default_config']
SimulationConfig
dataclass
Configuration values for RIR simulation and convolution.
Examples:
cfg = SimulationConfig(max_order=6, tmax=0.3, device="auto")
cfg.validate()
Source code in src/torchrir/config.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
replace
replace(**kwargs)
Return a new config with updated fields.
Source code in src/torchrir/config.py
64 65 66 67 68 | |
validate
validate()
Validate configuration values.
Source code in src/torchrir/config.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
default_config
default_config()
Return the default simulation configuration.
Examples:
cfg = default_config()
Source code in src/torchrir/config.py
71 72 73 74 75 76 77 78 79 80 81 | |
torchrir.util
torchrir.util
General-purpose math, device, and tensor utilities for torchrir.
__all__
module-attribute
__all__ = ['DeviceSpec', 'add_output_args', 'as_tensor', 'attenuation_db_to_time_sabine', 'ensure_dim', 'estimate_beta_from_t60', 'estimate_image_counts_from_tmax', 'estimate_t60_from_beta', 'extend_size', 'infer_device_dtype', 'normalize_orientation', 'orientation_to_unit', 'resolve_device']
DeviceSpec
dataclass
Resolve device + dtype defaults consistently.
Examples:
spec = DeviceSpec(device="auto", dtype=torch.float32)
device, dtype = spec.resolve(tensor)
Source code in src/torchrir/util/device.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
resolve
resolve(*values)
Resolve device/dtype from inputs with overrides.
Source code in src/torchrir/util/device.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
add_output_args
add_output_args(parser, *, out_dir_default, plot_default=False, include_plot=True, include_show=True, include_gif=False)
Add common output/plot/GIF arguments to a parser.
Source code in src/torchrir/util/cli.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
as_tensor
as_tensor(value, *, device=None, dtype=None)
Convert a value to a tensor while preserving device/dtype when possible.
Source code in src/torchrir/util/tensor.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
attenuation_db_to_time_sabine
attenuation_db_to_time_sabine(att_db, t60)
Convert attenuation (dB) to time based on T60.
Note
This function corresponds to gpuRIR's att2t_SabineEstimation. TorchRIR
uses snake_case naming for consistency.
Examples:
t = attenuation_db_to_time_sabine(att_db=60.0, t60=0.4)
Source code in src/torchrir/util/acoustics.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
ensure_dim
ensure_dim(size)
Validate room size dimensionality (2D or 3D).
Source code in src/torchrir/util/tensor.py
32 33 34 35 36 | |
estimate_beta_from_t60
estimate_beta_from_t60(size, t60, *, device=None, dtype=None)
Estimate reflection coefficients from T60 using Sabine's formula.
Note
This function corresponds to gpuRIR's beta_SabineEstimation. TorchRIR
uses snake_case naming for consistency.
Examples:
beta = estimate_beta_from_t60(torch.tensor([6.0, 4.0, 3.0]), t60=0.4)
Source code in src/torchrir/util/acoustics.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
estimate_image_counts_from_tmax
estimate_image_counts_from_tmax(tmax, room_size, c=_DEF_SPEED_OF_SOUND)
Estimate image counts per dimension needed to cover tmax.
Note
This function corresponds to gpuRIR's t2n helper, renamed for clarity.
Examples:
nb_img = estimate_image_counts_from_tmax(0.3, torch.tensor([6.0, 4.0, 3.0]))
Source code in src/torchrir/util/acoustics.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
estimate_t60_from_beta
estimate_t60_from_beta(size, beta, *, device=None, dtype=None)
Estimate T60 from reflection coefficients using Sabine's formula.
Examples:
t60 = estimate_t60_from_beta(torch.tensor([6.0, 4.0, 3.0]), beta=torch.full((6,), 0.9))
Source code in src/torchrir/util/acoustics.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
extend_size
extend_size(size, dim)
Extend 2D room size to 3D by adding a dummy z dimension.
Source code in src/torchrir/util/tensor.py
39 40 41 42 43 44 45 46 | |
infer_device_dtype
infer_device_dtype(*values, device=None, dtype=None)
Infer device/dtype from inputs with optional overrides.
Source code in src/torchrir/util/device.py
98 99 100 101 102 103 104 | |
normalize_orientation
normalize_orientation(orientation, *, eps=1e-08)
Normalize orientation vectors with numerical stability.
Source code in src/torchrir/util/orientation.py
9 10 11 12 13 | |
orientation_to_unit
orientation_to_unit(orientation, dim)
Convert orientation representation to unit vectors in 2D/3D.
Source code in src/torchrir/util/orientation.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
resolve_device
resolve_device(device, *, prefer=('cuda', 'mps', 'cpu'))
Resolve a device string (including 'auto') into a torch.device.
Falls back to CPU when the requested backend is unavailable.
Examples:
device = resolve_device("auto")
Source code in src/torchrir/util/device.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
torchrir.datasets
torchrir.datasets
Dataset helpers for torchrir.
Includes CMU ARCTIC and LibriSpeech dataset wrappers plus collate utilities for
DataLoader usage. Experimental dataset stubs live under
torchrir.experimental. Use load_dataset_sources to build fixed-length
source signals from random utterances. Dynamic CMU ARCTIC scene generation is
available via build_dynamic_cmu_arctic_dataset.
Examples:
from torch.utils.data import DataLoader
from torchrir.datasets import CmuArcticDataset, collate_dataset_items
dataset = CmuArcticDataset("datasets/cmu_arctic", speaker="bdl", download=True)
loader = DataLoader(dataset, batch_size=4, collate_fn=collate_dataset_items)
from pathlib import Path
from torchrir.datasets import LibriSpeechDataset
librispeech = LibriSpeechDataset(Path("datasets/librispeech"), subset="train-clean-100")
__all__
module-attribute
__all__ = ['BaseDataset', 'CmuArcticDataset', 'CmuArcticSentence', 'choose_speakers', 'DatasetItem', 'DatasetAttribution', 'CollateBatch', 'default_modification_notes', 'collate_dataset_items', 'cmu_arctic_speakers', 'build_dynamic_cmu_arctic_dataset', 'attribution_for', 'SentenceLike', 'load_dataset_sources', 'load', 'save', 'LibriSpeechDataset', 'LibriSpeechSentence']
BaseDataset
Bases: Dataset[DatasetItem]
Base dataset class compatible with torch.utils.data.Dataset.
Source code in src/torchrir/datasets/base.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
attribution_info
attribution_info()
Return attribution and license information for this dataset.
Source code in src/torchrir/datasets/base.py
49 50 51 | |
available_sentences
available_sentences()
Return sentence entries that have audio available.
Source code in src/torchrir/datasets/base.py
41 42 43 | |
list_speakers
list_speakers()
Return available speaker IDs.
Source code in src/torchrir/datasets/base.py
37 38 39 | |
load_audio
load_audio(utterance_id)
Load audio for an utterance and return (audio, sample_rate).
Source code in src/torchrir/datasets/base.py
45 46 47 | |
CmuArcticDataset
Bases: BaseDataset
CMU ARCTIC dataset loader.
Examples:
dataset = CmuArcticDataset(Path("datasets/cmu_arctic"), speaker="bdl", download=True)
audio, fs = dataset.load_audio("arctic_a0001")
Source code in src/torchrir/datasets/cmu_arctic.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
audio_dir
property
audio_dir
Return the directory containing audio files.
text_path
property
text_path
Return the path to txt.done.data.
__init__
__init__(root, speaker='bdl', download=False)
Initialize a CMU ARCTIC dataset handle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Path
|
Root directory where the dataset is stored. |
required |
speaker
|
str
|
Speaker ID (e.g., "bdl"). |
'bdl'
|
download
|
bool
|
Download and extract if missing. |
False
|
Source code in src/torchrir/datasets/cmu_arctic.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
attribution_info
attribution_info()
Return attribution and license information for CMU ARCTIC.
Source code in src/torchrir/datasets/cmu_arctic.py
156 157 158 | |
audio_path
audio_path(utterance_id)
Return the audio path for an utterance ID.
Source code in src/torchrir/datasets/cmu_arctic.py
147 148 149 | |
available_sentences
available_sentences()
Return sentences that have a corresponding wav file.
Source code in src/torchrir/datasets/cmu_arctic.py
138 139 140 141 | |
list_speakers
list_speakers()
Return available speaker IDs.
Source code in src/torchrir/datasets/cmu_arctic.py
143 144 145 | |
load_audio
load_audio(utterance_id)
Load mono audio for the given utterance ID.
Source code in src/torchrir/datasets/cmu_arctic.py
151 152 153 154 | |
sentences
sentences()
Parse all sentence metadata.
Source code in src/torchrir/datasets/cmu_arctic.py
126 127 128 129 130 131 132 133 134 135 136 | |
CmuArcticSentence
dataclass
Sentence metadata from CMU ARCTIC.
Source code in src/torchrir/datasets/cmu_arctic.py
49 50 51 52 53 54 | |
CollateBatch
dataclass
Collated batch of dataset items.
Fields
- audio: Padded audio tensor of shape (batch, max_len).
- lengths: Original lengths for each item.
- sample_rate: Sample rate shared across the batch.
- utterance_ids: Utterance IDs per item.
- texts: Optional text per item.
- speakers: Optional speaker IDs per item.
- metadata: Optional per-item metadata (pass-through).
Source code in src/torchrir/datasets/collate.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
DatasetAttribution
dataclass
Structured attribution info used for redistribution notices.
Source code in src/torchrir/datasets/attribution.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
to_dict
to_dict()
Return a JSON-serializable mapping.
Source code in src/torchrir/datasets/attribution.py
22 23 24 | |
DatasetItem
dataclass
Dataset item for DataLoader consumption.
Source code in src/torchrir/datasets/base.py
21 22 23 24 25 26 27 28 29 | |
LibriSpeechDataset
Bases: BaseDataset
LibriSpeech dataset loader.
Examples:
dataset = LibriSpeechDataset(Path("datasets/librispeech"), subset="train-clean-100", download=True)
audio, fs = dataset.load_audio("103-1240-0000")
Source code in src/torchrir/datasets/librispeech.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
__init__
__init__(root, subset='train-clean-100', speaker=None, download=False)
Initialize a LibriSpeech dataset handle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Path
|
Root directory where the dataset is stored. |
required |
subset
|
str
|
LibriSpeech subset name (e.g., "train-clean-100"). |
'train-clean-100'
|
speaker
|
str | None
|
Optional speaker ID directory name (e.g., "103"). If provided, restrict loading to that speaker. |
None
|
download
|
bool
|
Download and extract if missing. |
False
|
Source code in src/torchrir/datasets/librispeech.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
attribution_info
attribution_info()
Return attribution and license information for LibriSpeech.
Source code in src/torchrir/datasets/librispeech.py
154 155 156 | |
available_sentences
available_sentences()
Return sentences that have a corresponding audio file.
Source code in src/torchrir/datasets/librispeech.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
list_speakers
list_speakers()
Return available speaker IDs.
Source code in src/torchrir/datasets/librispeech.py
90 91 92 93 94 95 96 | |
load_audio
load_audio(utterance_id)
Load mono audio for the given utterance ID.
Source code in src/torchrir/datasets/librispeech.py
126 127 128 129 130 | |
LibriSpeechSentence
dataclass
Sentence metadata from LibriSpeech.
Source code in src/torchrir/datasets/librispeech.py
33 34 35 36 37 38 39 40 | |
SentenceLike
Bases: Protocol
Minimal sentence interface for dataset entries.
Source code in src/torchrir/datasets/base.py
14 15 16 17 18 | |
attribution_for
attribution_for(dataset, subset=None)
Return attribution info for a supported dataset key.
Source code in src/torchrir/datasets/attribution.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
build_dynamic_cmu_arctic_dataset
build_dynamic_cmu_arctic_dataset(*, cmu_root, dataset_root=Path('outputs/cmu_arctic_torchrir_dynamic_dataset'), speakers=DEFAULT_SPEAKERS, n_scenes=10, n_sources=3, n_moving_sources=1, duration_sec=20.0, room_size=(8.0, 6.0, 3.0), mic_center=(4.0, 3.0, 1.5), octa_edge_m=1.0, source_margin=(0.5, 0.5, 0.3), trajectory_steps=1024, rir_samples=4096, rt60=0.3, sound_speed=343.0, max_order=6, seed=42, download_cmu=False, overwrite=False, randomize_mic_center=True, move_start_ratio=0.35, move_end_ratio=0.65, moving_speed_min=0.3, moving_speed_max=0.8, save_layout_mp4=True, save_layout_mp4_3d=True, layout_video_fps=None, layout_video_mux_audio=True, save_layout_images=True, save_layout_images_3d=True, annotate_source_indices=True, logger=None)
Build a dynamic CMU ARCTIC dataset with oobss-compatible layout.
Source code in src/torchrir/datasets/dynamic_cmu_arctic.py
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 | |
choose_speakers
choose_speakers(dataset, num_sources, rng)
Select unique speakers for the requested number of sources.
Examples:
rng = random.Random(0)
speakers = choose_speakers(dataset, num_sources=2, rng=rng)
Source code in src/torchrir/datasets/utils.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
cmu_arctic_speakers
cmu_arctic_speakers()
Return supported CMU ARCTIC speaker IDs.
Source code in src/torchrir/datasets/cmu_arctic.py
44 45 46 | |
collate_dataset_items
collate_dataset_items(items, *, pad_value=0.0, keep_metadata=False)
Collate DatasetItem entries into a padded batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
Iterable[DatasetItem]
|
Iterable of DatasetItem. |
required |
pad_value
|
float
|
Value used for padding. |
0.0
|
keep_metadata
|
bool
|
Preserve item-level metadata field if present. |
False
|
Returns:
| Type | Description |
|---|---|
CollateBatch
|
CollateBatch with padded audio and metadata lists. |
Source code in src/torchrir/datasets/collate.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
default_modification_notes
default_modification_notes(*, dynamic)
Return concise modification notes for generated outputs.
Source code in src/torchrir/datasets/attribution.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
load
load(path)
Load a wav file and return mono audio and sample rate.
Notes
- Multichannel input uses channel 0 only (warns).
- For non-wav formats, use
torchrir.io.audio.load_audio.
Examples:
audio, fs = load(Path("datasets/cmu_arctic/.../arctic_a0001.wav"))
Source code in src/torchrir/io/audio.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
load_dataset_sources
load_dataset_sources(*, dataset_factory, num_sources, duration_s, rng)
Load and concatenate utterances for each speaker into fixed-length signals.
Examples:
from pathlib import Path
from torchrir.datasets import CmuArcticDataset
rng = random.Random(0)
root = Path("datasets/cmu_arctic")
signals, fs, info = load_dataset_sources(
dataset_factory=lambda spk: CmuArcticDataset(root, speaker=spk, download=True),
num_sources=2,
duration_s=10.0,
rng=rng,
)
Source code in src/torchrir/datasets/utils.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
save
save(path, audio, sample_rate, *, normalize=True, peak=1.0, subtype=None)
Save a mono or multi-channel wav to disk.
By default this normalizes to the specified peak.
Values outside [-1, 1] are preserved when normalization is disabled.
To preserve explicit file metadata, use load_audio_data /
save_audio_data or pass subtype directly.
For non-wav formats, use torchrir.io.audio.save_audio.
Examples:
save(Path("outputs/example.wav"), audio, sample_rate)
Source code in src/torchrir/io/audio.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
torchrir.experimental
torchrir.experimental
Experimental and work-in-progress APIs.
These APIs may change without notice. Prefer the stable interfaces in
torchrir and documented submodules where possible.
__all__
module-attribute
__all__ = ['FDTDSimulator', 'RayTracingSimulator', 'TemplateDataset', 'TemplateSentence']
FDTDSimulator
dataclass
Work in progress placeholder for FDTD simulation.
Goal
Provide a wave-based solver (finite-difference time-domain) with configurable grid resolution, boundary conditions, and stability constraints. The solver should target CPU/GPU execution and return RIRResult with the same metadata contract as ISM.
Source code in src/torchrir/experimental/simulators.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
RayTracingSimulator
dataclass
Work in progress placeholder for ray tracing simulation.
Goal
Provide a geometric acoustics backend that traces specular/diffuse reflection paths, supports frequency-dependent absorption/scattering, and returns a RIRResult compatible with the ISM path. The intent is to reuse Scene/SimulationConfig for inputs and keep output shape parity.
Source code in src/torchrir/experimental/simulators.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
TemplateDataset
Bases: BaseDataset
Template dataset stub for future integrations.
This class is a placeholder to document the expected dataset API surface. It will be replaced with concrete dataset loaders in future releases.
Source code in src/torchrir/experimental/datasets.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
attribution_info
attribution_info()
Return attribution and license information for this dataset.
Source code in src/torchrir/datasets/base.py
49 50 51 | |
available_sentences
available_sentences()
Return sentence entries that have audio available.
Source code in src/torchrir/datasets/base.py
41 42 43 | |
list_speakers
list_speakers()
Return available speaker IDs.
Source code in src/torchrir/datasets/base.py
37 38 39 | |
load_audio
load_audio(utterance_id)
Load audio for an utterance and return (audio, sample_rate).
Source code in src/torchrir/datasets/base.py
45 46 47 | |
TemplateSentence
dataclass
Template for dataset sentences (work in progress).
Source code in src/torchrir/experimental/datasets.py
12 13 14 15 16 17 18 19 | |