當前位置: 首頁>>代碼示例>>Python>>正文


Python hparams.sample_rate方法代碼示例

本文整理匯總了Python中hparams.hparams.sample_rate方法的典型用法代碼示例。如果您正苦於以下問題:Python hparams.sample_rate方法的具體用法?Python hparams.sample_rate怎麽用?Python hparams.sample_rate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在hparams.hparams的用法示例。


在下文中一共展示了hparams.sample_rate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from hparams import hparams [as 別名]
# 或者: from hparams.hparams import sample_rate [as 別名]
def main():
    data_foler = "data"
    wavs = [os.path.join(data_foler, file[:-4]) for file in os.listdir(data_foler) if file.endswith(".wav")]
    outputs_lws = [file + ".lws.gen.wav" for file in wavs]
    wavs = [audio.load_wav(wav_path + ".wav", hparams.sample_rate) for wav_path in wavs]

    lws_processor = lws.lws(512, 128, mode="speech")  # 512: window length; 128: window shift
    i = 0
    for x in wavs:
        X = lws_processor.stft(x)  # where x is a single-channel waveform
        X0 = np.abs(X)  # Magnitude spectrogram
        print('{:6}: {:5.2f} dB'.format('Abs(X)', lws_processor.get_consistency(X0)))
        X1 = lws_processor.run_lws(
            X0)  # reconstruction from magnitude (in general, one can reconstruct from an initial complex spectrogram)
        print(X1.shape)
        print('{:6}: {:5.2f} dB'.format('LWS', lws_processor.get_consistency(X1)))
        print(X1.shape)
        wav = lws_processor.istft(X1).astype(np.float32)

        audio.save_wav(wav, outputs_lws[i])
        i += 1 
開發者ID:candlewill,項目名稱:Griffin_lim,代碼行數:23,代碼來源:LWS.py

示例2: _process_utterance

# 需要導入模塊: from hparams import hparams [as 別名]
# 或者: from hparams.hparams import sample_rate [as 別名]
def _process_utterance(out_dir, index, wav_path, labels_path, text):
  # Load the wav file and trim silence from the ends:
  wav = audio.load_wav(wav_path)
  start_offset, end_offset = _parse_labels(labels_path)
  start = int(start_offset * hparams.sample_rate)
  end = int(end_offset * hparams.sample_rate) if end_offset is not None else -1
  wav = wav[start:end]
  max_samples = _max_out_length * hparams.frame_shift_ms / 1000 * hparams.sample_rate
  if len(wav) > max_samples:
    return None
  spectrogram = audio.spectrogram(wav).astype(np.float32)
  n_frames = spectrogram.shape[1]
  mel_spectrogram = audio.melspectrogram(wav).astype(np.float32)
  spectrogram_filename = 'blizzard-spec-%05d.npy' % index
  mel_filename = 'blizzard-mel-%05d.npy' % index
  np.save(os.path.join(out_dir, spectrogram_filename), spectrogram.T, allow_pickle=False)
  np.save(os.path.join(out_dir, mel_filename), mel_spectrogram.T, allow_pickle=False)
  return (spectrogram_filename, mel_filename, n_frames, text) 
開發者ID:yanggeng1995,項目名稱:vae_tacotron,代碼行數:20,代碼來源:blizzard.py

示例3: save_and_plot_fn

# 需要導入模塊: from hparams import hparams [as 別名]
# 或者: from hparams.hparams import sample_rate [as 別名]
def save_and_plot_fn(args, log_dir, step, loss, prefix):
    idx, (seq, spec, align) = args

    audio_path = os.path.join(log_dir, '{}-step-{:09d}-audio{:03d}.wav'.format(prefix, step, idx))
    align_path = os.path.join(log_dir, '{}-step-{:09d}-align{:03d}.png'.format(prefix, step, idx))

    waveform = inv_spectrogram(spec.T,hparams)
    save_wav(waveform, audio_path,hparams.sample_rate)

    info_text = 'step={:d}, loss={:.5f}'.format(step, loss)
    if 'korean_cleaners' in [x.strip() for x in hparams.cleaners.split(',')]:
        log('Training korean : Use jamo')
        plot.plot_alignment( align, align_path, info=info_text, text=sequence_to_text(seq,skip_eos_and_pad=True, combine_jamo=True), isKorean=True)
    else:
        log('Training non-korean : X use jamo')
        plot.plot_alignment(align, align_path, info=info_text,text=sequence_to_text(seq,skip_eos_and_pad=True, combine_jamo=False), isKorean=False) 
開發者ID:hccho2,項目名稱:Tacotron-Wavenet-Vocoder-Korean,代碼行數:18,代碼來源:train_tacotron.py

示例4: create_seed

