Ejemplo n.º 1
0
def test_get_vad_samples_stft_consistency():
    sr = 48000
    win_size_ms = 50
    percent_overlap = 0
    snr = 20
    speech, sr = sp.loadsound(test_python, sr=sr)
    noise = sp.generate_noise(len(speech), random_seed=40)
    speech_snr, snr_measured = sp.dsp.add_backgroundsound(
        speech,
        noise,
        sr=sr,
        snr=snr,
        delay_mainsound_sec=1,
        total_len_sec=3,
        random_seed=40)
    vad_samples, vad_matrix1 = sp.feats.get_vad_samples(
        speech_snr,
        sr=sr,
        win_size_ms=win_size_ms,
        percent_overlap=percent_overlap)
    vad_stft, vad_matrix2 = sp.feats.get_vad_stft(
        speech_snr,
        sr=sr,
        win_size_ms=win_size_ms,
        percent_overlap=percent_overlap)
    vad_samples_ms = len(vad_samples) / sr / 0.001
    vad_stft_ms = len(vad_stft) * win_size_ms
    assert vad_samples_ms == vad_stft_ms
Ejemplo n.º 2
0
def test_get_samples_clipped_40SNR_50percentVAD_length_threshold():
    sr = 48000
    win_size_ms = 50
    percent_overlap = 0
    snr = 40
    speech, sr = sp.loadsound(test_python, sr=sr, remove_dc=False)
    # get just speech segment, no surrounding silence:
    # goal VAD
    speech_only, sr = sp.loadsound('{}python_speech_only.wav'.format(test_dir),
                                   sr=sr,
                                   remove_dc=False)
    noise = sp.generate_noise(len(speech), random_seed=40)
    speech_snr, snr_measured = sp.dsp.add_backgroundsound(
        speech,
        noise,
        sr=sr,
        snr=snr,
        delay_mainsound_sec=1,
        total_len_sec=3,
        random_seed=snr,
        remove_dc=False)
    vad_samples, vad_vector = sp.feats.get_samples_clipped(
        speech_snr,
        sr=sr,
        win_size_ms=win_size_ms,
        percent_overlap=percent_overlap)
    vad_samples_ms = len(vad_samples) / sr / 0.001
    example_speech_ms = len(speech_only) / sr / 0.001
    if example_speech_ms >= vad_samples_ms:
        assert (example_speech_ms / vad_samples_ms) < 2
    elif example_speech_ms <= vad_samples_ms:
        assert (vad_samples_ms / example_speech_ms) < 2
Ejemplo n.º 3
0
#########################################################################
# Add them together and see what they look like:
sig3 = sig1 + sig2
sp.plotsound(sig3,
             sr=sr,
             feature_type='signal',
             title='Mixed Signals: {} Hz + {} Hz'.format(sig1_hz, sig2_hz))

##########################################################################
# Generate Pseudo-Random Noise
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#########################################################################
# Create noise to add to the signal:
noise = sp.generate_noise(len(sig3), amplitude=0.025, random_seed=40)
sp.plotsound(noise, sr=sr, feature_type='signal', title='Random Noise')

###########################################################################
# Control SNR: Adding a Background Sound
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#########################################################################
# Add noise at signal-to-noise ratio of 40
sig_noisy, snr = sp.dsp.add_backgroundsound(audio_main=sig3,
                                            audio_background=noise,
                                            sr=sr,
                                            snr=40,
                                            clip_at_zero=False)

# keep energy between 1 and -1