save¶
- paddle.audio. save ( filepath: str, src: Tensor, sample_rate: int, channels_first: bool = True, encoding: str | None = None, bits_per_sample: int | None = 16 ) None [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, int(num_frames)) * 0.1 >>> waveform = wav_data.tile([num_channels, 1]) >>> filepath = "./test.wav" >>> paddle.audio.save(filepath, waveform, sample_rate)