save¶
- paddle.audio. save ( filepath, src, sample_rate, channels_first=True, encoding=None, bits_per_sample=16 ) [源代码] ¶
保存音频数据。
参数¶
filepath (str) - 保存音频路径。
src (Tensor) - 音频数据。
sample_rate (int) - 采样率。
channels_first (bool,可选) - 如果是 True,那么 src 的 Tensor 形状是[channel,time],如果是 False,则是[time,channel]。默认是 True。
encoding (str|None,可选) - 默认是 None,编码信息。
bits_per_sample (int|None,可选) - 默认是 16,编码位长。
返回¶
无
代码示例¶
>>> 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)