当前位置: 首页>>代码示例>>Python>>正文


Python librosa.amplitude_to_db方法代码示例

本文整理汇总了Python中librosa.amplitude_to_db方法的典型用法代码示例。如果您正苦于以下问题:Python librosa.amplitude_to_db方法的具体用法?Python librosa.amplitude_to_db怎么用?Python librosa.amplitude_to_db使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在librosa的用法示例。


在下文中一共展示了librosa.amplitude_to_db方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: wav2melspec_db

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import amplitude_to_db [as 别名]
def wav2melspec_db(wav, sr, n_fft, win_length, hop_length, n_mels, normalize=False, max_db=None, min_db=None, time_first=True, **kwargs):

    # Mel-spectrogram
    mel_spec = wav2melspec(wav, sr, n_fft, win_length, hop_length, n_mels, time_first=False, **kwargs)

    # Decibel
    mel_db = librosa.amplitude_to_db(mel_spec)

    # Normalization
    mel_db = normalize_db(mel_db, max_db, min_db) if normalize else mel_db

    # Time-axis first
    if time_first:
        mel_db = mel_db.T  # (t, n_mels)

    return mel_db 
开发者ID:andabi,项目名称:voice-vector,代码行数:18,代码来源:audio.py

示例2: wav2melspec_db

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import amplitude_to_db [as 别名]
def wav2melspec_db(wav, sr, n_fft, win_length, hop_length, n_mels, max_db=None, min_db=None,
                   time_first=True, **kwargs):
    # Mel-spectrogram
    mel_spec = wav2melspec(wav, sr, n_fft, win_length, hop_length, n_mels, time_first=False, **kwargs)

    # Decibel
    mel_db = librosa.amplitude_to_db(mel_spec)

    # Normalization
    mel_db = normalize_db(mel_db, max_db, min_db) if max_db and min_db else mel_db

    # Time-axis first
    if time_first:
        mel_db = mel_db.T  # (t, n_mels)

    return mel_db 
开发者ID:andabi,项目名称:parallel-wavenet-vocoder,代码行数:18,代码来源:audio.py

示例3: visualize_spectrogram

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import amplitude_to_db [as 别名]
def visualize_spectrogram(audio_signal, ch=0, do_mono=False, x_axis='time', 
                          y_axis='linear',  **kwargs):
    """
    Wrapper around `librosa.display.specshow` for usage with AudioSignals.
    
    Args:
        audio_signal (AudioSignal): AudioSignal to plot
        ch (int, optional): Which channel to plot. Defaults to 0.
        do_mono (bool, optional): Make the AudioSignal mono. Defaults to False.
        x_axis (str, optional): x_axis argument to librosa.display.specshow. Defaults to 'time'.
        y_axis (str, optional): y_axis argument to librosa.display.specshow. Defaults to 'linear'.
        kwargs: Additional keyword arguments to librosa.display.specshow.
    """
    import librosa.display

    if do_mono:
        audio_signal = audio_signal.to_mono(overwrite=False)
    
    data = librosa.amplitude_to_db(np.abs(audio_signal.stft()), ref=np.max)
    librosa.display.specshow(data[..., ch], x_axis=x_axis, y_axis=y_axis, 
        sr=audio_signal.sample_rate, hop_length=audio_signal.stft_params.hop_length,
        **kwargs) 
开发者ID:nussl,项目名称:nussl,代码行数:24,代码来源:utils.py

