set_backend

paddle.audio.backends. set_backend ( backend_name: str ) [源代码]

设置处理语音 I/O 的后端。

参数

  • backend_name (str) - 语音 I/O 后端名称,现支持 'wave_backend' ,如果安装了 paddleaudio >=1.0.2,则也支持 'soundfile'

返回

代码示例

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

>>> current_backend = paddle.audio.backends.get_current_backend()
>>> print(current_backend)
wave_backend

>>> backends = paddle.audio.backends.list_available_backends()
>>> # default backends is ['wave_backend']
>>> # backends is ['wave_backend', 'soundfile'], if have installed paddleaudio >= 1.0.2

>>> if 'soundfile' in backends:
...     paddle.audio.backends.set_backend('soundfile')
...
>>> paddle.audio.save(wav_path, waveform, sample_rate)