def any_to_flac(audio_file_name): if audio_file_name.split('.')[1] == 'mp3': sound = AudioSegment.from_file(audio_file_name) audio_file_name = audio_file_name.split('.')[0] + '.flac' effects.high_pass_filter(sound, 300) sound.export(audio_file_name, format='flac') print('Flac Conversion Done') elif audio_file_name.split('.')[1] == 'm4a': sound = AudioSegment.from_file(audio_file_name) audio_file_name = audio_file_name.split('.')[0] + '.flac' sound.export(audio_file_name, format='flac') print('Flac Conversion Done') else: print('The format is not recognized')
def cheap_eq(seg, focus_freq, bandwidth=100, mode="peak", gain_dB=0, order=2): ''' Cheap EQ in PyDub Silence=-120dBFS I2/I1=2=>3dB SPL Gain ''' if gain_dB >= 0: if mode == "peak": sec = band_pass_filter(seg, focus_freq - bandwidth / 2, focus_freq + bandwidth / 2, order=order) seg = seg.overlay(sec - (3 - gain_dB)) return peak_limiter(seg) pass if mode == "low_shelf": sec = low_pass_filter(seg, focus_freq, order=order) seg = seg.overlay(sec - (3 - gain_dB)) return peak_limiter(seg) pass if mode == "high_shelf": sec = high_pass_filter(seg, focus_freq, order=order) seg = seg.overlay(sec - (3 - gain_dB)) return peak_limiter(seg) pass pass if gain_dB < 0: if mode == "peak": sec = high_pass_filter(seg, focus_freq - bandwidth / 2, order=order) seg = seg.overlay(sec - (3 + gain_dB)) + gain_dB sec = low_pass_filter(seg, focus_freq + bandwidth / 2, order=order) seg = seg.overlay(sec - (3 + gain_dB)) + gain_dB return peak_limiter(seg) pass if mode == "low_shelf": sec = high_pass_filter(seg, focus_freq, order=order) seg = seg.overlay(sec - (3 + gain_dB)) + gain_dB return peak_limiter(seg) pass if mode == "high_shelf": sec = low_pass_filter(seg, focus_freq, order=order) seg = seg.overlay(sec - (3 + gain_dB)) + gain_dB return peak_limiter(seg) pass pass pass
def blah_custom_eq(sample, low_db=0, demud_db=0, intel_db=0, air_db=0): sample.set_channels(1) # tmp print("eq-ing ...") bands = [] bands.append( scipy_effects.low_pass_filter(sample, 100) + low_db ) bands.append( scipy_effects.band_pass_filter(sample, 100, 250) ) bands.append( scipy_effects.band_pass_filter(sample, 250, 300) + demud_db ) bands.append( scipy_effects.band_pass_filter(sample, 300, 2500) ) bands.append( scipy_effects.band_pass_filter(sample, 2500, 3000) + intel_db ) bands.append( scipy_effects.band_pass_filter(sample, 3000, 10000) ) bands.append( scipy_effects.band_pass_filter(sample, 10000, 16000) + air_db ) bands.append( scipy_effects.high_pass_filter(sample, 16000) ) result = bands[0] for b in bands[1:]: result = result.overlay(b) plt.figure() sample.set_channels(1) raw = sample.get_array_of_samples() fft = np.fft.rfft(raw) freq = np.fft.rfftfreq(len(raw), d=1/sample_rate) plt.plot(freq, np.abs(fft), label="sample") if True: for i, b in enumerate(bands[1:2]): b.set_channels(1) raw = b.get_array_of_samples() fft = np.fft.rfft(raw) freq = np.fft.rfftfreq(len(raw), d=1/sample_rate) plt.plot(freq, np.abs(fft), label="band %d" % i) result.set_channels(1) raw = result.get_array_of_samples() fft = np.fft.rfft(raw) freq = np.fft.rfftfreq(len(raw), d=1/sample_rate) plt.plot(freq, np.abs(fft), label="eq result") #fig, ax = plt.subplots(nrows=8, sharex=True, sharey=True) #oenv = librosa.onset.onset_strength(y=np.array(raw).astype('float'), # sr=sample_rate, # hop_length=hop_length) #t = librosa.times_like(oenv, sr=sample_rate, hop_length=hop_length) #chroma = librosa.feature.chroma_cqt(y=np.array(raw).astype('float'), # sr=sample_rate, # hop_length=hop_length) #img = librosa.display.specshow(chroma, # x_axis='time', # y_axis='chroma', # hop_length=int(hop_length*0.5), ax=ax[0]) #fig.colorbar(img, ax=ax)a plt.legend() plt.show() return result
def lofi_filter(audioclip: AudioSegment, cutoff=500) -> AudioSegment: """ Yeah I just rewrapped the pydub's band_pass_filter. Fight me. """ audioclip = scipy_effects.low_pass_filter(audioclip, cutoff) audioclip = scipy_effects.high_pass_filter(audioclip, cutoff) return audioclip
print("> successfully opened mp3 file") # use ffmpeg for conversion to 16 bit & mono channel wav # required format for transcription api subprocess.call(f"ffmpeg -i {MP3_FILE} -acodec pcm_s16le -ac 1 -ar 16000 {WAV_FILE}", shell=True) # Use pydub low pass filter and export # cuts off all frequencies above 3500 Hz lp_audio = scipy_effects.low_pass_filter(audio_file, 3500) LP_MP3 = LP_FILE.replace("wav", "mp3") lp_audio.export(LP_MP3, format="mp3") subprocess.call(f"ffmpeg -i {LP_MP3} -acodec pcm_s16le -ac 1 -ar 16000 {LP_FILE}", shell=True) print("> successfully saved and converted low pass filter") # Use pydub high pass filter and export # cuts off all frequencies below 70 Hz # reference: Human hearing starts at 20 Hz, lowest average human speech starts at 85 Hz hp_audio = scipy_effects.high_pass_filter(audio_file, 70) HP_MP3 = HP_FILE.replace("wav", "mp3") hp_audio.export(HP_MP3, format="mp3") subprocess.call(f"ffmpeg -i {HP_MP3} -acodec pcm_s16le -ac 1 -ar 16000 {HP_FILE}", shell=True) print("> successfully saved and converted high pass filter") # Use pydub bandpass filter and export # Cut off frequencies below 70 and above 3500 Hz bp_audio = scipy_effects.band_pass_filter(audio_file, 70, 3500) BP_MP3 = BP_FILE.replace("wav", "mp3") bp_audio.export(BP_MP3, format="mp3") subprocess.call(f"ffmpeg -i {BP_MP3} -acodec pcm_s16le -ac 1 -ar 16000 {BP_FILE}", shell=True) print("> successfully saved and converted band pass filter")
''' print('Processing DynaMIX Stereo') print('\tTime Domain Processing') ''' DynaMIX Sample Processing:- Time Domain Gain Analysis: Using Relative Dominance Relative Stereo Separation ''' #Bass Band mid_channel = cheap_eq(mid_channel, 250, mode="low_shelf", gain_dB=6, order=2) mid_channel = cheap_eq(mid_channel, 650, mode="high_shelf", gain_dB=-24, order=2) rear_channel[0] = high_pass_filter(rear_channel[0], 100, order=2) rear_channel[1] = high_pass_filter(rear_channel[1], 100, order=2) ex_channel[0] = cheap_eq(ex_channel[0], 250, mode="low_shelf", gain_dB=1.5, order=2) ex_channel[1] = cheap_eq(ex_channel[1], 250, mode="low_shelf", gain_dB=1.5, order=2) ex_channel[4] = cheap_eq(ex_channel[4], 650, mode="low_shelf", gain_dB=-18,