예제 #1
0
def test_reduce_cafe_noise():
    # load data
    wav_loc = "assets/coffe-1_2020-03-08_170854361.wav"
    rate, data = wavfile.read(wav_loc)
    data = int16_to_float32(data)
    noise_loc = "assets/coffe-1x_2020-03-08_170932616.wav"
    noise_rate, noise_data = wavfile.read(noise_loc)
    noise_data = int16_to_float32(noise_data)
    # add noise
    snr = 2  # signal to noise ratio
    noise_clip = noise_data / snr
    audio_clip_cafe = data
    # reduce noise
    reduced_noise = nr.reduce_noise(audio_clip=audio_clip_cafe,
                                    noise_clip=noise_clip,
                                    verbose=True)
    return float32_to_int16(reduced_noise)
예제 #2
0
def test_reduce_cafe_noise():
    # load data
    wav_loc = "assets/fish.wav"
    rate, data = wavfile.read(wav_loc)
    data = int16_to_float32(data)
    noise_loc = "assets/cafe_short.wav"
    noise_rate, noise_data = wavfile.read(noise_loc)
    noise_data = int16_to_float32(noise_data)
    # add noise
    snr = 2  # signal to noise ratio
    noise_clip = noise_data / snr
    audio_clip_cafe = data + noise_clip

    # reduce noise
    reduced_noise = nrv1.reduce_noise(audio_clip=audio_clip_cafe,
                                      noise_clip=noise_clip,
                                      verbose=True)
    return float32_to_int16(reduced_noise)
예제 #3
0
def test_reduce_generated_noise():
    # load data
    wav_loc = "assets/fish.wav"
    rate, data = wavfile.read(wav_loc)
    data = int16_to_float32(data)
    # add noise
    noise_len = 2  # seconds
    noise = (band_limited_noise(
        min_freq=2000, max_freq=12000, samples=len(data), samplerate=rate) *
             10)
    noise_clip = noise[:rate * noise_len]
    audio_clip_band_limited = data + noise
    return nrv1.reduce_noise(audio_clip=audio_clip_band_limited,
                             noise_clip=noise_clip,
                             verbose=True)
예제 #4
0
                        type=str,
                        help='Noisy File',
                        required=True)
    parser.add_argument('--output_file',
                        '-o',
                        type=str,
                        help='Denoised file',
                        required=True)
    parser.add_argument('--threshold',
                        '-t',
                        type=float,
                        help='Threshold',
                        default=1.5)

    args = parser.parse_args()

    r, y = load_wav(args.input_file)
    y = int16_to_float32(y)
    noise = find_some_background_noise(r, y)
    wavfile.write(f'{args.output_file}.noise_section.wav', r, noise)
    reduced_noise = nr.reduce_noise(
        n_std_thresh=args.threshold,
        n_fft=1024,
        win_length=1024,
        audio_clip=y,
        noise_clip=noise,
        use_tensorflow=False,
        verbose=False,
    )
    wavfile.write(args.output_file, r, np.array(reduced_noise))