# 需要導入模塊: from hparams import hparams [as 別名]
# 或者: from hparams.hparams import sample_rate [as 別名]
def create_seed(filename,sample_rate,quantization_channels,window_size,scalar_input):
    # seed의 앞부분만 사용한다.
    seed_audio, _ = librosa.load(filename, sr=sample_rate, mono=True)
    seed_audio = audio.trim_silence(seed_audio, hparams)
    if scalar_input:
        if len(seed_audio) < window_size:
            return seed_audio
        else: return seed_audio[:window_size]
    else:
        quantized = mu_law_encode(seed_audio, quantization_channels)
    
    
        # 짧으면 짧은 대로 return하는데, padding이라도 해야되지 않나???
        cut_index = tf.cond(tf.size(quantized) < tf.constant(window_size), lambda: tf.size(quantized), lambda: tf.constant(window_size))
    
        return quantized[:cut_index] 
開發者ID:hccho2,項目名稱:Tacotron-Wavenet-Vocoder-Korean,代碼行數:18,代碼來源:generate.py

示例5: evaluate_model

# 需要導入模塊: from hparams import hparams [as 別名]
# 或者: from hparams.hparams import sample_rate [as 別名]
def evaluate_model(model, data_loader, checkpoint_dir, limit_eval_to=5):
    """evaluate model and save generated wav and plot

    """
    test_path = data_loader.dataset.test_path
    test_files = os.listdir(test_path)
    counter = 0
    output_dir = os.path.join(checkpoint_dir,'eval')
    for f in test_files:
        if f[-7:] == "mel.npy":
            mel = np.load(os.path.join(test_path,f))
            wav = model.generate(mel)
            # save wav
            wav_path = os.path.join(output_dir,"checkpoint_step{:09d}_wav_{}.wav".format(global_step,counter))
            librosa.output.write_wav(wav_path, wav, sr=hp.sample_rate)
            # save wav plot
            fig_path = os.path.join(output_dir,"checkpoint_step{:09d}_wav_{}.png".format(global_step,counter))
            fig = plt.plot(wav.reshape(-1))
            plt.savefig(fig_path)
            # clear fig to drawing to the same plot
            plt.clf()
            counter += 1
        # stop evaluation early via limit_eval_to
        if counter >= limit_eval_to:
            break 
開發者ID:G-Wang,項目名稱:WaveRNN-Pytorch,代碼行數:27,代碼來源:train.py

示例6: mel_synthesis

# 需要導入模塊: from hparams import hparams [as 別名]
# 或者: from hparams.hparams import sample_rate [as 別名]
def mel_synthesis(out_dir='wav_griffi_syn',in_dir='mel'):
    os.makedirs(out_dir, exist_ok=True)

    #mel_file = os.path.join(mel_folder, mel_file)
    mel_filenames=[x.split('.')[0] for x in os.listdir(in_dir)]
    start_time=time.time()
    for mel_file in mel_filenames:
        try:
            print('process {}'.format(mel_file))
            mel_file_path = os.path.join('training_data/mels', 'mel-{}.wav.npy'.format(mel_file))
            mel_spectro = np.load(mel_file_path)
            wav = inv_mel_spectrogram(mel_spectro.T, hparams)
            # save the wav under test_<folder>_<file>
            save_wav(wav, os.path.join(out_dir, 'test_mel_{}.wav'.format(
                mel_file.replace('/', '_').replace('\\', '_').replace('.npy', ''))),
                     sr=hparams.sample_rate)
        except:
            print('{} error'.format(mel_file))

    print('griffin-lim :{}'.format(time.time()-start_time)) 
開發者ID:cnlinxi,項目名稱:style-token_tacotron2,代碼行數:22,代碼來源:synthesis_mel.py

示例7: save_wav

# 需要導入模塊: from hparams import hparams [as 別名]
# 或者: from hparams.hparams import sample_rate [as 別名]
def save_wav(wav, path):
    wav *= 32767 / max(0.01, np.max(np.abs(wav)))
    wavfile.write(path, hparams.sample_rate, wav.astype(np.int16)) 
開發者ID:candlewill,項目名稱:Griffin_lim,代碼行數:5,代碼來源:audio.py

示例8: _build_mel_basis

# 需要導入模塊: from hparams import hparams [as 別名]
# 或者: from hparams.hparams import sample_rate [as 別名]
def _build_mel_basis():
    n_fft = (hparams.num_freq - 1) * 2
    return librosa.filters.mel(hparams.sample_rate, n_fft, n_mels=hparams.num_mels) 
開發者ID:candlewill,項目名稱:Griffin_lim,代碼行數:5,代碼來源:audio.py

示例9: get_hop_size

