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


Python librosa.istft方法代码示例

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


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

示例1: spectrogramToAudioFile

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import istft [as 别名]
def spectrogramToAudioFile(magnitude, fftWindowSize, hopSize, phaseIterations=10, phase=None, length=None):
    '''
    Computes an audio signal from the given magnitude spectrogram, and optionally an initial phase.
    Griffin-Lim is executed to recover/refine the given the phase from the magnitude spectrogram.
    :param magnitude: Magnitudes to be converted to audio
    :param fftWindowSize: Size of FFT window used to create magnitudes
    :param hopSize: Hop size in frames used to create magnitudes
    :param phaseIterations: Number of Griffin-Lim iterations to recover phase
    :param phase: If given, starts ISTFT with this particular phase matrix
    :param length: If given, audio signal is clipped/padded to this number of frames
    :return: 
    '''
    if phase is not None:
        if phaseIterations > 0:
            # Refine audio given initial phase with a number of iterations
            return reconPhase(magnitude, fftWindowSize, hopSize, phaseIterations, phase, length)
        # reconstructing the new complex matrix
        stftMatrix = magnitude * np.exp(phase * 1j) # magnitude * e^(j*phase)
        audio = librosa.istft(stftMatrix, hop_length=hopSize, length=length)
    else:
        audio = reconPhase(magnitude, fftWindowSize, hopSize, phaseIterations)
    return audio 
开发者ID:Veleslavia,项目名称:vimss,代码行数:24,代码来源:Input.py

示例2: griffin_lim

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import istft [as 别名]
def griffin_lim(mag, phase_angle, n_fft, hop, num_iters):
  """Iterative algorithm for phase retrieval from a magnitude spectrogram.

  Args:
    mag: Magnitude spectrogram.
    phase_angle: Initial condition for phase.
    n_fft: Size of the FFT.
    hop: Stride of FFT. Defaults to n_fft/2.
    num_iters: Griffin-Lim iterations to perform.

  Returns:
    audio: 1-D array of float32 sound samples.
  """
  fft_config = dict(n_fft=n_fft, win_length=n_fft, hop_length=hop, center=True)
  ifft_config = dict(win_length=n_fft, hop_length=hop, center=True)
  complex_specgram = inv_magphase(mag, phase_angle)
  for i in range(num_iters):
    audio = librosa.istft(complex_specgram, **ifft_config)
    if i != num_iters - 1:
      complex_specgram = librosa.stft(audio, **fft_config)
      _, phase = librosa.magphase(complex_specgram)
      phase_angle = np.angle(phase)
      complex_specgram = inv_magphase(mag, phase_angle)
  return audio 
开发者ID:magenta,项目名称:magenta,代码行数:26,代码来源:utils.py

示例3: inv_linear_spectrogram

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import istft [as 别名]
def inv_linear_spectrogram(linear_spectrogram, hparams):
	'''Converts linear spectrogram to waveform using librosa'''
	if hparams.signal_normalization:
		D = _denormalize(linear_spectrogram, hparams)
	else:
		D = linear_spectrogram

	S = _db_to_amp(D + hparams.ref_level_db)**(1/hparams.magnitude_power) #Convert back to linear

	if hparams.use_lws:
		processor = _lws_processor(hparams)
		D = processor.run_lws(S.astype(np.float64).T ** hparams.power)
		y = processor.istft(D).astype(np.float32)
		return inv_preemphasis(y, hparams.preemphasis, hparams.preemphasize)
	else:
		return inv_preemphasis(_griffin_lim(S ** hparams.power, hparams), hparams.preemphasis, hparams.preemphasize) 
开发者ID:Rayhane-mamah,项目名称:Tacotron-2,代码行数:18,代码来源:audio.py

示例4: inv_mel_spectrogram

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import istft [as 别名]
def inv_mel_spectrogram(mel_spectrogram, hparams):
	'''Converts mel spectrogram to waveform using librosa'''
	if hparams.signal_normalization:
		D = _denormalize(mel_spectrogram, hparams)
	else:
		D = mel_spectrogram

	S = _mel_to_linear(_db_to_amp(D + hparams.ref_level_db)**(1/hparams.magnitude_power), hparams)  # Convert back to linear

	if hparams.use_lws:
		processor = _lws_processor(hparams)
		D = processor.run_lws(S.astype(np.float64).T ** hparams.power)
		y = processor.istft(D).astype(np.float32)
		return inv_preemphasis(y, hparams.preemphasis, hparams.preemphasize)
	else:
		return inv_preemphasis(_griffin_lim(S ** hparams.power, hparams), hparams.preemphasis, hparams.preemphasize)

###########################################################################################
# tensorflow Griffin-Lim
# Thanks to @begeekmyfriend: https://github.com/begeekmyfriend/Tacotron-2/blob/mandarin-new/datasets/audio.py 
开发者ID:Rayhane-mamah,项目名称:Tacotron-2,代码行数:22,代码来源:audio.py

