mindspore.dataset.audio.Vol
- class mindspore.dataset.audio.Vol(gain, gain_type=GainType.AMPLITUDE)[source]
Adjust volume of waveform.
- Parameters
gain (float) – Gain at the boost (or attenuation). If gain_type is
GainType.AMPLITUDE
, it is a non negative amplitude ratio. If gain_type isGainType.POWER
, it is a power (voltage squared). If gain_type isGainType.DB
, it is in decibels.gain_type (GainType, optional) – Type of gain, can be
GainType.AMPLITUDE
,GainType.POWER
orGainType.DB
. Default:GainType.AMPLITUDE
.
- Raises
TypeError – If gain is not of type float.
TypeError – If gain_type is not of type
mindspore.dataset.audio.GainType
.ValueError – If gain is a negative number when gain_type is
GainType.AMPLITUDE
.ValueError – If gain is not a positive number when gain_type is
GainType.POWER
.RuntimeError – If input tensor is not in shape of <…, time>.
- Supported Platforms:
CPU
Examples
>>> import numpy as np >>> import mindspore.dataset as ds >>> import mindspore.dataset.audio as audio >>> >>> # Use the transform in dataset pipeline mode >>> waveform = np.random.random([5, 30]) # 5 sample >>> numpy_slices_dataset = ds.NumpySlicesDataset(data=waveform, column_names=["audio"]) >>> transforms = [audio.Vol(gain=10, gain_type=audio.GainType.DB)] >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms, input_columns=["audio"]) >>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True): ... print(item["audio"].shape, item["audio"].dtype) ... break (30,) float64 >>> >>> # Use the transform in eager mode >>> waveform = np.random.random([30]) # 1 sample >>> output = audio.Vol(gain=10, gain_type=audio.GainType.DB)(waveform) >>> print(output.shape, output.dtype) (30,) float64
- Tutorial Examples: