2018-06-13 00:22:53 +02:00
|
|
|
|
import os
|
|
|
|
|
import sys
|
|
|
|
|
import csv
|
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
|
import convert_xsampa2ipa
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## ======================= user define =======================
|
|
|
|
|
forced_alignment_module = r'C:\Users\Aki\source\repos\forced_alignment'
|
|
|
|
|
ipa_xsampa_converter_dir = r'C:\Users\Aki\source\repos\ipa-xsama-converter'
|
|
|
|
|
csvfile = r"C:\OneDrive\Research\rug\stimmen\Frisian Variants Picture Task Stimmen.csv"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sys.path.append(forced_alignment_module)
|
|
|
|
|
from forced_alignment import convert_phone_set
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping = convert_xsampa2ipa.load_converter('xsampa', 'ipa', ipa_xsampa_converter_dir)
|
|
|
|
|
#word_xsampa = 'e:j@X'
|
|
|
|
|
#word_ipa = convert_xsampa2ipa.conversion('xsampa', 'ipa', mapping, word_xsampa)
|
|
|
|
|
|
|
|
|
|
with open(csvfile, encoding="utf-8") as fin:
|
|
|
|
|
lines = csv.reader(fin, delimiter=';', lineterminator="\n", skipinitialspace=True)
|
|
|
|
|
next(lines, None) # skip the headers
|
|
|
|
|
|
|
|
|
|
filenames = []
|
|
|
|
|
words = []
|
|
|
|
|
pronunciations = []
|
|
|
|
|
for line in lines:
|
|
|
|
|
if line[1] is not '' and len(line) > 5:
|
|
|
|
|
filenames.append(line[0])
|
|
|
|
|
words.append(line[1])
|
|
|
|
|
word_xsampa = line[3]
|
|
|
|
|
word_ipa = convert_xsampa2ipa.conversion('xsampa', 'ipa', mapping, word_xsampa)
|
|
|
|
|
word_ipa = word_ipa.replace('ː', ':')
|
|
|
|
|
word_famehtk = convert_phone_set.ipa2famehtk(word_ipa)
|
|
|
|
|
pronunciations.append(word_famehtk)
|
|
|
|
|
phonelist = ' '.join(pronunciations)
|
|
|
|
|
np.unique(phonelist.split(' '))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## ======================= forced alignment =======================
|
2018-04-25 09:07:46 +02:00
|
|
|
|
#if forced_alignment:
|
|
|
|
|
# try:
|
|
|
|
|
# scripts.run_command([
|
|
|
|
|
# 'HVite','-T', '1', '-a', '-C', configHVite,
|
|
|
|
|
# '-H', AcousticModel, '-m', '-I',
|
|
|
|
|
# mlf_file, '-i', fa_file, '-S',
|
|
|
|
|
# script_file, htk_dict_file, filePhoneList
|
|
|
|
|
# ])
|
|
|
|
|
# except:
|
|
|
|
|
# print("\033[91mHVite command failed with these input files:\033[0m")
|
|
|
|
|
# print(_debug_show_file('HVite config', configHVite))
|
|
|
|
|
# print(_debug_show_file('Accoustic model', AcousticModel))
|
|
|
|
|
# print(_debug_show_file('Master Label file', mlf_file))
|
|
|
|
|
# print(_debug_show_file('Output', fa_file))
|
|
|
|
|
# print(_debug_show_file('Script file', script_file))
|
|
|
|
|
# print(_debug_show_file('HTK dictionary', htk_dict_file))
|
|
|
|
|
# print(_debug_show_file('Phoneme list', filePhoneList))
|
|
|
|
|
# raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##os.remove(hcopy_scp.name)
|