示例5: _griffinlim

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import istft [as 别名]
def _griffinlim(self, spectrogram, n_iter=100, window='hann', n_fft=2048, hop_length=-1, verbose=False):
        if hop_length == -1:
            hop_length = n_fft // 4

        angles = np.exp(2j * np.pi * np.random.rand(*spectrogram.shape))

        t = tqdm(range(n_iter), ncols=100, mininterval=2.0, disable=not verbose)
        for i in t:
            full = np.abs(spectrogram).astype(np.complex) * angles
            inverse = librosa.istft(full, hop_length=hop_length, window=window)
            rebuilt = librosa.stft(inverse, n_fft=n_fft, hop_length=hop_length, window=window)
            angles = np.exp(1j * np.angle(rebuilt))

            if verbose:
                diff = np.abs(spectrogram) - np.abs(rebuilt)
                t.set_postfix(loss=np.linalg.norm(diff, 'fro'))

        full = np.abs(spectrogram).astype(np.complex) * angles
        inverse = librosa.istft(full, hop_length=hop_length, window=window)

        return inverse 
开发者ID:tiberiu44,项目名称:TTS-Cube,代码行数:23,代码来源:vocoder.py

示例6: inv_linear_spectrogram

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import istft [as 别名]
def inv_linear_spectrogram(linear_spectrogram, hparams):
    '''Converts linear spectrogram to waveform using librosa'''
    if hparams.signal_normalization:
        D = _denormalize(linear_spectrogram, hparams)
    else:
        D = linear_spectrogram

    S = _db_to_amp(D + hparams.ref_level_db) #Convert back to linear

    if hparams.use_lws:
        processor = _lws_processor(hparams)
        D = processor.run_lws(S.astype(np.float64).T ** hparams.power)
        y = processor.istft(D).astype(np.float32)
        return inv_preemphasis(y, hparams.preemphasis, hparams.preemphasize)
    else:
        return inv_preemphasis(_griffin_lim(S ** hparams.power, hparams), hparams.preemphasis, hparams.preemphasize) 
开发者ID:hccho2,项目名称:Tacotron-Wavenet-Vocoder-Korean,代码行数:18,代码来源:audio.py

示例7: inv_mel_spectrogram

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import istft [as 别名]
def inv_mel_spectrogram(mel_spectrogram, hparams):
    '''Converts mel spectrogram to waveform using librosa'''
    if hparams.signal_normalization:
        D = _denormalize(mel_spectrogram, hparams)
    else:
        D = mel_spectrogram

    S = _mel_to_linear(_db_to_amp(D + hparams.ref_level_db), hparams)  # Convert back to linear

    if hparams.use_lws:
        processor = _lws_processor(hparams)
        D = processor.run_lws(S.astype(np.float64).T ** hparams.power)
        y = processor.istft(D).astype(np.float32)
        return inv_preemphasis(y, hparams.preemphasis, hparams.preemphasize)
    else:
        return inv_preemphasis(_griffin_lim(S ** hparams.power, hparams), hparams.preemphasis, hparams.preemphasize) 
开发者ID:hccho2,项目名称:Tacotron-Wavenet-Vocoder-Korean,代码行数:18,代码来源:audio.py

示例8: inv_linear_spectrogram

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import istft [as 别名]
def inv_linear_spectrogram(linear_spectrogram, hparams):
	'''Converts linear spectrogram to waveform using librosa'''
	if hparams.signal_normalization:
		D = _denormalize(linear_spectrogram, hparams)
	else:
		D = linear_spectrogram

	S = _db_to_amp(D + hparams.ref_level_db) #Convert back to linear

	if hparams.use_lws:
		processor = _lws_processor(hparams)
		D = processor.run_lws(S.astype(np.float64).T ** hparams.power)
		y = processor.istft(D).astype(np.float32)
		return inv_preemphasis(y, hparams.preemphasis)
	else:
		return inv_preemphasis(_griffin_lim(S ** hparams.power, hparams), hparams.preemphasis) 
开发者ID:Joee1995,项目名称:tacotron2-mandarin-griffin-lim,代码行数:18,代码来源:audio.py

示例9: inv_mel_spectrogram

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import istft [as 别名]
def inv_mel_spectrogram(mel_spectrogram, hparams):
	'''Converts mel spectrogram to waveform using librosa'''
	if hparams.signal_normalization:
		D = _denormalize(mel_spectrogram, hparams)
	else:
		D = mel_spectrogram

	S = _mel_to_linear(_db_to_amp(D + hparams.ref_level_db), hparams)  # Convert back to linear

	if hparams.use_lws:
		processor = _lws_processor(hparams)
		D = processor.run_lws(S.astype(np.float64).T ** hparams.power)
		y = processor.istft(D).astype(np.float32)
		return inv_preemphasis(y, hparams.preemphasis)
	else:
		return inv_preemphasis(_griffin_lim(S ** hparams.power, hparams), hparams.preemphasis) 
开发者ID:Joee1995,项目名称:tacotron2-mandarin-griffin-lim,代码行数:18,代码来源:audio.py