示例4: test_melfilter_librosa

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import amplitude_to_db [as 别名]
def test_melfilter_librosa():
    filename = librosa.util.example_audio_file()
    y, sr = librosa.load(filename, offset=1.0, duration=0.3)
    n_fft = 1024
    hop_length = 256
    fmin = 500
    fmax = 5000
    n_mels = 16

    spec = numpy.abs(librosa.core.stft(y, n_fft=n_fft, hop_length=hop_length))**2
    spec1 = spec[:,0]

    ref = librosa.feature.melspectrogram(S=spec1, sr=sr, norm=None, htk=True, n_fft=n_fft, n_mels=n_mels, fmin=fmin, fmax=fmax)
    out = eml_audio.melfilter(spec1, sr, n_fft, n_mels, fmin, fmax)

    fig, (ref_ax, out_ax) = plt.subplots(2)
    def specshow(d, ax):
        s = librosa.amplitude_to_db(d, ref=numpy.max)
        librosa.display.specshow(s, ax=ax, x_axis='time')
    specshow(ref.reshape(-1, 1), ax=ref_ax)
    specshow(out.reshape(-1, 1), ax=out_ax)
    fig.savefig('melfilter.librosa.png')

    assert ref.shape == out.shape
    numpy.testing.assert_allclose(ref, out, rtol=0.01) 
开发者ID:emlearn,项目名称:emlearn,代码行数:27,代码来源:test_audio.py

示例5: compute_features

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import amplitude_to_db [as 别名]
def compute_features(self):
        """Actual implementation of the features.

        Returns
        -------
        mfcc: np.array(N, F)
            The features, each row representing a feature vector for a give
            time frame/beat.
        """
        S = librosa.feature.melspectrogram(self._audio,
                                           sr=self.sr,
                                           n_fft=self.n_fft,
                                           hop_length=self.hop_length,
                                           n_mels=self.n_mels)
        log_S = librosa.amplitude_to_db(S, ref=self.ref_power)
        mfcc = librosa.feature.mfcc(S=log_S, n_mfcc=self.n_mfcc).T
        return mfcc 
开发者ID:urinieto,项目名称:msaf,代码行数:19,代码来源:features.py

示例6: parse_audio

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import amplitude_to_db [as 别名]
def parse_audio(audio_path):
    sound = load_audio(audio_path, DEL_SILENCE)

    spectrogram = librosa.feature.melspectrogram(sound, SAMPLE_RATE, n_mels=N_MELS, n_fft=N_FFT, hop_length=HOP_LENGTH)
    spectrogram = librosa.amplitude_to_db(spectrogram, ref=np.max)

    if NORMALIZE:
        mean = np.mean(spectrogram)
        std = np.std(spectrogram)
        spectrogram -= mean
        spectrogram /= std

    spectrogram = spectrogram[:, ::-1]

    spectrogram = torch.FloatTensor(np.ascontiguousarray(np.swapaxes(spectrogram, 0, 1)))

    return spectrogram 
开发者ID:sooftware,项目名称:KoSpeech,代码行数:19,代码来源:attn_visualize.py

示例7: __init__

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import amplitude_to_db [as 别名]
def __init__(self, sample_rate=16000, n_mels=80, window_size=20, stride=10, feature_extract_by='librosa'):
        self.sample_rate = sample_rate
        self.n_mels = n_mels
        self.n_fft = int(sample_rate * 0.001 * window_size)
        self.hop_length = int(sample_rate * 0.001 * stride)
        self.feature_extract_by = feature_extract_by.lower()

        if self.feature_extract_by == 'torchaudio':
            self.transforms = torchaudio.transforms.MelSpectrogram(
                sample_rate=sample_rate,
                win_length=window_size,
                hop_length=self.hop_length,
                n_fft=self.n_fft,
                n_mels=n_mels
            )
            self.amplitude_to_db = torchaudio.transforms.AmplitudeToDB() 
开发者ID:sooftware,项目名称:KoSpeech,代码行数:18,代码来源:feature.py

示例8: __call__

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import amplitude_to_db [as 别名]
def __call__(self, signal):
        if self.feature_extract_by == 'torchaudio':
            melspectrogram = self.transforms(torch.FloatTensor(signal))
            melspectrogram = self.amplitude_to_db(melspectrogram)
            melspectrogram = melspectrogram.numpy()

        elif self.feature_extract_by == 'librosa':
            melspectrogram = librosa.feature.melspectrogram(
                y=signal,
                sr=self.sample_rate,
                n_mels=self.n_mels,
                n_fft=self.n_fft,
                hop_length=self.hop_length
            )
            melspectrogram = librosa.amplitude_to_db(melspectrogram, ref=np.max)

        else:
            raise ValueError("Unsupported library : {0}".format(self.feature_extract_by))

        return melspectrogram 
