簡體   English   中英

如何在 python 中寫入多通道 wav 文件

[英]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 文檔中的更多信息

我推薦使用soundfilewrite 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM