<jupyter_start><jupyter_text>Pitch shifting<jupyter_code>import IPython
import librosa
import numpy as np
import shiftpitch as s
%%timeit # RUNS 10 TIMES


s.pitchshift("audiodata/e2.wav",24)

s.pitchshift("audiodata/e2.wav",24)
%%timeit

# TIME FOR LOADING A .WAV FILE

y, sr = librosa.load("audiodata/e2.wav")         # y is audio array and sr is sample rate   
# LOADING AND SLICING .WAV FILE

y, sr = librosa.load("e2.wav")         # y is audio array and sr is sample rate   

y = y[0:6000]                          # slicing first 6000 values of array

IPython.display.Audio(data=y, rate=sr) 
%%timeit

# TIME FOR PITCH SHIFTING THE NOTE 24 times

for i in range(0,24):     
    
    y_shift = librosa.effects.pitch_shift(y, sr, i, bins_per_octave=12)  
# PITCH SHIFTING AND CONCATENATING THE NOTE 24 times

ARRAY = np.zeros(0)      #empty array 

for i in range(0,24):     
    
    y_shift = librosa.effects.pitch_shift(y, sr, i, bins_per_octave=12)  
    
    #A step (i) is equal to a semitone if bins_per_octave is set to 12.
    
    ARRAY = np.concatenate((ARRAY, y_shift))
    
IPython.display.Audio(data=y_shift, rate=sr)
IPython.display.Image(url="https://i.imgur.com/59wKWkd.jpg")<jupyter_output><empty_output><jupyter_text>Measuring pitch<jupyter_code># useful for measuring pitch shift in numbers
# https://web.mst.edu/~kosbar/ee3430/ff/fourier/notes_pitchnames.html

import pitch

p = pitch.find_pitch('e2.wav')

print('pitch =', p)<jupyter_output>pitch = 164.55223880597015<jupyter_text>pysndfx<jupyter_code># 358 ms ± 1.23 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

# REVERB and other effects

# ERROR 1 : [WinError 2] The system cannot find the file specified
# Fix - install soX from sourceforge, add its path to sys variables and restart pc

# full implementation - https://github.com/carlthome/python-audio-effects/blob/master/pysndfx/dsp.py


from pysndfx import AudioEffectsChain

fx = (AudioEffectsChain().reverb())
fx1 = (AudioEffectsChain().equalizer(frequency=20, q=100.0, db=-20.0))

infile = 'hello.wav'

from librosa import load
hello, sr = load(infile)
hello_reverb = fx(hello)
hello_eq = fx1(hello)
IPython.display.Audio(data=hello, rate=sr)
IPython.display.Audio(data=hello_reverb, rate=sr)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11458792419568092, 'fraction_numerical': 0.035698545614808286, 'mean_word_length': 4.022123893805309, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '425965', 'license': 'MIT', 'n_tokens_mistral': 942, 'n_tokens_neox': 858, 'n_words': 217, 'path': 'resources/Pitch-shifting-and-pysndfx.ipynb', 'repo_name': 'Redict/rg_production', 'size': '2269'}