开发者ID:sooftware,项目名称:KoSpeech,代码行数:22,代码来源:feature.py

示例9: wav2melspec_db

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import amplitude_to_db [as 别名]
def wav2melspec_db(wav, sr, n_fft, win_length, hop_length, n_mels, normalize=False, max_db=None, min_db=None,
                   time_first=True, **kwargs):
    # Mel-spectrogram
    mel_spec = wav2melspec(wav, sr, n_fft, win_length, hop_length, n_mels, time_first=False, **kwargs)

    # Decibel
    mel_db = librosa.amplitude_to_db(mel_spec)

    # Normalization
    mel_db = normalize_db(mel_db, max_db, min_db) if normalize else mel_db

    # Time-axis first
    if time_first:
        mel_db = mel_db.T  # (t, n_mels)

    return mel_db 
开发者ID:andabi,项目名称:deep-voice-conversion,代码行数:18,代码来源:audio.py

示例10: amp2db

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import amplitude_to_db [as 别名]
def amp2db(amp):
    return librosa.amplitude_to_db(amp) 
开发者ID:andabi,项目名称:parallel-wavenet-vocoder,代码行数:4,代码来源:audio.py

示例11: test_ml_amplitude_to_db

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import amplitude_to_db [as 别名]
def test_ml_amplitude_to_db(one_item):
    module = ml.networks.modules.AmplitudeToDB()
    output = module(one_item['mix_magnitude'])

    librosa_output = librosa.amplitude_to_db(
        one_item['mix_magnitude'].cpu().numpy()[0],
        amin=1e-4,
        ref=1.0,
    )
    output = output.cpu().numpy()
    assert np.allclose(output, librosa_output) 
开发者ID:nussl,项目名称:nussl,代码行数:13,代码来源:test_modules.py

示例12: extract_feature

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import amplitude_to_db [as 别名]
def extract_feature(filepath, args):
    samples, sample_rate = sf.read(filepath)
    if args.use_lg_mels == 1:
        S = librosa.feature.melspectrogram(samples.astype(float), sr=sample_rate, n_mels=args.n_mels,\
                                           n_fft=int(sample_rate*(args.n_fft/1000)), \
                                           hop_length=int(sample_rate*(args.hop_length/1000)),\
                                           power=1.0)
        original_len = S.shape[-1]; #print(S.shape)
        if (args.max_frame_len - original_len) >= 0:
            S = np.append(S, (1e-9)*np.ones((args.n_mels, args.max_frame_len-original_len)), axis=1)
            S = librosa.amplitude_to_db(S) # convert to log mel energies
            delta1_S = librosa.feature.delta(S, order=1)
            delta2_S = librosa.feature.delta(S, order=2)
            #S[:,:original_len] = scaler.fit_transform(S[:,:original_len].T).T
            #delta1_S[:,:original_len] = scaler.fit_transform(delta1_S[:,:original_len].T).T
            #delta2_S[:,:original_len] = scaler.fit_transform(delta2_S[:,:original_len].T).T
            features = np.stack((S, delta1_S, delta2_S), axis=0); #break; break;break
            #features = librosa.power_to_db(S, ref=np.max)
            #features = scaler.fit_transform(S.T).T
        else:
            features = None
    else:
        mfcc = librosa.feature.mfcc(y=samples.astype(float), sr=sample_rate, n_mfcc=args.n_mfcc,\
                                                        n_fft=int(sample_rate*(args.n_fft/1000)), \
                                                        hop_length=int(sample_rate*(args.hop_length/1000)))
        original_len = mfcc.shape[-1]
        if (args.max_frame_len - original_len) >= 0:
            mfcc = np.append(mfcc, np.zeros((args.n_mfcc, args.max_frame_len-original_len)), axis=1)
            delta1_mfcc = librosa.feature.delta(mfcc, order=1)
            delta2_mfcc = librosa.feature.delta(mfcc, order=2)
            #mfcc[:,:original_len] = scaler.fit_transform(mfcc[:,:original_len].T).T
            #delta1_mfcc[:,:original_len] = scaler.fit_transform(delta1_mfcc[:,:original_len].T).T
            #delta2_mfcc[:,:original_len] = scaler.fit_transform(delta2_mfcc[:,:original_len].T).T
            features = np.stack((mfcc, delta1_mfcc, delta2_mfcc), axis=0)
        else:
            features = None
    return features, original_len 
