mirror of
https://github.com/wassname/TTS.git
synced 2026-08-30 11:16:07 +08:00
450 KiB
450 KiB
In [5]:
%matplotlib inline
from tts.utils.audio import AudioProcessor
from tts.tts.utils.visual import plot_spectrogram
from tts.utils.io import load_config
import glob In [20]:
config_path = "/home/erogol/Projects/TTS/tts/tts/config_thorsten_de.json"
data_path = "/home/erogol/Data/thorsten-german/"
file_paths = glob.glob(data_path + "/**/*.wav", recursive=True)
CONFIG = load_config(config_path)In [21]:
# audio={
# 'audio_processor': 'audio',
# 'num_mels': 80, # In general, you don'tneed to change it
# 'fft_size': 1024, # In general, you don'tneed to change it
# 'sample_rate': 22050, # It depends to the sample rate of the dataset.
# 'hop_length': 256, # In general, you don'tneed to change it
# 'win_length': 1024, # In general, you don'tneed to change it
# 'preemphasis': 0.98, # In general, 0 gives better voice recovery but makes traning harder. If your model does not train, try 0.97 - 0.99.
# 'min_level_db': -100,
# 'ref_level_db': 20, # It is the base DB, higher until you remove the background noise in the spectrogram and then lower until you hear a better speech below.
# 'power': 1.5, # Change this value and listen the synthesized voice. 1.2 - 1.5 are some resonable values.
# 'griffin_lim_iters': 60, # It does not give any imporvement for values > 60
# 'signal_norm': True, # This is more about your model. It does not give any change for the synthsis performance.
# 'symmetric_norm': False, # Same as above
# 'max_norm': 1, # Same as above
# 'clip_norm': True, # Same as above
# 'mel_fmin': 0.0, # You can play with this and check mel-spectrogram based voice synthesis below.
# 'mel_fmax': 8000.0, # You can play with this and check mel-spectrogram based voice synthesis below.
# 'do_trim_silence': True} # If you dataset has some silience at the beginning or end, this trims it. Check the AP.load_wav() below,if it causes any difference for the loaded audio file.
AP = AudioProcessor(**CONFIG.audio);> Setting up Audio Processor... | > sample_rate:22050 | > num_mels:80 | > min_level_db:-100 | > frame_shift_ms:None | > frame_length_ms:None | > ref_level_db:20 | > fft_size:1024 | > power:1.5 | > preemphasis:0.0 | > griffin_lim_iters:60 | > signal_norm:True | > symmetric_norm:True | > mel_fmin:0 | > mel_fmax:8000.0 | > spec_gain:1.0 | > stft_pad_mode:reflect | > max_norm:4.0 | > clip_norm:True | > do_trim_silence:True | > trim_db:60 | > do_sound_norm:True | > stats_path:None | > hop_length:256 | > win_length:1024
In [22]:
wav = AP.load_wav(file_paths[10])
ipd.Audio(data=wav, rate=AP.sample_rate) Out [22]:
In [28]:
AP.power = 1.0In [29]:
mel = AP.melspectrogram(wav)
print("Max:", mel.max())
print("Min:", mel.min())
print("Mean:", mel.mean())
plot_spectrogram(mel.T, AP);
wav_gen = AP.inv_melspectrogram(mel)
ipd.Audio(wav_gen, rate=AP.sample_rate)Out [29]:
Max: 2.4340844 Min: 2.0181823 Mean: 2.2137265
In [18]:
spec = AP.spectrogram(wav)
print("Max:", spec.max())
print("Min:", spec.min())
print("Mean:", spec.mean())
plot_spectrogram(spec.T, AP);
wav_gen = AP.inv_spectrogram(spec)
ipd.Audio(wav_gen, rate=AP.sample_rate)[0;31m---------------------------------------------------------------------------[0m [0;31mRuntimeError[0m Traceback (most recent call last) [0;32m<ipython-input-18-91e8914b5c6a>[0m in [0;36m<module>[0;34m[0m [0;32m----> 1[0;31m [0mspec[0m [0;34m=[0m [0mAP[0m[0;34m.[0m[0mspectrogram[0m[0;34m([0m[0mwav[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m [0m[1;32m 2[0m [0mprint[0m[0;34m([0m[0;34m"Max:"[0m[0;34m,[0m [0mspec[0m[0;34m.[0m[0mmax[0m[0;34m([0m[0;34m)[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m [1;32m 3[0m [0mprint[0m[0;34m([0m[0;34m"Min:"[0m[0;34m,[0m [0mspec[0m[0;34m.[0m[0mmin[0m[0;34m([0m[0;34m)[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m [1;32m 4[0m [0mprint[0m[0;34m([0m[0;34m"Mean:"[0m[0;34m,[0m [0mspec[0m[0;34m.[0m[0mmean[0m[0;34m([0m[0;34m)[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m [1;32m 5[0m [0mplot_spectrogram[0m[0;34m([0m[0mspec[0m[0;34m.[0m[0mT[0m[0;34m,[0m [0mAP[0m[0;34m)[0m[0;34m;[0m[0;34m[0m[0;34m[0m[0m [0;32m~/Projects/TTS/tts/utils/audio.py[0m in [0;36mspectrogram[0;34m(self, y)[0m [1;32m 218[0m [0mD[0m [0;34m=[0m [0mself[0m[0;34m.[0m[0m_stft[0m[0;34m([0m[0my[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m [1;32m 219[0m [0mS[0m [0;34m=[0m [0mself[0m[0;34m.[0m[0m_amp_to_db[0m[0;34m([0m[0mnp[0m[0;34m.[0m[0mabs[0m[0;34m([0m[0mD[0m[0;34m)[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m [0;32m--> 220[0;31m [0;32mreturn[0m [0mself[0m[0;34m.[0m[0mnormalize[0m[0;34m([0m[0mS[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m [0m[1;32m 221[0m [0;34m[0m[0m [1;32m 222[0m [0;32mdef[0m [0mmelspectrogram[0m[0;34m([0m[0mself[0m[0;34m,[0m [0my[0m[0;34m)[0m[0;34m:[0m[0;34m[0m[0;34m[0m[0m [0;32m~/Projects/TTS/tts/utils/audio.py[0m in [0;36mnormalize[0;34m(self, S)[0m [1;32m 117[0m [0;32mreturn[0m [0mself[0m[0;34m.[0m[0mlinear_scaler[0m[0;34m.[0m[0mtransform[0m[0;34m([0m[0mS[0m[0;34m.[0m[0mT[0m[0;34m)[0m[0;34m.[0m[0mT[0m[0;34m[0m[0;34m[0m[0m [1;32m 118[0m [0;32melse[0m[0;34m:[0m[0;34m[0m[0;34m[0m[0m [0;32m--> 119[0;31m [0;32mraise[0m [0mRuntimeError[0m[0;34m([0m[0;34m' [!] Mean-Var stats does not match the given feature dimensions.'[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m [0m[1;32m 120[0m [0;31m# range normalization[0m[0;34m[0m[0;34m[0m[0;34m[0m[0m [1;32m 121[0m [0mS[0m [0;34m-=[0m [0mself[0m[0;34m.[0m[0mref_level_db[0m [0;31m# discard certain range of DB assuming it is air noise[0m[0;34m[0m[0;34m[0m[0m [0;31mRuntimeError[0m: [!] Mean-Var stats does not match the given feature dimensions.
In [ ]:
audio={
'audio_processor': 'audio',
'num_mels': 80, # In general, you don'tneed to change it
'num_freq': 1025, # In general, you don'tneed to change it
'sample_rate': 22050, # It depends to the sample rate of the dataset.
'frame_length_ms': 50, # In general, you don'tneed to change it
'frame_shift_ms': 12.5, # In general, you don'tneed to change it
'preemphasis': 0.98, # In general, 0 gives better voice recovery but makes traning harder. If your model does not train, try 0.97 - 0.99.
'min_level_db': -100,
'ref_level_db': 20, # It is the base DB, higher until you remove the background noise in the spectrogram and then lower until you hear a better speech below.
'power': 1.5, # Change this value and listen the synthesized voice. 1.2 - 1.5 are some resonable values.
'griffin_lim_iters': 60, # It does not give any imporvement for values > 60
'signal_norm': True, # This is more about your model. It does not give any change for the synthsis performance.
'symmetric_norm': False, # Same as above
'max_norm': 1, # Same as above
'clip_norm': True, # Same as above
'mel_fmin': 0.0, # You can play with this and check mel-spectrogram based voice synthesis below.
'mel_fmax': 8000.0, # You can play with this and check mel-spectrogram based voice synthesis below.
'do_trim_silence': True} # If you dataset has some silience at the beginning or end, this trims it. Check the AP.load_wav() below,if it causes any difference for the loaded audio file.
AP = AudioProcessor(**audio);In [ ]:
from librosa import display
from matplotlib import pylab as plt
import IPython
plt.rcParams['figure.figsize'] = (20.0, 16.0)
def compare_values(attribute, values, file):
"""
attributes (str): the names of the attribute you like to test.
values (list): list of values to compare.
file (str): file name to perform the tests.
"""
wavs = []
for idx, val in enumerate(values):
set_val_cmd = "AP.{}={}".format(attribute, val)
exec(set_val_cmd)
wav = AP.load_wav(file)
spec = AP.spectrogram(wav)
spec_norm = AP.denormalize(spec.T)
plt.subplot(len(values), 2, 2*idx + 1)
plt.imshow(spec_norm.T, aspect="auto", origin="lower")
# plt.colorbar()
plt.tight_layout()
wav_gen = AP.inv_spectrogram(spec)
wavs.append(wav_gen)
plt.subplot(len(values), 2, 2*idx + 2)
display.waveplot(wav, alpha=0.5)
display.waveplot(wav_gen, alpha=0.25)
plt.title("{}={}".format(attribute, val))
plt.tight_layout()
wav = AP.load_wav(file)
print(" > Ground-truth")
IPython.display.display(IPython.display.Audio(wav, rate=AP.sample_rate))
for idx, wav_gen in enumerate(wavs):
val = values[idx]
print(" > {} = {}".format(attribute, val))
IPython.display.display(IPython.display.Audio(wav_gen, rate=AP.sample_rate))In [ ]:
compare_values("preemphasis", [0, 0.5, 0.97, 0.98, 0.99], file_paths[10])In [ ]:
compare_values("ref_level_db", [10, 15, 20, 25, 30, 35, 40], file_paths[10])