0

I have an original file 0.flac which I just open with librosa and then save with SoundFile as 1.flac:

import soundfile as sf
import librosa

in_path = "0.flac"
out_path = "1.flac"

sampling_rate = 16000

wav, source_sampling_rate = librosa.load(in_path, sr=None)
assert(source_sampling_rate == sampling_rate)

# 16bit -> PCM_16
sf.write(out_path, wav, sampling_rate, format='flac', subtype='PCM_16')

However the file size and file itself seems to be changed:

User@User-MacBook-Pro:~/check_librosa$ metaflac --list 0.flac 
METADATA block #0
  type: 0 (STREAMINFO)
  is last: false
  length: 34
  minimum blocksize: 4096 samples
  maximum blocksize: 4096 samples
  minimum framesize: 107 bytes
  maximum framesize: 5961 bytes
  sample_rate: 16000 Hz
  channels: 1
  bits-per-sample: 16
  total samples: 225360
  MD5 signature: 41222a894966327db4f89afa74e5e1a1
METADATA block #1
  type: 3 (SEEKTABLE)
  is last: false
  length: 36
  seek points: 2
    point 0: sample_number=0, stream_offset=0, frame_samples=4096
    point 1: sample_number=159744, stream_offset=170830, frame_samples=4096
METADATA block #2
  type: 4 (VORBIS_COMMENT)
  is last: false
  length: 40
  vendor string: reference libFLAC 1.2.1 20070917
  comments: 0
METADATA block #3
  type: 1 (PADDING)
  is last: true
  length: 8192

User@User-MacBook-Pro:~/check_librosa$ metaflac --list 1.flac 
METADATA block #0
  type: 0 (STREAMINFO)
  is last: false
  length: 34
  minimum blocksize: 4096 samples
  maximum blocksize: 4096 samples
  minimum framesize: 107 bytes
  maximum framesize: 6040 bytes
  sample_rate: 16000 Hz
  channels: 1
  bits-per-sample: 16
  total samples: 225360
  MD5 signature: 41222a894966327db4f89afa74e5e1a1
METADATA block #1
  type: 4 (VORBIS_COMMENT)
  is last: true
  length: 40
  vendor string: reference libFLAC 1.3.3 20190804
  comments: 0

There are less metadata blocks and the maximum framesize is different. What could be the reason for this? Is loading the file via librosa lossy?

Andy
  • 1,072
  • 2
  • 19
  • 33
  • 1
    For the metadata it has just dropped a padding block and the seek table neither of which are necessary. Not sure about the frame size, it may have redone the compression using different parameters (but still lossless) – greg-449 Mar 19 '21 at 17:41
  • @greg-449 Thank you for your answer! Is there a way to check/prove that it is lossless? – Andy Mar 20 '21 at 16:39
  • I don't know anything about this specific library but FLAC compression is always lossless – greg-449 Mar 20 '21 at 16:58
  • 1
    To check that the transformation is lossless, load up the saved data again, and compare the saved audio to the original audio. – Jon Nordby Mar 24 '21 at 17:25

0 Answers0