LCAV / pyroomacoustics

Pyroomacoustics is a package for audio signal processing for indoor applications. It was developed as a fast prototyping platform for beamforming algorithms in indoor scenarios.
https://pyroomacoustics.readthedocs.io
MIT License
1.42k stars 424 forks source link

Dimensionality Error with Room Simulation #104

Closed arilato closed 5 years ago

arilato commented 5 years ago

Following the example code for room simulation found on the docs [https://pyroomacoustics.readthedocs.io/en/pypi-release/pyroomacoustics.room.html], I am running into a syntax error.

My code block:

room = pra.ShoeBox([9, 7.5, 3.5], fs=fs, absorption=0.35, max_order=17)

my_source = pra.SoundSource([2.5, 3.73, 1.76], signal=signal, delay=1.3)

# place the source in the room
room.add_source([2.5, 3.73, 1.76], signal)

R = np.c_[
    [6.3, 4.87, 1.2],  # mic 1
    [6.3, 4.93, 1.2],  # mic 2
    ]

# the fs of the microphones is the same as the room
mic_array = pra.MicrophoneArray(R, room.fs)

# finally place the array in the room
room.add_microphone_array(mic_array)

room.compute_rir()

room.simulate()

Note that fs and signal was already loaded. I am getting an error with FFT:

ValueError                                Traceback (most recent call last)
<ipython-input-5-e77621760d1a> in <module>()
----> 1 room.simulate()

~/anaconda3/lib/python3.6/site-packages/pyroomacoustics/room.py in simulate(self, snr, reference_mic, callback_mix, callback_mix_kwargs, return_premix, recompute_rir)
   1078                 d = int(np.floor(self.sources[s].delay * self.fs))
   1079                 h = self.rir[m][s]
-> 1080                 premix_signals[s,m,d:d + len(sig) + len(h) - 1] += fftconvolve(h, sig)
   1081 
   1082         if callback_mix is not None:

~/anaconda3/lib/python3.6/site-packages/scipy/signal/signaltools.py in fftconvolve(in1, in2, mode, axes)
    372         return in1 * in2
    373     elif in1.ndim != in2.ndim:
--> 374         raise ValueError("in1 and in2 should have the same dimensionality")
    375     elif in1.size == 0 or in2.size == 0:  # empty arrays
    376         return array([])

ValueError: in1 and in2 should have the same dimensionality
fakufaku commented 5 years ago

It seems there's a problem with the dimensionality of signal. They should be 1D ndarrays. Have you checked this is the case ?

arilato commented 5 years ago

I see, I mistakenly assumed a single channel for the audio signal. After ensuring that, I no longer get this error. Resolved!

VijaykumarMangukiya commented 1 year ago

I am new here in python, have some basic level, I faced same problem in my experiment can you provide the solution with help of code. It seems veryhelpful for me to learn pyton and solved this kind of problem in future.