<jupyter_start><jupyter_text>Comparision of different SNR  Read clean voices<jupyter_code>clean_voices_list = glob('..\\data\\snr_test\\clean_voice\\*')
clean_voices_list = [os.path.basename(voice) for voice in clean_voices_list]
print(clean_voices_list)<jupyter_output>['marcin_clean.wav']<jupyter_text>Read noises<jupyter_code>noises_list = glob('..\\data\\snr_test\\noise\\*')
noises_list = [os.path.basename(noise) for noise in noises_list]
print(noises_list)<jupyter_output>['birds.wav', 'keyboard.wav', 'mouse.wav']<jupyter_text>Apply noise and compare<jupyter_code>def create_noise_files(noise_name):
    multipliers = [0.1, 0.2, 0.3, 0.4, 0.5, 0.8, 0.9, 1, 1.1, 1.5, 2, 2.5, 3, 4, 6, 8, 10, 14, 20, 30, 50, 100, 200]
    s, fs = librosa.load(os.path.join('..\\data\\snr_test\\clean_voice', clean_voices_list[0]))
    s_norm = librosa.util.normalize(s)
    snrs = []
    n, _ = librosa.load(os.path.join('..\\data\\snr_test\\noise', noise_name))
    n_norm = librosa.util.normalize(n)
    for i, multiplier in enumerate(multipliers):
        snrs.append(snr_db(s_norm, n_norm * multiplier))
        apply_noise('..\\data\\snr_test\\noisy_voice\\',
                                   f'{clean_voices_list[0][:-9]}{i}_{noise_name}', s_norm, n_norm * multiplier, fs)
    print(snrs)
    return snrs
    
def denoise_files():
    noisy_voices_list = sorted(glob('..\\data\\snr_test\\noisy_voice\\*'), key=len)
    noisy_voices_list = [os.path.basename(voice) for voice in noisy_voices_list]
    print(noisy_voices_list)
    
    for voice in noisy_voices_list:
        predict(audio_input_prediction=voice, audio_output_prediction=f'pred_{voice}', path='..\\data\\snr_test\\')
        
def calculate_psnrs():
    original, fs = librosa.load(os.path.join('..\\data\\snr_test\\clean_voice', clean_voices_list[0]))
    original_norm = librosa.util.normalize(original)
    # predicted_voices_list = glob('..\\data\\snr_test\\save_prediction\\*')
    predicted_voices_list = sorted(glob('..\\data\\snr_test\\save_prediction\\*'), key=len)
    predicted_voices_list = [os.path.basename(voice) for voice in predicted_voices_list]
    print(predicted_voices_list)

    psnrs = []
    for voice in predicted_voices_list:
        pred, fs = librosa.load(os.path.join('..\\data\\snr_test\\save_prediction', voice))
        psnrs.append(psnr(original_norm[:pred.shape[0]], pred))
    print(psnrs)
    
    fig, ax = plt.subplots(figsize=(10, 5))
    ax.plot(snrs, psnrs)
    ax.invert_xaxis()
    ax.set_xlabel('SNR [dB]')
    ax.set_ylabel('PSNR predict to clean [dB]')
    
def clean_files():
    files = glob('..\\data\\snr_test\\save_prediction\\*')
    for f in files:
        os.remove(f)
        
    files = glob('..\\data\\snr_test\\noisy_voice\\*')
    for f in files:
        os.remove(f)<jupyter_output><empty_output><jupyter_text>Marcin voice - keyboard noise<jupyter_code>%%capture
