예제 #1
0
def randAudioAugment():
    fx = AudioEffectsChain()
    effect = [random.randint(0, 1) for i in range(6)]

    if effect[0] == 1:  # lowshelf
        randGain = random.randint(0, 12) * random.choice([-1, 1])
        randFreq = random.randint(20, 300)
        randSlop = random.uniform(1, 7) / 10  # 0.1~0.7
        fx.lowshelf(gain=randGain, frequency=randFreq, slope=randSlop)
    if effect[1] == 1:  # highshelf
        randGain = random.randint(0, 12) * random.choice([-1, 1])
        randFreq = random.randint(1000, 3000)
        randSlop = random.uniform(1, 7) / 10  # 0.1~0.7
        fx.highshelf(gain=randGain, frequency=randFreq, slope=randSlop)
    if effect[2] == 1:  # equalizer
        randFreq = random.randint(100, 3000)
        randQ = random.uniform(5, 15) / 10  # 0.5~1.5
        randDB = random.randint(0, 6) * random.choice([-1, 1])
        fx.equalizer(frequency=randFreq, q=randQ, db=randDB)
    if effect[3] == 1:  # overdrive
        randGain = random.randint(3, 7)
        fx.overdrive(gain=randGain, colour=40)
    if effect[4] == 1:  # phaser
        fx.phaser(
            gain_in=0.9, gain_out=0.8, delay=1, decay=0.25, speed=2, triangular=False
        )
    if effect[5] == 1:  # reverb
        randReverb = random.randint(30, 70)
        randDamp = random.randint(30, 70)
        randRoom = random.randint(30, 70)
        randWet = random.randint(1, 6)
        fx.reverb(
            reverberance=randReverb,
            hf_damping=randDamp,
            room_scale=randRoom,
            stereo_depth=100,
            pre_delay=20,
            wet_gain=randWet,
            wet_only=False,
        )
    return fx
 def _lowshelf(self, chain: AudioEffectsChain):
     return chain.lowshelf(frequency=300)
예제 #3
0
import scipy.signal as sg
from pysndfx import AudioEffectsChain


def filter_audio(y, sr=16_000, cutoff=15_000, low_cutoff=1, filter_order=5):
    sos = sg.butter(filter_order, [low_cutoff / sr / 2, cutoff / sr / 2],
                    btype='band',
                    analog=False,
                    output='sos')
    filtered = sg.sosfilt(sos, y)

    return filtered


def shelf(y,
          sr=16_000,
          gain=5,
          frequency=500,
          slope=0.5,
          high_frequency=7_000):
    afc = AudioEffectsChain()
    fx = afc.lowshelf(gain=gain, frequency=frequency, slope=slope)\
            .highshelf(gain=-gain, frequency=high_frequency, slope=slope)

    y = fx(y, sample_in=sr, sample_out=sr)

    return y