Browse Source

phoneset conversion is added.

master
yemaozi88 4 years ago
parent
commit
5a587e0422
  1. BIN
      .vs/acoustic_model/v15/.suo
  2. 13152
      HCompV.scp
  3. 4
      acoustic_model.sln
  4. BIN
      acoustic_model/__pycache__/acoustic_model_functions.cpython-36.pyc
  5. 57
      acoustic_model/acoustic_model.py
  6. 64
      acoustic_model/acoustic_model_functions.py
  7. 4
      acoustic_model/config.ini
  8. 1600
      acoustic_model/script.txt

BIN
.vs/acoustic_model/v15/.suo

Binary file not shown.

13152
HCompV.scp

File diff suppressed because it is too large Load Diff

4
acoustic_model.sln

@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.26730.12 @@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.26730.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "acoustic_model", "acoustic_model\acoustic_model.pyproj", "{4D8C8573-32F0-4A62-9E62-3CE5CC680390}"
EndProject
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "forced_alignment", "..\forced_alignment\forced_alignment\forced_alignment.pyproj", "{92E4D819-38D0-467A-ABEE-09662EEAA084}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -13,6 +15,8 @@ Global @@ -13,6 +15,8 @@ Global
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4D8C8573-32F0-4A62-9E62-3CE5CC680390}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4D8C8573-32F0-4A62-9E62-3CE5CC680390}.Release|Any CPU.ActiveCfg = Release|Any CPU
{92E4D819-38D0-467A-ABEE-09662EEAA084}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{92E4D819-38D0-467A-ABEE-09662EEAA084}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

BIN
acoustic_model/__pycache__/acoustic_model_functions.cpython-36.pyc

Binary file not shown.

57
acoustic_model/acoustic_model.py

@ -4,14 +4,19 @@ import tempfile @@ -4,14 +4,19 @@ import tempfile
import configparser
import subprocess
import pandas as pd
## ======================= user define =======================
repo_dir = 'C:\\Users\\Aki\\source\\repos\\acoustic_model'
curr_dir = repo_dir + '\\acoustic_model'
config_ini = curr_dir + '\\config.ini'
output_dir = 'd:\\OneDrive\\Research\\rug\\experiments\\friesian\\acoustic_model'
forced_alignment_module = 'C:\\Users\\Aki\\source\\repos\\forced-alignment'
sys.path.append(os.path.join(os.path.dirname(sys.path[0]), curr_dir))
sys.path.append(forced_alignment_module)
from forced_alignment import convert_phone_set
import acoustic_model_functions as am_func
@ -27,6 +32,7 @@ config_hcopy = config['Settings']['config_hcopy'] @@ -27,6 +32,7 @@ config_hcopy = config['Settings']['config_hcopy']
config_train = config['Settings']['config_train']
FAME_dir = config['Settings']['FAME_dir']
lexicon_file = FAME_dir + '\\lexicon\\lex.asr'
dataset_list = ['devel', 'test', 'train']
@ -39,7 +45,7 @@ dataset_list = ['devel', 'test', 'train'] @@ -39,7 +45,7 @@ dataset_list = ['devel', 'test', 'train']
#hcopy_scp = tempfile.NamedTemporaryFile(mode='w', delete=False)
#hcopy_scp.close()
## using the wav_scp in FAME! corpus
## using the filelist in FAME! corpus
#feature_dir = output_dir + '\\mfc\\' + dataset
#am_func.make_hcopy_scp_from_filelist_in_fame(FAME_dir, dataset, feature_dir, hcopy_scp.name)
@ -62,5 +68,50 @@ dataset_list = ['devel', 'test', 'train'] @@ -62,5 +68,50 @@ dataset_list = ['devel', 'test', 'train']
## ======================= check the phonemes used in the lexicon =======================
lex_file = FAME_dir + '\\lexicon\\lex.asr'
phonelist = am_func.get_phonelist(lex_file)
phonelist = am_func.get_phonelist(lexicon_file) # 49
phonelist_list = list(phonelist)
#lines_g1 = am_func.find_phone(lexicon_file, 'g')
#lines_g2 = am_func.find_phone(lexicon_file, 'ɡ')
## ======================= make label file =======================
dataset = 'train'
hcompv_scp = output_dir + '\\scp\\' + dataset + '.scp'
script_list = FAME_dir + '\\data\\' + dataset + '\\text'
lexicon = pd.read_table(lexicon_file, names=['word', 'pronunciation'])
with open(hcompv_scp) as fin:
features = fin.read()
features = features.split('\n')
with open(script_list, "rt", encoding="utf-8") as fin:
scripts = fin.read()
scripts = pd.Series(scripts.split('\n'))
feature = features[0]
file_basename = os.path.basename(feature).replace('.mfc', '')
# get words from scripts.
script = scripts[scripts.str.contains(file_basename)]
script_id = script.index[0]
script_txt = script.get(script_id)
script_words = script_txt.split(' ')
del script_words[0]
# make the label file.
SCRIPT_WORDS = []
script_prons = []
all_prons_found = 1
for word in script_words:
SCRIPT_WORDS.append(word.upper())
extracted = lexicon[lexicon['word']==word]
script_prons.append(extracted)
all_prons_found *= len(extracted)
# make the dict file.
convert_phone_set.ipa2fame(phonelist_list)
phonelist_list

