0

I am trying to load a .wav file in Python using librosa library. Let's assume my code is as simple as:

import librosa
import numpy as np

pcm_data, spl_rate = librosa.core.load(resource_file, sr=None)

In general it does work, however I am experiencing strange quantization problems when reading audio files with amplitude of less than 1e-5. I need some really low amplitude noise samples for my project (VERY little ambient noise, yet not complete silence).

For instance, when I generate white noise of amplitude 0.00001 in Audacity, its waveform is visible in Audacity preview when fully magnified. It is also visible after exporting the waveform as 32bit float and re-importing it to empty Audacity project. However, when I read that file using code presented above, np.max(np.abs(pcm_data)) is 0.0. Did I just reach limits of Python in this matter? How do I read my data (without pre-scaling and rescaling in runtime)?

LDTV
  • 41
  • 5
  • Are you sure the WAV file contains floating-point values, not integers? – mkrieger1 Aug 05 '19 at 21:32
  • 1
    https://librosa.github.io/librosa/generated/librosa.core.load.html says: "`audioread` may truncate the precision of the audio data to 16 bits." You should check the values you get, when you generate noise with amplitude `10` or something like that. – mkrieger1 Aug 05 '19 at 21:34
  • Bingo. I have to use pysoundfile explicitly, as it used to throw errors at some audacity formats. Librosa just falls back to audioread which is less precise. Thank you. – LDTV Aug 05 '19 at 23:18
  • Great that you found the problem. @mkrieger1 you might want to add your comment as answer – Jon Nordby Aug 14 '19 at 08:19

0 Answers0