# 需要導入模塊: from hparams import hparams [as 別名]
# 或者: from hparams.hparams import sample_rate [as 別名]
def get_hop_size():
    hop_size = hparams.hop_size
    if hop_size is None:
        assert hparams.frame_shift_ms is not None
        hop_size = int(hparams.frame_shift_ms / 1000 * hparams.sample_rate)
    return hop_size 
開發者ID:candlewill,項目名稱:Griffin_lim,代碼行數:8,代碼來源:audio.py

示例10: spectrogram2wav

# 需要導入模塊: from hparams import hparams [as 別名]
# 或者: from hparams.hparams import sample_rate [as 別名]
def spectrogram2wav(spectrogram, n_iter=hparams.griffin_lim_iters, n_fft=(hparams.num_freq - 1) * 2,
                    win_length=int(hparams.frame_length_ms / 1000 * hparams.sample_rate),
                    hop_length=int(hparams.frame_shift_ms / 1000 * hparams.sample_rate)):
    '''Converts spectrogram into a waveform using Griffin-lim's raw.
    '''

    def invert_spectrogram(spectrogram):
        '''
        spectrogram: [t, f]
        '''
        spectrogram = tf.expand_dims(spectrogram, 0)
        inversed = tf.contrib.signal.inverse_stft(spectrogram, win_length, hop_length, n_fft)
        squeezed = tf.squeeze(inversed, 0)
        return squeezed

    spectrogram = tf.transpose(spectrogram)

    spectrogram = tf.cast(spectrogram, dtype=tf.complex64)  # [t, f]
    X_best = tf.identity(spectrogram)
    for i in range(n_iter):
        X_t = invert_spectrogram(X_best)
        est = tf.contrib.signal.stft(X_t, win_length, hop_length, n_fft, pad_end=False)  # (1, T, n_fft/2+1)
        phase = est / tf.cast(tf.maximum(1e-8, tf.abs(est)), tf.complex64)  # [t, f]
        X_best = spectrogram * phase  # [t, t]
    X_t = invert_spectrogram(X_best)
    y = tf.real(X_t)

    return y 
開發者ID:candlewill,項目名稱:Griffin_lim,代碼行數:30,代碼來源:griffin_lim.py

示例11: load_wav

# 需要導入模塊: from hparams import hparams [as 別名]
# 或者: from hparams.hparams import sample_rate [as 別名]
def load_wav(path):
  return librosa.core.load(path, sr=hparams.sample_rate)[0] 
開發者ID:yanggeng1995,項目名稱:vae_tacotron,代碼行數:4,代碼來源:audio.py

示例12: save_wav

# 需要導入模塊: from hparams import hparams [as 別名]
# 或者: from hparams.hparams import sample_rate [as 別名]
def save_wav(wav, path):
  wav *= 32767 / max(0.01, np.max(np.abs(wav)))
  scipy.io.wavfile.write(path, hparams.sample_rate, wav.astype(np.int16)) 
開發者ID:yanggeng1995,項目名稱:vae_tacotron,代碼行數:5,代碼來源:audio.py

示例13: find_endpoint

# 需要導入模塊: from hparams import hparams [as 別名]
# 或者: from hparams.hparams import sample_rate [as 別名]
def find_endpoint(wav, threshold_db=-40, min_silence_sec=0.8):
  window_length = int(hparams.sample_rate * min_silence_sec)
  hop_length = int(window_length / 4)
  threshold = _db_to_amp(threshold_db)
  for x in range(hop_length, len(wav) - window_length, hop_length):
    if np.max(wav[x:x+window_length]) < threshold:
      return x + hop_length
  return len(wav) 
開發者ID:yanggeng1995,項目名稱:vae_tacotron,代碼行數:10,代碼來源:audio.py

示例14: _stft_parameters

# 需要導入模塊: from hparams import hparams [as 別名]
# 或者: from hparams.hparams import sample_rate [as 別名]
def _stft_parameters():
  n_fft = (hparams.num_freq - 1) * 2
  hop_length = int(hparams.frame_shift_ms / 1000 * hparams.sample_rate)
  win_length = int(hparams.frame_length_ms / 1000 * hparams.sample_rate)
  return n_fft, hop_length, win_length


# Conversions: 
開發者ID:yanggeng1995,項目名稱:vae_tacotron,代碼行數:10,代碼來源:audio.py

示例15: _build_mel_basis

# 需要導入模塊: from hparams import hparams [as 別名]
# 或者: from hparams.hparams import sample_rate [as 別名]
def _build_mel_basis():
  n_fft = (hparams.num_freq - 1) * 2
  return librosa.filters.mel(hparams.sample_rate, n_fft, n_mels=hparams.num_mels) 
開發者ID:yanggeng1995,項目名稱:vae_tacotron,代碼行數:5,代碼來源:audio.py


注:本文中的hparams.hparams.sample_rate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。