【问题标题】:Process 24bit wavs using pydub使用 pydub 处理 24 位 wav
【发布时间】:2018-02-18 02:36:54
【问题描述】:

我正在尝试编写一个基本程序,它随机选择 2 个音频文件,将它们分层,然后将其作为新文件写出来。我正在使用 pydub 并且一切正常,但是结果被扭曲了。我怀疑这是因为据我所知,pydub 无法处理 24 位 wav,而这恰好是示例包中的标准。

所以在进入 pydub 之前需要一些将 wav 转换为 16 位的小代码。希望不是需要先将其写入光盘。

from pydub import AudioSegment
import os
import random
import shutil    


def process(user_folder):

new_library_folder = user_folder + " Generated Combo Samples"
files_list = []
for root, directory, files in os.walk(user_folder):
    for file in files:
        if file_is_valid_ext(file):
            filepath = str(root) + "/" + str(file)
            # print filepath
            files_list.append(filepath)

# removes previously created folder
shutil.rmtree(new_library_folder)
os.makedirs(new_library_folder)

i = 0
for number in range(gen_count): # global at 100
    i = i + 1

    file1 = random.choice(files_list)
    file2 = random.choice(files_list)

    sound1 = AudioSegment.from_file(file1)
    sound2 = AudioSegment.from_file(file2)
    sound1 = match_target_amplitude(sound1, -20)
    sound2 = match_target_amplitude(sound2, -20)

    combinedsound = sound1.overlay(sound2)
    combinedsoundnormalised = match_target_amplitude(combinedsound, -6)

    combinedsound_path = new_library_folder + "/" + "Sample " + str(i) + ".wav"

    combinedsoundnormalised.export(combinedsound_path, format='wav')

【问题讨论】:

    标签: python pydub


    【解决方案1】:

    自您发布此问题以来已经有几个月了,但我会为可能需要解决此问题的其他人回答这个问题。据我所知,PySoundFile 是唯一可以处理 24 位音频的 python 包(我相信还有其他的,但我还没有找到)。我的建议是首先使用PySoundFile 读取音频,然后使用该数据创建pydub.AudioSegment

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-03
      • 1970-01-01
      • 1970-01-01
      • 2018-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多