save

paddle.audio. save ( filepath: str, src: paddle.Tensor, sample_rate: int, channels_first: bool = True, encoding: Optional[str] = None, bits_per_sample: Optional[int] = 16 ) [source]

Save audio tensor to file.

Parameters
  • filepath – saved path

  • src – the audio tensor

  • sample_rate – the number of samples of audio per second.

  • channels_first – src channel information if True, means input tensor is (channels, time) if False, means input tensor is (time, channels)

  • encoding – audio encoding format, wave_backend only support PCM16 now.

  • bits_per_sample – bits per sample, wave_backend only support 16 bits now.

Returns

None

Examples

>>> 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])
>>> filepath = "./test.wav"

>>> paddle.audio.save(filepath, waveform, sample_rate)