torchaudio load for PCM file - EfficientConformer

Viewed 21

I'm struggling with parsing audio length in PCM file.

EfficientConformer use LibriSpeechDataset and the audio file format is flac, but in my case i'm using pcm files. EfficientConformer extracts audio length by torchaudio like this

audio_length = torchaudio.load(DATASET_PATH)[0].size(1)

But for my case, it doesn't work for PCM files, so I tried in different way.

What i did

get signal first by below code

signal = np.memmap(audio_path, dtype='h', mode='r').astype('float32')

if sum(abs(signal)) <= 80:
    raise ValueError('[WARN] Silence file in {0}'.format(audio_path))

return signal / 32767  # normalize audio

and then get waveform

waveform = Tensor(signal).unsqueeze(0).t()

and then finally get size in dim(1)

audio_length = waveform.size(1)

but it keep print 1 in terminal

This is my PCM dataset infos

  • No header pcm files
  • Sampling Fequency : 16000Hz
  • Mono Channel

How to get audio length in pcm files?

0 Answers
Related