(1, n_samples) is not accepted as a mono waveform
See original GitHub issueDescription
Librosa typically operates on one-dimensional, one-channel signals whose shape is (n_samples,)
. In some cases, stereo signals are accepted in “time-major” format, e.g. of shape (2, n_samples)
. But the analogous single-channel signal, whose shape is (1, n_samples)
, is rejected – at least by numpy.resample()
To Reproduce
import librosa
import numpy as np
# Conventional mono
mono_signal = np.random.randn(1000)
resampled_mono = librosa.resample(mono_signal, 1000, 2000)
# Conventional stereo
stereo_signal = np.random.randn(2, 1000)
resampled_stereo = librosa.resample(stereo_signal, 1000, 2000)
# Stereo-like single channel
onechan_signal = np.random.randn(1, 1000)
resampled_onechan = librosa.resample(onechan_signal, 1000, 2000)
Expected behavior
resampled_mono == resampled_onechan[0]
Actual behavior
---------------------------------------------------------------------------
ParameterError Traceback (most recent call last)
<ipython-input-7-3776517cab8b> in <module>()
1 onechan_signal = np.random.randn(1, 1000)
----> 2 resampled_onechan = librosa.resample(onechan_signal, 1000, 2000)
3 print(resampled_onechan.shape)
1 frames
/usr/local/lib/python3.7/dist-packages/librosa/util/utils.py in valid_audio(y, mono)
304 elif y.ndim == 2 and y.shape[0] < 2:
305 raise ParameterError(
--> 306 "Mono data must have shape (samples,). " "Received shape={}".format(y.shape)
307 )
308
ParameterError: Mono data must have shape (samples,). Received shape=(1, 1000)
Software versions
Linux-5.4.104+-x86_64-with-Ubuntu-18.04-bionic
Python 3.7.10 (default, May 3 2021, 02:48:31)
[GCC 7.5.0]
NumPy 1.19.5
SciPy 1.4.1
librosa 0.8.1
INSTALLED VERSIONS
------------------
python: 3.7.10 (default, May 3 2021, 02:48:31)
[GCC 7.5.0]
librosa: 0.8.1
audioread: 2.1.9
numpy: 1.19.5
scipy: 1.4.1
sklearn: 0.22.2.post1
joblib: 1.0.1
decorator: 4.4.2
soundfile: 0.10.3
resampy: 0.2.2
numba: 0.51.2
numpydoc: None
sphinx: 1.8.5
sphinx_rtd_theme: None
sphinxcontrib.versioning: None
sphinx-gallery: None
pytest: 3.6.4
pytest-mpl: None
pytest-cov: None
matplotlib: 3.2.2
presets: None
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (13 by maintainers)
Top Results From Across the Web
Bpod Wiki - AudioPlayer - Google Sites
Note: Both speakers play mono waveforms. Bytes 3 - 6: The number of samples in the audio waveform expressed as a 32-bit integer...
Read more >Use Quick Sampler to edit and play single samples in Logic Pro
Load any audio file into Quick Sampler, or create samples by recording directly ... Click one of these options above the waveform display:....
Read more >Waveform User Guide 2021 - Tracktion
Chapter 1 - Introduction. Welcome to the Waveform User Guide. The goal of this guide is to help you learn Waveform. If.
Read more >sound: The Waveform Matrix of a Sample Object in sound: A Sound ...
Here, filenames are not accepted for codes. The matrix can have one (for mono samples) or two rows (for stereo samples), where in...
Read more >Using the WAVEFORMATEX Structure - Win32 apps
For PCM audio data on no more than two channels and with 8-bit or 16-bit samples, use the WAVEFORMATEX structure to specify the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So an empty dimension is okay as long as it’s not in the time position? I guess the shape check would then be
y.shape[-1] != 0
?Or, we could switch the default padding behavior to constant/zeros. It’s going into a major revision, after all. 😁
Yeah, I think I agree with that. The lingering question for me is whether there are legitimate use cases for a length-0 signal. I can’t think of one right now, but there might be some weird edge cases that pop up, eg, in the cqt module where it might be nice to have a graceful fallback when the signal is sliced too thin.
sounds good to me