|
|
|
@ -1,7 +1,14 @@
@@ -1,7 +1,14 @@
|
|
|
|
|
## this script should be used only by Aki Kunikoshi. |
|
|
|
|
|
|
|
|
|
import numpy as np |
|
|
|
|
import argparse |
|
|
|
|
import json |
|
|
|
|
|
|
|
|
|
from novoapi.backend import session |
|
|
|
|
|
|
|
|
|
import defaultfiles as default |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_phonset(): |
|
|
|
|
translation_key_ipa2novo70 = dict() |
|
|
|
|
translation_key_novo702ipa = dict() |
|
|
|
@ -112,7 +119,7 @@ def make_grammar(word, pronunciation_ipa):
@@ -112,7 +119,7 @@ def make_grammar(word, pronunciation_ipa):
|
|
|
|
|
|
|
|
|
|
grammer_data_elements0_pronunciation = [] |
|
|
|
|
for id, ipa in enumerate(pronunciation_ipa): |
|
|
|
|
novo70 = novoapi_functions.ipa2novo70(ipa) |
|
|
|
|
novo70 = ipa2novo70(ipa) |
|
|
|
|
grammer_data_elements0_pronunciation.append({ |
|
|
|
|
"phones": novo70.split(), |
|
|
|
|
"id": id |
|
|
|
@ -135,4 +142,32 @@ def make_grammar(word, pronunciation_ipa):
@@ -135,4 +142,32 @@ def make_grammar(word, pronunciation_ipa):
|
|
|
|
|
"phoneset": "novo70" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return grammar |
|
|
|
|
return grammar |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def forced_alignment(wav_file, word, pronunciation_ipa): |
|
|
|
|
### IMPORTANT ### |
|
|
|
|
# because of this function, this script should not be uploaded / shared. |
|
|
|
|
|
|
|
|
|
# username / password cannot be passed as artuments... |
|
|
|
|
p = argparse.ArgumentParser() |
|
|
|
|
p.add_argument("--user", default='martijn.wieling') |
|
|
|
|
p.add_argument("--password", default='fa0Thaic') |
|
|
|
|
args = p.parse_args() |
|
|
|
|
|
|
|
|
|
rec = session.Recognizer(grammar_version="1.0", lang="nl", snodeid=101, user=args.user, password=args.password, keepopen=True) # , modeldir=modeldir) |
|
|
|
|
|
|
|
|
|
grammar = make_grammar(word, pronunciation_ipa) |
|
|
|
|
result = rec.setgrammar(grammar) |
|
|
|
|
#print "Set grammar result", res |
|
|
|
|
result = rec.recognize_wav(wav_file) |
|
|
|
|
return result.export() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def result2pronunciation(result, word): |
|
|
|
|
result_ = [result[i] for i in range(len(result)) if result[i]['label'] == word] |
|
|
|
|
llh = result_[0]['llh'] |
|
|
|
|
phones = result_[0]['phones'] |
|
|
|
|
pronunciation_novo70 = [phone['label'] for phone in phones] |
|
|
|
|
pronunciation_ipa = [novo702ipa(phone) for phone in pronunciation_novo70] |
|
|
|
|
return pronunciation_ipa, pronunciation_novo70, llh |