Example #1
0
def Pattern_Generate(path, top_db=60):
    sig = librosa.core.load(path, sr=hp_Dict['Sound']['Sample_Rate'])[0]
    sig = preemphasis(sig)
    sig = librosa.effects.trim(
        sig, top_db=top_db, frame_length=32, hop_length=16)[0] * 0.99
    sig = inv_preemphasis(sig)

    mel = np.transpose(
        melspectrogram(y=sig,
                       num_freq=hp_Dict['Sound']['Spectrogram_Dim'],
                       hop_length=hp_Dict['Sound']['Frame_Shift'],
                       win_length=hp_Dict['Sound']['Frame_Length'],
                       num_mels=hp_Dict['Sound']['Mel_Dim'],
                       sample_rate=hp_Dict['Sound']['Sample_Rate'],
                       max_abs_value=hp_Dict['Sound']['Max_Abs_Mel']))

    return sig, mel
def Spectrogram_Generate(path, top_db=60, range_Ignore=False):
    sig = librosa.core.load(path, sr=hp_Dict['Sound']['Sample_Rate'])[0]
    sig = preemphasis(sig)
    sig = librosa.effects.trim(
        sig, top_db=top_db, frame_length=32, hop_length=16)[0] * 0.99
    sig = inv_preemphasis(sig)

    sig_Length = sig.shape[0] / hp_Dict['Sound']['Sample_Rate'] * 1000  #ms
    if not range_Ignore and (sig_Length < hp_Dict['Train']['Min_Wav_Length'] or
                             sig_Length > hp_Dict['Train']['Max_Wav_Length']):
        return None

    return np.transpose(
        spectrogram(y=sig,
                    num_freq=hp_Dict['Sound']['Spectrogram_Dim'],
                    frame_shift_ms=hp_Dict['Sound']['Frame_Shift'],
                    frame_length_ms=hp_Dict['Sound']['Frame_Length'],
                    sample_rate=hp_Dict['Sound']['Sample_Rate']).astype(
                        np.float32))