How to use the pyroomacoustics.ShoeBox function in pyroomacoustics

To help you get started, we’ve selected a few pyroomacoustics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LCAV / pyroomacoustics / examples / doa_algorithms.py View on Github external
distance = 3.  # 3 meters

#######################
# algorithms parameters
SNR = 0.    # signal-to-noise ratio
c = 343.    # speed of sound
fs = 16000  # sampling frequency
nfft = 256  # FFT size
freq_bins = np.arange(5, 60)  # FFT bins to use for estimation

# compute the noise variance
sigma2 = 10**(-SNR / 10) / (4. * np.pi * distance)**2

# Create an anechoic room
room_dim = np.r_[10.,10.]
aroom = pra.ShoeBox(room_dim, fs=fs, max_order=0, sigma2_awgn=sigma2)

# add the source
source_location = room_dim / 2 + distance * np.r_[np.cos(azimuth), np.sin(azimuth)]
source_signal = np.random.randn((nfft // 2 + 1) * nfft)
aroom.add_source(source_location, signal=source_signal)

# We use a circular array with radius 15 cm # and 12 microphones
R = pra.circular_2D_array(room_dim / 2, 12, 0., 0.15)
aroom.add_microphone_array(pra.MicrophoneArray(R, fs=aroom.fs))

# run the simulation
aroom.simulate()

################################
# Compute the STFT frames needed
X = np.array([
github LCAV / pyroomacoustics / examples / room_shoebox_3d_rt.py View on Github external
# room dimension
room_dim = [7.5, 9.9, 3]

# Create the shoebox

materials = {
    'ceiling': pra.Material.from_db('hard_surface'),
    'floor': pra.Material.from_db('6mm_carpet'),
    'east': pra.Material.from_db('brickwork'),
    'west': pra.Material.from_db('brickwork'),
    'north': pra.Material.from_db('brickwork'),
    'south': pra.Material.from_db('brickwork'),
}

shoebox = pra.ShoeBox(
    room_dim,
    # materials=pra.Material.from_db('brickwork', 'rpg_skyline'),
    materials=materials,
    # materials=pra.Material.from_db('brickwork'),
    # materials=pra.Material.make_freq_flat(0.1, 0.2),
    # absorption=0.2,
    fs=16000,
    max_order=3,
    ray_tracing=True,
    air_absorption=True,
)

# source and mic locations
shoebox.add_source([2, 3.1, 2])
shoebox.add_microphone_array(
        pra.MicrophoneArray(np.array([[2, 1.5, 2]]).T, shoebox.fs)
github onolab-tmu / overiva / overiva_oneshot.py View on Github external
[3.0, 5.5, 1.5], n_sources - n_sources_target, offset=[6.5, 1.0, 0.5], seed=1
    )
    source_locs = np.concatenate((target_locs, interferer_locs), axis=1)

    # Prepare the signals
    wav_files = sampling(
        1,
        n_sources,
        f"{samples_dir}/metadata.json",
        gender_balanced=True,
        seed=3,
    )[0]
    signals = wav_read_center(wav_files, seed=123)

    # Create the room itself
    room = pra.ShoeBox(room_dim, fs=fs, absorption=absorption, max_order=max_order)

    # Place a source of white noise playing for 5 s
    for sig, loc in zip(signals, source_locs.T):
        room.add_source(loc, signal=sig)

    # Place the microphone array
    room.add_microphone_array(pra.MicrophoneArray(mic_locs, fs=room.fs))

    # compute RIRs
    room.compute_rir()

    # define a callback that will do the signal mix to
    # get a the correct SNR and SIR
    callback_mix_kwargs = {
        "snr": SNR,
        "sir": SIR,
github LCAV / pyroomacoustics / examples / room_shoebox_3d.py View on Github external
'''
A simple example of using pyroomacoustics to generate
room impulse responses of shoebox shaped rooms in 3d.
'''

from __future__ import print_function
import time
import numpy as np
import pyroomacoustics as pra
import matplotlib.pyplot as plt

# room dimension
room_dim = [5, 4, 6]

# Create the shoebox
shoebox = pra.ShoeBox(
    room_dim,
    absorption=0.2,
    fs=16000,
    max_order=15,
    )

# source and mic locations
shoebox.add_source([2, 3.1, 2])
shoebox.add_microphone_array(
        pra.MicrophoneArray(
            np.array([[2, 1.5, 2]]).T, 
            shoebox.fs)
        )

# run ism
shoebox.image_source_model()
github LCAV / pyroomacoustics / examples / room_rt60.py View on Github external
room_dim = args.dim
    rt60 = args.rt60

    if len(room_dim) not in [2,3]:
        raise ValueError('The room dimension must be a pair or triplet of numbers')

    mic_loc = 0.33 * np.array(room_dim)
    src_loc = 0.66 * np.array(room_dim)

    # we just do this to avoid some probability zero
    # placements with special artefacts
    mic_loc += 0.0005 * np.random.randn(len(room_dim))
    src_loc += 0.0005 * np.random.randn(len(room_dim))

    # Create the room and place equipment in it
    room = pra.ShoeBox(
            room_dim,
            fs=16000,
            rt60=rt60,
            )
    room.add_source(src_loc)
    room.add_microphone_array(
            pra.MicrophoneArray(
                np.c_[ mic_loc, ],
                room.fs,
                )
            )

    # Simulate and analyze
    room.compute_rir()
    rt60_analysis(room, 0, 0, rt60_tgt=rt60)
github pyannote / pyannote-audio / pyannote / audio / augmentation / reverb.py View on Github external
def __call__(self,
                 original: np.ndarray,
                 sample_rate: int) -> np.ndarray:

        original = normalize(original).squeeze()
        n_samples = len(original)

        # generate a room at random
        depth = self.random(*self.depth)
        width = self.random(*self.width)
        height = self.random(*self.height)
        absorption = self.random(*self.absorption)
        room = pra.ShoeBox([depth, width, height],
                           fs=sample_rate,
                           absorption=absorption,
                           max_order=self.max_order_)

        # play the original audio chunk at a random location within the room
        source = [self.random(0, depth),
                  self.random(0, width),
                  self.random(0, height)]
        room.add_source(source,
                        signal=original,
                        delay=0.)

        # generate noise with random SNR
        noise = self.noise_(n_samples, sample_rate)
        snr = self.random(*self.snr)
        alpha = np.exp(-np.log(10) * snr / 20)
github LCAV / pyroomacoustics / examples / room_simulation.py View on Github external
'''

from __future__ import print_function
import time
import numpy as np
import pyroomacoustics as pra
import matplotlib.pyplot as plt
from scipy.io import wavfile

fs, audio_anechoic = wavfile.read('examples/samples/guitar_16k.wav')

# room dimension
room_dim = [5, 4, 6]

# Create the shoebox
shoebox = pra.ShoeBox(
    room_dim,
    reflection=0.8,
    fs=fs,
    max_order=15,
    )

# source and mic locations
shoebox.add_source([2, 3.1, 2], signal=audio_anechoic)
shoebox.add_microphone_array(
        pra.MicrophoneArray(
            np.array([[2, 1.5, 2]]).T, 
            shoebox.fs)
        )

# run ism
shoebox.simulate()