64
acoustic_model/acoustic_model_functions.py

@ -0,0 +1,64 @@ @@ -0,0 +1,64 @@
import os
import sys
repo_dir = 'C:\\Users\\Aki\\source\\repos\\acoustic_model'
curr_dir = repo_dir + '\\acoustic_model'
sys.path.append(os.path.join(os.path.dirname(sys.path[0]), curr_dir))
def make_hcopy_scp_from_filelist_in_fame(FAME_dir, dataset, feature_dir, hcopy_scp):
""" Make a script file for HCopy using the filelist in FAME! corpus. """
filelist_txt = FAME_dir + '\\fame\\filelists\\' + dataset + 'list.txt'
with open(filelist_txt) as fin:
filelist = fin.read()
filelist = filelist.split('\n')
with open(hcopy_scp, 'w') as fout:
for filename_ in filelist:
filename = filename_.replace('.TextGrid', '')
if len(filename) > 3: # remove '.', '..' and ''
wav_file = FAME_dir + '\\fame\\wav\\' + dataset + '\\' + filename + '.wav'
mfc_file = feature_dir + '\\' + filename + '.mfc'
fout.write(wav_file + '\t' + mfc_file + '\n')
def make_filelist(input_dir, output_txt):
""" Make a list of files in the input_dir. """
filenames = os.listdir(input_dir)
with open(output_txt, 'w') as fout:
for filename in filenames:
fout.write(input_dir + '\\' + filename + '\n')
def get_phonelist(lexicon_file):
""" Make a list of phones which appears in the lexicon. """
with open(lexicon_file, "rt", encoding="utf-8") as fin:
lines = fin.read()
lines = lines.split('\n')
phonelist = set([])
for line in lines:
line = line.split('\t')
if len(line) > 1:
pronunciation = set(line[1].split())
phonelist = phonelist | pronunciation
return phonelist
def find_phone(lexicon_file, phone):
""" Search where the phone is used in the lexicon. """
with open(lexicon_file, "rt", encoding="utf-8") as fin:
lines = fin.read()
lines = lines.split('\n')
extracted = []
for line in lines:
line = line.split('\t')
if len(line) > 1:
pron = line[1]
if phone in pron:
extracted.append(line)
return extracted

4
acoustic_model/config.ini

@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
[Settings]
config_hcopy = c:\cygwin64\home\Aki\acoustic_model\config\config.HCopy
config_train = c:\cygwin64\home\Aki\acoustic_model\config\config.train
FAME_dir = d:\OneDrive\Research\rug\experiments\friesian\corpus

1600
acoustic_model/script.txt

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save