注意
点击此处下载完整示例代码
AudioEffector 用法¶
作者:Moto Hira
警告
从 2.8 版本开始,我们正在重构 TorchAudio,以使其进入维护阶段。因此:
本教程中描述的 API 在 2.8 版本中已被弃用,并将在 2.9 版本中移除。
PyTorch 用于音频和视频的解码和编码功能正在被整合到 TorchCodec 中。
请参阅 https://github.com/pytorch/audio/issues/3902 获取更多信息。
本教程展示了如何使用 torchaudio.io.AudioEffector
对波形张量应用各种效果和编解码器。
注意
本教程需要 FFmpeg 库。详情请参阅 FFmpeg 依赖项。
概述¶
AudioEffector
结合了 StreamWriter
和 StreamReader
提供的内存中编码、解码和过滤功能。
下图说明了整个过程。

import torch
import torchaudio
print(torch.__version__)
print(torchaudio.__version__)
2.8.0+cu126
2.8.0
from torchaudio.io import AudioEffector, CodecConfig
import matplotlib.pyplot as plt
from IPython.display import Audio
/pytorch/audio/examples/tutorials/effector_tutorial.py:59: UserWarning: torio.utils.ffmpeg_utils.get_versions has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
for k, v in torchaudio.utils.ffmpeg_utils.get_versions().items():
libavcodec (60, 3, 100)
libavdevice (60, 1, 100)
libavfilter (9, 3, 100)
libavformat (60, 3, 100)
libavutil (58, 2, 100)
用法¶
要使用 AudioEffector
,请使用 effect
和 format
实例化它,然后将波形传递给 apply()
或 stream()
方法。
effector = AudioEffector(effect=..., format=...,)
# Apply at once
applied = effector.apply(waveform, sample_rate)
apply
方法一次性对整个波形应用效果和编解码器。因此,如果输入波形很长,并且内存消耗是一个问题,可以使用 stream
方法逐块处理。
# Apply chunk by chunk
for applied_chunk = effector.stream(waveform, sample_rate):
...
示例¶
/pytorch/audio/examples/tutorials/effector_tutorial.py:94: UserWarning: torchaudio.utils.download.download_asset has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
src = torchaudio.utils.download_asset("tutorial-assets/Lab41-SRI-VOiCES-src-sp0307-ch127535-sg0042.wav")
/pytorch/audio/src/torchaudio/_backend/utils.py:213: UserWarning: In 2.9, this function's implementation will be changed to use torchaudio.load_with_torchcodec` under the hood. Some parameters like ``normalize``, ``format``, ``buffer_size``, and ``backend`` will be ignored. We recommend that you port your code to rely directly on TorchCodec's decoder instead: https://docs.pytorch.ac.cn/torchcodec/stable/generated/torchcodec.decoders.AudioDecoder.html#torchcodec.decoders.AudioDecoder.
warnings.warn(
/pytorch/audio/src/torchaudio/_backend/ffmpeg.py:88: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
s = torchaudio.io.StreamReader(src, format, None, buffer_size)
画廊¶
def show(effect, *, stereo=False):
wf = torch.cat([waveform] * 2, dim=1) if stereo else waveform
figsize = (6.4, 2.1 if stereo else 1.2)
effector = AudioEffector(effect=effect, pad_end=False)
result = effector.apply(wf, int(sr))
num_channels = result.size(1)
f, ax = plt.subplots(num_channels, 1, squeeze=False, figsize=figsize, sharex=True)
for i in range(num_channels):
ax[i][0].specgram(result[:, i], Fs=sr)
f.set_tight_layout(True)
return Audio(result.numpy().T, rate=sr)
原始¶
show(effect=None)

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
效果¶
节奏¶
https://ffmpeg.net.cn/ffmpeg-filters.html#atempo
show("atempo=0.7")

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
show("atempo=1.8")

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
高通¶
https://ffmpeg.net.cn/ffmpeg-filters.html#highpass
show("highpass=frequency=1500")

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
低通¶
https://ffmpeg.net.cn/ffmpeg-filters.html#lowpass
show("lowpass=frequency=1000")

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
全通¶
https://ffmpeg.net.cn/ffmpeg-filters.html#allpass
show("allpass")

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
带通¶
https://ffmpeg.net.cn/ffmpeg-filters.html#bandpass
show("bandpass=frequency=3000")

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
带阻¶
https://ffmpeg.net.cn/ffmpeg-filters.html#bandreject
show("bandreject=frequency=3000")

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
回声¶
https://ffmpeg.net.cn/ffmpeg-filters.html#aecho
show("aecho=in_gain=0.8:out_gain=0.88:delays=6:decays=0.4")

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
show("aecho=in_gain=0.8:out_gain=0.88:delays=60:decays=0.4")

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
show("aecho=in_gain=0.8:out_gain=0.9:delays=1000:decays=0.3")

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
合唱¶
https://ffmpeg.net.cn/ffmpeg-filters.html#chorus
show("chorus=0.5:0.9:50|60|40:0.4|0.32|0.3:0.25|0.4|0.3:2|2.3|1.3")

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
fft 滤波器¶
https://ffmpeg.net.cn/ffmpeg-filters.html#afftfilt
# fmt: off
show(
"afftfilt="
"real='re * (1-clip(b * (b/nb), 0, 1))':"
"imag='im * (1-clip(b * (b/nb), 0, 1))'"
)

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
show(
"afftfilt="
"real='hypot(re,im) * sin(0)':"
"imag='hypot(re,im) * cos(0)':"
"win_size=512:"
"overlap=0.75"
)

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
show(
"afftfilt="
"real='hypot(re,im) * cos(2 * 3.14 * (random(0) * 2-1))':"
"imag='hypot(re,im) * sin(2 * 3.14 * (random(1) * 2-1))':"
"win_size=128:"
"overlap=0.8"
)
# fmt: on

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
颤音¶
https://ffmpeg.net.cn/ffmpeg-filters.html#vibrato
show("vibrato=f=10:d=0.8")

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
/pytorch/audio/ci_env/lib/python3.10/site-packages/IPython/lib/display.py:188: RuntimeWarning: invalid value encountered in cast
return scaled.astype("<h").tobytes(), nchan
震音¶
https://ffmpeg.net.cn/ffmpeg-filters.html#tremolo
show("tremolo=f=8:d=0.8")

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
晶化器¶
https://ffmpeg.net.cn/ffmpeg-filters.html#crystalizer
show("crystalizer")

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
镶边¶
https://ffmpeg.net.cn/ffmpeg-filters.html#flanger
show("flanger")

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
移相器¶
https://ffmpeg.net.cn/ffmpeg-filters.html#aphaser
show("aphaser")

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
脉冲器¶
https://ffmpeg.net.cn/ffmpeg-filters.html#apulsator
show("apulsator", stereo=True)

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
哈斯¶
https://ffmpeg.net.cn/ffmpeg-filters.html#haas
show("haas")

/pytorch/audio/examples/tutorials/effector_tutorial.py:108: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(effect=effect, pad_end=False)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
编解码器¶
def show_multi(configs):
results = []
for config in configs:
effector = AudioEffector(**config)
results.append(effector.apply(waveform, int(sr)))
num_configs = len(configs)
figsize = (6.4, 0.3 + num_configs * 0.9)
f, axes = plt.subplots(num_configs, 1, figsize=figsize, sharex=True)
for result, ax in zip(results, axes):
ax.specgram(result[:, 0], Fs=sr)
f.set_tight_layout(True)
return [Audio(r.numpy().T, rate=sr) for r in results]
ogg¶
results = show_multi(
[
{"format": "ogg"},
{"format": "ogg", "encoder": "vorbis"},
{"format": "ogg", "encoder": "opus"},
]
)

/pytorch/audio/examples/tutorials/effector_tutorial.py:278: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(**config)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
ogg - 默认编码器 (flac)¶
results[0]
ogg - vorbis¶
results[1]
ogg - opus¶
results[2]
mp3¶
https://trac.ffmpeg.org/wiki/Encode/MP3
results = show_multi(
[
{"format": "mp3"},
{"format": "mp3", "codec_config": CodecConfig(compression_level=1)},
{"format": "mp3", "codec_config": CodecConfig(compression_level=9)},
{"format": "mp3", "codec_config": CodecConfig(bit_rate=192_000)},
{"format": "mp3", "codec_config": CodecConfig(bit_rate=8_000)},
{"format": "mp3", "codec_config": CodecConfig(qscale=9)},
{"format": "mp3", "codec_config": CodecConfig(qscale=1)},
]
)

/pytorch/audio/examples/tutorials/effector_tutorial.py:330: UserWarning: torio.io._streaming_media_encoder.CodecConfig has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
{"format": "mp3", "codec_config": CodecConfig(compression_level=1)},
/pytorch/audio/examples/tutorials/effector_tutorial.py:331: UserWarning: torio.io._streaming_media_encoder.CodecConfig has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
{"format": "mp3", "codec_config": CodecConfig(compression_level=9)},
/pytorch/audio/examples/tutorials/effector_tutorial.py:332: UserWarning: torio.io._streaming_media_encoder.CodecConfig has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
{"format": "mp3", "codec_config": CodecConfig(bit_rate=192_000)},
/pytorch/audio/examples/tutorials/effector_tutorial.py:333: UserWarning: torio.io._streaming_media_encoder.CodecConfig has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
{"format": "mp3", "codec_config": CodecConfig(bit_rate=8_000)},
/pytorch/audio/examples/tutorials/effector_tutorial.py:334: UserWarning: torio.io._streaming_media_encoder.CodecConfig has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
{"format": "mp3", "codec_config": CodecConfig(qscale=9)},
/pytorch/audio/examples/tutorials/effector_tutorial.py:335: UserWarning: torio.io._streaming_media_encoder.CodecConfig has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
{"format": "mp3", "codec_config": CodecConfig(qscale=1)},
/pytorch/audio/examples/tutorials/effector_tutorial.py:278: UserWarning: torchaudio.io._effector.AudioEffector has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
effector = AudioEffector(**config)
/pytorch/audio/src/torchaudio/io/_effector.py:98: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
writer = StreamWriter(buffer, format=muxer)
/pytorch/audio/src/torchaudio/io/_effector.py:286: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
reader = StreamReader(src, format=muxer, option=option)
默认¶
results[0]
压缩级别=1¶
results[1]
压缩级别=9¶
results[2]
比特率=192k¶
results[3]
比特率=8k¶
results[4]
量化级别=9¶
results[5]
量化级别=1¶
results[6]
脚本总运行时间: ( 0 分钟 3.000 秒)