question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

An error occurred, when librosa.resample() with the return value of the sf.read().

See original GitHub issue

Description

An error occurred, when resamping with the return value of the sf.read() function. what’s different, between librosa.load() and sf.read(). how can i get it work, when read RAW file.

Steps/Code to Reproduce

I have two sound documents with similar parameters,Need to re-sampling. One is in wav format and the other is in pure raw format.

The raw format cannot be loaded using librosa.load(). Then changed to soundfile.read () read, but when call librosa.resample(), got an error.

I have attached the relevant attachments and documentation. Please help with the science… I check the pcm file ,it can be replayed in AdobeAudition. code

Here are the relevant documents. HaveException.zip

Content

import librosa                     #librosa                0.6.3
import librosa.display
import matplotlib.pyplot as plt    #matplotlib             3.1.0
import numpy as np                 #numpy                  1.16.2
import soundfile as sf             #PySoundFile            0.9.0.post1

showPictures=True

sourceFileName ="chineseRecord2Stereo.wav"
destFileName="16bitMono16K.wav"
DATA, SR = librosa.load(sourceFileName,sr=48000,mono=False,dtype=np.float32)
# work fine.

sourceFileName = 'Call_streamout.pcm.0.AudioALSAStreamOut.pid400.tid8131_48K2Stero32PCM.pcm'
destFileName="16bitMono16K.wav"
DATA,SR = sf.read(sourceFileName, channels=2, samplerate=48000,dtype=np.float32,
                               subtype='PCM_32',format="RAW",endian='LITTLE')
# work failed

DATA_16k = librosa.resample(DATA,SR,16000)
DATA_16k_mono=librosa.to_mono(DATA_16k)
sf.write(destFileName, DATA_16k_mono, 16000, subtype='PCM_16')

Expected Results

No Error

Actual Results

Error ValueError: Input signal length=2 is too small to resample from 48000->16000

Versions

import platform; print(platform.platform()) Windows-10-10.0.18362-SP0 import sys; print(“Python”, sys.version) Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] import numpy; print(“NumPy”, numpy.version) NumPy 1.16.2 import scipy; print(“SciPy”, scipy.version) SciPy 1.3.0 import librosa; print(“librosa”, librosa.version) librosa 0.6.3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
lostanlencommented, Nov 7, 2020

Hello @Vladislav2018, from your screenshots it sounds like your array is a 409600x1 matrix and needs to be raveled into a vector https://numpy.org/doc/stable/reference/generated/numpy.ravel.html

0reactions
bmcfeecommented, Dec 8, 2021

If i want to rewrite the audio ndarry into .wav file. Should i need to transpose the result of resample() function?

Yes probably. Consult the soundfile documentation to see what exactly it expects.

Read more comments on GitHub >

github_iconTop Results From Across the Web

librosa.load — librosa 0.10.0.dev0 documentation
Load an audio file as a floating point time series. Audio will be automatically resampled to the given rate (default sr=22050 ). To...
Read more >
librosa.resample — librosa 0.10.0.dev0 documentation
By default, this uses a high-quality method (soxr_hq) for band-limited sinc interpolation. The alternate res_type values listed below offer different trade-offs ...
Read more >
Source code for librosa.core.audio
Audio will be automatically resampled to the given rate (default ``sr=22050``). ... Audio will be streamed in its native sample rate, so no...
Read more >
Source code for librosa.core.audio
This function does not return audio buffers directly. It returns a generator, which you can iterate over to produce blocks of audio. A...
Read more >
Source code for librosa.core.audio
import pathlib import warnings import soundfile as sf import audioread import ... signal to mono offset : float start reading after this time...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found