开发者ID:plkmo,项目名称:NLP_Toolkit,代码行数:39,代码来源:preprocessing_funcs.py

示例13: transform_audio

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import amplitude_to_db [as 别名]
def transform_audio(self, y):
        '''Compute the STFT magnitude and phase.

        Parameters
        ----------
        y : np.ndarray
            The audio buffer

        Returns
        -------
        data : dict
            data['mag'] : np.ndarray, shape=(n_frames, 1 + n_fft//2)
                STFT magnitude

            data['phase'] : np.ndarray, shape=(n_frames, 1 + n_fft//2)
                STFT phase
        '''
        n_frames = self.n_frames(get_duration(y=y, sr=self.sr))

        D = stft(y, hop_length=self.hop_length,
                 n_fft=self.n_fft)

        D = fix_length(D, n_frames)

        mag, phase = magphase(D)
        if self.log:
            mag = amplitude_to_db(mag, ref=np.max)

        return {'mag': to_dtype(mag.T[self.idx], self.dtype),
                'phase': to_dtype(np.angle(phase.T)[self.idx], self.dtype)} 
开发者ID:bmcfee,项目名称:pumpp,代码行数:32,代码来源:fft.py

示例14: transform_audio

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import amplitude_to_db [as 别名]
def transform_audio(self, y):
        '''Compute the CQT

        Parameters
        ----------
        y : np.ndarray
            The audio buffer

        Returns
        -------
        data : dict
            data['mag'] : np.ndarray, shape = (n_frames, n_bins)
                The CQT magnitude

            data['phase']: np.ndarray, shape = mag.shape
                The CQT phase
        '''
        n_frames = self.n_frames(get_duration(y=y, sr=self.sr))

        C = cqt(y=y, sr=self.sr, hop_length=self.hop_length,
                fmin=self.fmin,
                n_bins=(self.n_octaves * self.over_sample * 12),
                bins_per_octave=(self.over_sample * 12))

        C = fix_length(C, n_frames)

        cqtm, phase = magphase(C)
        if self.log:
            cqtm = amplitude_to_db(cqtm, ref=np.max)

        return {'mag': to_dtype(cqtm.T[self.idx], self.dtype),
                'phase': to_dtype(np.angle(phase).T[self.idx], self.dtype)} 
开发者ID:bmcfee,项目名称:pumpp,代码行数:34,代码来源:cqt.py

示例15: transform_audio

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import amplitude_to_db [as 别名]
def transform_audio(self, y):
        '''Compute the Mel spectrogram

        Parameters
        ----------
        y : np.ndarray
            The audio buffer

        Returns
        -------
        data : dict
            data['mag'] : np.ndarray, shape=(n_frames, n_mels)
                The Mel spectrogram
        '''
        n_frames = self.n_frames(get_duration(y=y, sr=self.sr))

        mel = np.sqrt(melspectrogram(y=y, sr=self.sr,
                                     n_fft=self.n_fft,
                                     hop_length=self.hop_length,
                                     n_mels=self.n_mels,
                                     fmax=self.fmax))

        mel = fix_length(mel, n_frames)

        if self.log:
            mel = amplitude_to_db(mel, ref=np.max)

        # Type convert
        mel = to_dtype(mel, self.dtype)

        return {'mag': mel.T[self.idx]} 
开发者ID:bmcfee,项目名称:pumpp,代码行数:33,代码来源:mel.py


注:本文中的librosa.amplitude_to_db方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。