clean_files()
snrs = create_noise_files('keyboard.wav')
denoise_files()<jupyter_output>WARNING:tensorflow:5 out of the last 5 calls to <function Model.make_predict_function.<locals>.predict_function at 0x0000021C4703C8B0> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for  more details.
WARNING:tensorflow:6 out of the last 6 calls to <function Model.make_predict_function.<locals>.predict_function at 0x0000021C4703CDC0> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.f[...]<jupyter_text>Input SNR and predicted PSNR relationship<jupyter_code>calculate_psnrs()<jupyter_output>['pred_marcin_0_keyboard.wav', 'pred_marcin_1_keyboard.wav', 'pred_marcin_2_keyboard.wav', 'pred_marcin_3_keyboard.wav', 'pred_marcin_4_keyboard.wav', 'pred_marcin_5_keyboard.wav', 'pred_marcin_6_keyboard.wav', 'pred_marcin_7_keyboard.wav', 'pred_marcin_8_keyboard.wav', 'pred_marcin_9_keyboard.wav', 'pred_marcin_10_keyboard.wav', 'pred_marcin_11_keyboard.wav', 'pred_marcin_12_keyboard.wav', 'pred_marcin_13_keyboard.wav', 'pred_marcin_14_keyboard.wav', 'pred_marcin_15_keyboard.wav', 'pred_marcin_16_keyboard.wav', 'pred_marcin_17_keyboard.wav', 'pred_marcin_18_keyboard.wav', 'pred_marcin_19_keyboard.wav', 'pred_marcin_20_keyboard.wav', 'pred_marcin_21_keyboard.wav', 'pred_marcin_22_keyboard.wav']
[25.04, 25.0, 24.96, 24.95, 24.95, 24.96, 24.94, 24.92, 24.91, 24.83, 24.63, 24.08, 23.34, 22.04, 20.28, 19.51, 19.04, 18.73, 18.56, 18.4, 18.33, 18.28, 18.26]<jupyter_text>Marcin voice - birds noise<jupyter_code>%%capture
clean_files()
snrs = create_noise_files('birds.wav')
denoise_files()<jupyter_output><empty_output><jupyter_text>Input SNR and predicted PSNR relationship<jupyter_code>calculate_psnrs()<jupyter_output>['pred_marcin_0_birds.wav', 'pred_marcin_1_birds.wav', 'pred_marcin_2_birds.wav', 'pred_marcin_3_birds.wav', 'pred_marcin_4_birds.wav', 'pred_marcin_5_birds.wav', 'pred_marcin_6_birds.wav', 'pred_marcin_7_birds.wav', 'pred_marcin_8_birds.wav', 'pred_marcin_9_birds.wav', 'pred_marcin_10_birds.wav', 'pred_marcin_11_birds.wav', 'pred_marcin_12_birds.wav', 'pred_marcin_13_birds.wav', 'pred_marcin_14_birds.wav', 'pred_marcin_15_birds.wav', 'pred_marcin_16_birds.wav', 'pred_marcin_17_birds.wav', 'pred_marcin_18_birds.wav', 'pred_marcin_19_birds.wav', 'pred_marcin_20_birds.wav', 'pred_marcin_21_birds.wav', 'pred_marcin_22_birds.wav']
[24.89, 24.7, 24.48, 24.17, 23.91, 22.93, 22.49, 22.06, 21.71, 20.6, 19.7, 19.24, 18.98, 18.72, 18.48, 18.37, 18.31, 18.24, 18.2, 18.16, 18.14, 18.12, 18.11]<jupyter_text>Marcin voice - mouseclicks noise<jupyter_code>%%capture
clean_files()
snrs = create_noise_files('mouse.wav')
denoise_files()<jupyter_output><empty_output><jupyter_text>Input SNR and predicted PSNR relationship<jupyter_code>calculate_psnrs()<jupyter_output>['pred_marcin_0_mouse.wav', 'pred_marcin_1_mouse.wav', 'pred_marcin_2_mouse.wav', 'pred_marcin_3_mouse.wav', 'pred_marcin_4_mouse.wav', 'pred_marcin_5_mouse.wav', 'pred_marcin_6_mouse.wav', 'pred_marcin_7_mouse.wav', 'pred_marcin_8_mouse.wav', 'pred_marcin_9_mouse.wav', 'pred_marcin_10_mouse.wav', 'pred_marcin_11_mouse.wav', 'pred_marcin_12_mouse.wav', 'pred_marcin_13_mouse.wav', 'pred_marcin_14_mouse.wav', 'pred_marcin_15_mouse.wav', 'pred_marcin_16_mouse.wav', 'pred_marcin_17_mouse.wav', 'pred_marcin_18_mouse.wav', 'pred_marcin_19_mouse.wav', 'pred_marcin_20_mouse.wav', 'pred_marcin_21_mouse.wav', 'pred_marcin_22_mouse.wav']
[25.25, 25.19, 25.13, 25.05, 25.0, 24.93, 24.93, 24.92, 24.91, 24.84, 24.71, 24.47, 24.08, 23.46, 22.79, 22.46, 22.3, 21.68, 20.74, 19.82, 18.99, 18.48, 18.26]
{'fraction_non_alphanumeric': 0.14878255945639865, 'fraction_numerical': 0.06568516421291053, 'mean_word_length': 5.487603305785124, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '621174', 'license': 'MIT', 'n_tokens_mistral': 3199, 'n_tokens_neox': 2857, 'n_words': 449, 'path': 'notebooks/psnr_to_snr_experiment.ipynb', 'repo_name': 'jigiciak/noise_reduction', 'size': '7064'}