Created
April 3, 2021 18:22
-
-
Save Hiroshiba/a49e9c8e8251ddb6cb0dfc1615fc9872 to your computer and use it in GitHub Desktop.
きりたん歌唱データベースにjuliusの音素アライメントを適用させるコードメモ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
from pathlib import Path | |
lab = Path("01.lab.txt").read_text() | |
i = 0 | |
out_labs = [] | |
for l in lab.splitlines(): | |
a, b, c = l.split() | |
if c == "pau": | |
if len(out_labs) == 0: | |
continue | |
start = float(out_labs[0].split()[0]) | |
end = float(b) | |
subprocess.run( | |
f"sox w1.wav split-{i}.wav trim {start - 0.1} {end - start}", shell=True | |
) | |
for ii in range(len(out_labs)): | |
s, e, p = out_labs[ii].split() | |
out_labs[ii] = f"0 0 {p}" | |
Path(f"split-{i}.lab").write_text("\n".join(out_labs)) | |
out_labs = [] | |
i += 1 | |
else: | |
out_labs.append(l) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sox 01.wav -r 16k -c 1 -b 16 w1.wav | |
for i in {0..8}; do | |
cat split-$i.lab |\ | |
awk '{print $NF}' |\ | |
sed -r 's/pau/sp/g' |\ | |
sed -r 's/br/sp/g' |\ | |
sed -r 's/cl/q/g' |\ | |
tr '\n' ' ' \ | |
> /tmp/yomi.txt | |
julius4seg_segment \ | |
split-$i.wav \ | |
/tmp/yomi.txt \ | |
output-split-$i.lab \ | |
--input_yomi_type phoneme \ | |
--hmm_model dictation-kit/model/dnn/binhmm.SID \ | |
--only_2nd_path \ | |
--model_type dnn \ | |
--options=' | |
-hlist dictation-kit/model/dnn/logicalTri.bin | |
-dnnconf dictation-kit/julius.dnnconf | |
' | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pathlib import Path | |
base_lab = Path("01.lab.txt").read_text() | |
pau_ends = [] | |
for l in base_lab.splitlines(): | |
a, b, c = l.split() | |
if c == "pau": | |
pau_ends += [float(b)] | |
pau_ends = pau_ends[:-1] | |
texts = [] | |
for i, et in enumerate(pau_ends): | |
for s in Path(f"output-split-{i}.lab").read_text().splitlines(): | |
s, e, p = s.split() | |
s = str(float(s) + et - 0.1) | |
e = str(float(e) + et - 0.1) | |
texts += [f"{s}\t{e}\t{p}"] | |
Path("output-merged.lab").write_text("\n".join(texts)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment