Mellotron代码记录
TextMelLoader
用于load【audio/text/speaker ids】【text converts to one hot?】以及【计算audio files中的mel-spectrograms / f0s】
用以获得train/valid set
english_cleaners:
-> convert_to_ascii
-> lowercase
-> expand_numbers [normalize_numbers {货币符号/小数点/第几缩写}]
-> expand_abbreviations [缩写]
-> collapse_whitespace
TextMelLoader中get_data
(self, audiopath_and_text): 通过wav path与text对应的情况进行下一步处理
* text = self.get_text(text) -> 得到一个关于text的int tensor
text_to_sequence(text, cleaner_names, 发音dict) 【作用是converts a string of text to a sequence of IDs corresponding to the symbols in the text】
- 按概率将单词转换为单词读音【_arpabet_to_sequence(读音组合)】
* mel, f0 = self.get_mel_and_f0(audiopath) -> 提取mel spec和基频
audio, sampling_rate = load_wav_to_torch(filepath)
# from scipy.io.wavfile import read
read(filepath) open a wav file 返回sample rate / data [numpy array]
audio_norm = audio / self.max_wav_value
audio_norm = audio_norm.unsqueeze(0)
melspec = self.stft.mel_spectrogram(audio_norm)
melspec = torch.squeeze(melspec, 0)
f0 = self.get_f0(audio.cpu().numpy(), self.sampling_rate, self.filter_length, self.hop_length, self.f0_min, self.f0_max, self.harm_thresh)
f0 = torch.from_numpy(f0)[None]
f0 = f0[:, :melspec.size(1)]
* speaker_id = self.get_speaker_id(speaker) -> 返回一个说话人的int tensor
发音字典
叮叮叮
像CMU的中文汉语发音字典??
发音字典(lexicon)包含了从单词(words)到音素(phones)之间的映射,作用是用来连接声学模型和语言模型的。
拼音-音素的映射
首先需要确定的是拼音到音素的转换规则/映射关系。
可以有不同的映射关系,不同的映射关系会产生不同的识别效果。
如汉字“一”,
“yi1”可以对应 “ii i1”,[清华语音识别使用的规则]
也可以对应 “y i1”
中文词-拼音的映射
需要列出尽可能多的中文词及其对应的拼音,有多音字的可列出其不同组合。
g2p工具实现
通过以上两个步骤即可实现中文词-音素的转换,也就是G2P(Grapheme-to-Phoneme Conversion)。
收集中文词
发音字典需要覆盖尽可能多的『词-音素』对。
将分词后的文本语料统计各单词及其词频,去掉低频词与过长的词,得到中文词表。
生成词典
将中文词表作为输入,通过g2p工具即可得到『词-音素』的映射,也就是发音词典。
继续继续....