示例10: image_to_sound

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import istft [as 别名]
def image_to_sound(self, image):
        if self.mode == 'reallog' or self.mode == 'abslog':
            x = np.zeros((image.shape[0] + 1, image.shape[1]))  # real spectrograms have 2**i + 1 freq bins
            # x.fill(image.mean())
            x[:image.shape[0], :image.shape[1]] = image
            if self.mode == 'reallog':
                signed = adjust_dynamic_range(x, self.drange, (-1, 1))
                sgn = np.sign(signed)
                real_pt_stft = (np.exp(np.abs(signed)) - 1) * sgn
                signal = lbr.istft(real_pt_stft, self.hop_length)
            else:
                x = adjust_dynamic_range(x, self.drange, (0, 255))
                signal = self.reconstruct_from_magnitude(x)
        elif self.mode == 'raw':
            signal = image.ravel()
        else:
            raise Exception(
                'image_to_sound: unrecognized mode: {}. Available modes are: reallog, abslog, raw.'.format(self.mode)
            )
        signal = signal / np.abs(signal).max()
        return signal 
开发者ID:deepsound-project,项目名称:pggan-pytorch,代码行数:23,代码来源:output_postprocess.py

示例11: griffinlim

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import istft [as 别名]
def griffinlim(spectrogram, n_iter=100, window='hann', n_fft=2048, hop_length=None, verbose=False):
    if hop_length is None:
        hop_length = n_fft // 4

    angles = np.exp(2j * np.pi * np.random.rand(*spectrogram.shape))

    t = tqdm(range(n_iter), ncols=100, mininterval=2.0, disable=not verbose)

    for _ in t:
        full = np.abs(spectrogram).astype(np.complex) * angles
        inverse = librosa.istft(full, hop_length=hop_length, window=window)
        rebuilt = librosa.stft(inverse, n_fft=n_fft, hop_length=hop_length, window=window)
        angles = np.exp(1j * np.angle(rebuilt))
        if verbose:
            diff = np.abs(spectrogram) - np.abs(rebuilt)
            t.set_postfix(loss=np.linalg.norm(diff, 'fro'))

    full = np.abs(spectrogram).astype(np.complex) * angles
    inverse = librosa.istft(full, hop_length=hop_length, window=window)

    return inverse 
开发者ID:RayanWang,项目名称:Speech_emotion_recognition_BLSTM,代码行数:23,代码来源:audio.py

示例12: griffin_lim

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import istft [as 别名]
def griffin_lim(magnitudes, n_iters=50, n_fft=1024):
  """
  Griffin-Lim algorithm to convert magnitude spectrograms to audio signals
  """

  phase = np.exp(2j * np.pi * np.random.rand(*magnitudes.shape))
  complex_spec = magnitudes * phase
  signal = librosa.istft(complex_spec)
  if not np.isfinite(signal).all():
    print("WARNING: audio was not finite, skipping audio saving")
    return np.array([0])

  for _ in range(n_iters):
    _, phase = librosa.magphase(librosa.stft(signal, n_fft=n_fft))
    complex_spec = magnitudes * phase
    signal = librosa.istft(complex_spec)
  return signal 
开发者ID:NVIDIA,项目名称:OpenSeq2Seq,代码行数:19,代码来源:text2speech.py

示例13: spectrogramToAudioFile

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import istft [as 别名]
def spectrogramToAudioFile(magnitude, fftWindowSize, hopSize, phaseIterations=10, phase=None, length=None):
    '''
    Computes an audio signal from the given magnitude spectrogram, and optionally an initial phase.
    Griffin-Lim is executed to recover/refine the given the phase from the magnitude spectrogram.
    :param magnitude: Magnitudes to be converted to audio
    :param fftWindowSize: Size of FFT window used to create magnitudes
    :param hopSize: Hop size in frames used to create magnitudes
    :param phaseIterations: Number of Griffin-Lim iterations to recover phase
    :param phase: If given, starts ISTFT with this particular phase matrix
    :param length: If given, audio signal is clipped/padded to this number of frames
    :return:
    '''
    if phase is not None:
        if phaseIterations > 0:
            # Refine audio given initial phase with a number of iterations
            return reconPhase(magnitude, fftWindowSize, hopSize, phaseIterations, phase, length)
        # reconstructing the new complex matrix
        stftMatrix = magnitude * np.exp(phase * 1j) # magnitude * e^(j*phase)
        audio = librosa.istft(stftMatrix, hop_length=hopSize, length=length)
    else:
        audio = reconPhase(magnitude, fftWindowSize, hopSize, phaseIterations)
    return audio 
开发者ID:f90,项目名称:Wave-U-Net,代码行数:24,代码来源:Utils.py

示例14: invert_spectrogram

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import istft [as 别名]
def invert_spectrogram(spectrogram):
    '''Applies inverse fft.
    Args:
      spectrogram: [1+n_fft//2, t]
    '''
    return librosa.istft(spectrogram, hp.hop_length, win_length=hp.win_length, window="hann") 
开发者ID:Kyubyong,项目名称:dc_tts,代码行数:8,代码来源:utils.py

示例15: _istft

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import istft [as 别名]
def _istft(y):
    return librosa.istft(y, hop_length=get_hop_size())


# Conversions: 
开发者ID:candlewill,项目名称:Griffin_lim,代码行数:7,代码来源:audio.py


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