[英]How to write multi channel wav file in python
我正在使用 pydub 读取多声道音频,并且正在做一些操作来改变音频的响度。 现在我想把这个多声道音频写成 .wav 文件?
我不知道该怎么做。 pydub 不支持此操作。
谁能帮我解决这个问题?
亲切的问候丹尼斯
您可以从多个 mono 音频段制作多声道音频段:
from pydub import AudioSegment
# load individual channels...
mutli_channel = AudioSegment.from_mono_audiosegments(channel1, channel2, ..., channel_n)
pydub 文档中的更多信息
我推荐使用soundfile的write function。 它需要一个形状为 (N, C) 的 numpy 矩阵,其中 N 是样本中的音频持续时间,C 是通道数。
pip install soundfile
import soundfile
import numpy as np
sampling_rate = 16000
duration_in_seconds = 1
num_channels = 2
# Create a white noise signal of two channels
audio_signal = np.random.randn(
sampling_rate*duration_in_seconds,
num_channels
)
soundfile.write("output.wav", audio_signal, sampling_rate)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.