load

paddle.audio. load ( filepath: Union[str, pathlib.Path], frame_offset: int = 0, num_frames: int = - 1, normalize: bool = True, channels_first: bool = True ) Tuple[paddle.Tensor, int] [source]

Load audio data from file. load the audio content start form frame_offset, and get num_frames.

Parameters
  • frame_offset – from 0 to total frames,

  • num_frames – from -1 (means total frames) or number frames which want to read,

  • normalize – if True: return audio which norm to (-1, 1), dtype=float32 if False: return audio with raw data, dtype=int16

  • channels_first – if True: return audio with shape (channels, time)

Returns

(audio_content, sample rate)

Return type

Tuple[paddle.Tensor, int]

Examples

import os
import paddle

sample_rate = 16000
wav_duration = 0.5
num_channels = 1
num_frames = sample_rate * wav_duration
wav_data = paddle.linspace(-1.0, 1.0, num_frames) * 0.1
waveform = wav_data.tile([num_channels, 1])
base_dir = os.getcwd()
filepath = os.path.join(base_dir, "test.wav")

paddle.audio.save(filepath, waveform, sample_rate)
wav_data_read, sr = paddle.audio.load(filepath)