paddleaudio.backends.soundfile_backend

paddleaudio.backends.soundfile_backend.depth_convert(y: numpy.ndarray, dtype: Union[type, str]) numpy.ndarray[source]

Convert audio array to target dtype safely. This function convert audio waveform to a target dtype, with addition steps of preventing overflow/underflow and preserving audio range.

Parameters
  • y (np.ndarray) -- Input waveform array in 1D or 2D.

  • dtype (Union[type, str]) -- Data type of waveform.

Returns

y after safe casting.

Return type

np.ndarray

paddleaudio.backends.soundfile_backend.load(file: os.PathLike, sr: Optional[int] = None, mono: bool = True, merge_type: str = 'average', normal: bool = True, norm_type: str = 'linear', norm_mul_factor: float = 1.0, offset: float = 0.0, duration: Optional[int] = None, dtype: str = 'float32', resample_mode: str = 'kaiser_fast') Tuple[numpy.ndarray, int][source]

Load audio file from disk. This function loads audio from disk using using audio beackend.

Parameters
  • file (os.PathLike) -- Path of auido file to load.

  • sr (Optional[int], optional) -- Sample rate of loaded waveform. Defaults to None.

  • mono (bool, optional) -- Return waveform with mono channel. Defaults to True.

  • merge_type (str, optional) -- Merge type of multi-channels waveform. Defaults to 'average'.

  • normal (bool, optional) -- Waveform normalization. Defaults to True.

  • norm_type (str, optional) -- Type of normalization. Defaults to 'linear'.

  • norm_mul_factor (float, optional) -- Scaling factor. Defaults to 1.0.

  • offset (float, optional) -- Offset to the start of waveform. Defaults to 0.0.

  • duration (Optional[int], optional) -- Duration of waveform to read. Defaults to None.

  • dtype (str, optional) -- Data type of waveform. Defaults to 'float32'.

  • resample_mode (str, optional) -- The resampling filter to use. Defaults to 'kaiser_fast'.

Returns

Waveform in ndarray and its samplerate.

Return type

Tuple[np.ndarray, int]

paddleaudio.backends.soundfile_backend.normalize(y: numpy.ndarray, norm_type: str = 'linear', mul_factor: float = 1.0) numpy.ndarray[source]

Normalize an input audio with additional multiplier.

Parameters
  • y (np.ndarray) -- Input waveform array in 1D or 2D.

  • norm_type (str, optional) -- Type of normalization. Defaults to 'linear'.

  • mul_factor (float, optional) -- Scaling factor. Defaults to 1.0.

Returns

y after normalization.

Return type

np.ndarray

paddleaudio.backends.soundfile_backend.resample(y: numpy.ndarray, src_sr: int, target_sr: int, mode: str = 'kaiser_fast') numpy.ndarray[source]

Audio resampling.

Parameters
  • y (np.ndarray) -- Input waveform array in 1D or 2D.

  • src_sr (int) -- Source sample rate.

  • target_sr (int) -- Target sample rate.

  • mode (str, optional) -- The resampling filter to use. Defaults to 'kaiser_fast'.

Returns

y resampled to target_sr

Return type

np.ndarray

paddleaudio.backends.soundfile_backend.save(y: numpy.ndarray, sr: int, file: os.PathLike) None[source]

Save audio file to disk. This function saves audio to disk using scipy.io.wavfile, with additional step to convert input waveform to int16.

Parameters
  • y (np.ndarray) -- Input waveform array in 1D or 2D.

  • sr (int) -- Sample rate.

  • file (os.PathLike) -- Path of auido file to save.

paddleaudio.backends.soundfile_backend.to_mono(y: numpy.ndarray, merge_type: str = 'average') numpy.ndarray[source]

Convert sterior audio to mono.

Parameters
  • y (np.ndarray) -- Input waveform array in 1D or 2D.

  • merge_type (str, optional) -- Merge type to generate mono waveform. Defaults to 'average'.

Returns

y with mono channel.

Return type

np.ndarray