This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.rb
199 lines (154 loc) · 5.66 KB
/
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
require 'optparse'
require 'ostruct'
require './htk'
require './string_helper'
require './txt2speech'
class Parser
def self.parse(args)
# We set default values here.
htkrunner = HTKSupport.new
speaker = TXT2Speech.new
options = OpenStruct.new
options.library = []
options.inplace = false
options.encoding = "utf8"
options.transfer_type = :auto
options.verbose = false
options.flag = false
opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: main.rb [options]"
opts.on("-path", "--path=FULL_PATH_FILE", "Nhap dia chi day du file can thuc thi") do |v|
options.file_path = v
end
opts.on("-topath", "--topath=OUTPUT_TO_PATH", "Nhap dia chi folder can xuat file output") do |v|
options.output_file_path = v
end
opts.on("--mkdir", "Tao prerequisite folder de phong HTK bao loi") do
htkrunner.make_dirs
end
opts.on("-d", "--dict", "Tao dict tu filepath vocabulary") do
options.make_dict = true
end
opts.on("-im", "--gen-initial-monophone", "Tao monophone tu dict, phai co san dict tu truoc") do
htkrunner.get_monophone_from_dict
end
opts.on("--monophones", "Tao monophone0, monophone1 tu prompt") do
htkrunner.generate_monophones
end
opts.on("-p", "--prompt", "Tao prompt file") do
options.do_create_prompt = true
end
opts.on("-t text", "--text=TEXTTOSAY", "Tieng noi can thu") do |t|
options.text = t
end
opts.on("--mlf", "Tao label file cho prompt file") do
htkrunner.make_master_label_file
end
opts.on("--labelfiles", "Tao label file cho training wave") do
htkrunner.make_training_label_file
end
opts.on("--correct-wintri", String,
"Replace */MSaaaaabb_1100.lab to /User/abc/.../MSaaaaabb_1100.lab" ) do |opt|
htkrunner.correct_wintri
end
opts.on("-a", "--action=TRAIN_OR_TEST_OR_LISTWAVMFC", "Xac dinh train hoac test hoac tao listwavmfc khi tao file scp") do |t|
options.action = t
end
opts.on("-s", "--MfccFiles", "Khoi tao cac file scp") do
options.do_create_scp_files = true
end
opts.on("-g", "--grammar", "Tao gram monoword") do
htkrunner.make_grammar_file
end
opts.on("-w", "--wlist", "Tao word list") do
htkrunner.make_word_list
end
opts.on("-ma", "--macro", "Tao macro tu vFloor cua folder") do
options.do_create_macro = true
end
opts.on("--sp2hmmdef=arg1[,...]", "Them sp vao hmmdef tu source_path (args1) sang dest_path (args2)") do |input|
source = input.split(",")[0]
dest = input.split(",")[1]
htkrunner.add_short_pause_to_hmmdef(source, dest)
end
opts.on("--f", "Flag") do
options.flag = true
end
opts.on("--level=LEVEL", "Kieu huan luyen 2-word | 3-sentence") do |level|
options.level = level
end
opts.on("--make-mktri-hed", "Tao mktri.hed de nhai mo hinh monophone thanh triphone") do
htkrunner.make_mktri_hed
end
opts.on("--make-tree-hed=THRESHOLD", Integer, "Khoi tao tree-hed theo monophones") do |threshold|
htkrunner.make_tree_hed(threshold)
end
opts.on("--clean-full-list", "Don dep triphones khong su dung trong phones/fulllist") do
htkrunner.clean_fulllist
end
opts.on("--clean-scp-files", "Xoa scp_files/* ") do
htkrunner.clean_scp_files
end
opts.on("--what-to-train=NUMBER", Integer, "Liet ke tu xuat hien nhieu hon 2 lan trong train_wav va de nghi") do |number|
options.recommend_training = true
options.number_to_train = number
end
opts.on("--make-testwords-mlf", "Tao file testwords.mlf chua toan bo noi dung nhu words.mlf nhung cua test") do
htkrunner.make_testwords
end
opts.on("-c", "--config", "Tao config") do
options.configuration = true
end
opts.on("-gl", "--genlab") do
options.genlab = true
end
opts.on("--cc", "Convert crawl file format text sang format sang") do
options.convert_crawl = true
end
opts.on("-h", "--help", "Prints this help") do
puts opts
exit
end
opts.on("--speak","Doc gio he thong theo format tieng Viet") do
puts speaker.action
end
end
opt_parser.parse!(args)
return options
end
end
options = Parser.parse(ARGV)
runner = HTKSupport.new
if options.make_dict
runner.get_dict(options.flag)
end
if options.do_create_prompt
runner.make_prompt_file(options.file_path.to_s, options.text.to_s)
end
if options.do_create_scp_files
raise "Vui long nhap --path hoac --act neu con thieu" if (options.file_path.nil? ||
options.action.nil?)
runner.make_mfcc_files(options.file_path.to_s, options.action.to_s)
end
if options.do_create_macro
raise "Vui long nhap --path" if options.file_path.nil?
runner.make_macro(options.file_path.to_s)
runner.make_hmmdef(options.file_path.to_s)
end
if options.recommend_training
runner.recommend_training(options.number_to_train, options.flag)
end
if options.configuration
raise "Vui long nhap --level= neu con thieu" if options.level.nil?
runner.config(options.level.to_i)
end
if options.genlab
raise "Vui long nhap --path" if options.file_path.nil?
raise "Vui long nhap --topath" if options.output_file_path.nil?
runner.parse_prompts(options.file_path.to_s, options.output_file_path.to_s)
end
if options.convert_crawl
raise "Vui long nhap --path" if options.file_path.nil?
raise "Vui long nhap --topath" if options.output_file_path.nil?
runner.format_crawled_data(options.file_path.to_s, options.output_file_path.to_s)
end