scipy 如何在python中编写多通道wav文件

k10s72fa  于 2022-11-10  发布在  Python
关注(0)|答案(2)|浏览(228)

我正在使用pydub阅读多声道音频,并且正在进行一些操作来更改音频的响度。现在我想将此多声道音频写为.wav文件吗?
我不知道该怎么做。pydub不支持此操作。
有人能帮我吗?
谨致问候Denis

aemubtdh

aemubtdh1#

您可以从多个单声道音频片段中制作多声道音频片段:

from pydub import AudioSegment

# load individual channels...

mutli_channel = AudioSegment.from_mono_audiosegments(channel1, channel2, ..., channel_n)

更多信息请参见pydub文档

ep6jt1vc

ep6jt1vc2#

我推荐使用soundfilewrite函数。它需要一个形状为(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)

相关问题