def fix_segmenter(self, model, model_L1): """ Fix the acoustic model directory, then create a SpeechSegmenter and AlignerIO. :param model: (str) Name of the directory of the acoustic model of the language of the text :param model_L1: (str) Name of the directory of the acoustic model of the mother language of the speaker """ if model_L1 is not None: try: model_mixer = sppasModelMixer() model_mixer.load(model, model_L1) output_dir = os.path.join(RESOURCES_PATH, "models", "models-mix") model_mixer.mix(output_dir, gamma=0.6) model = output_dir except Exception as e: self.print_message(MSG_MODEL_L1_FAILED.format(str(e)), indent=3, status=WARNING_ID) # Map phoneme names from model-specific to SAMPA and vice-versa mapping_filename = os.path.join(model, "monophones.repl") if os.path.isfile(mapping_filename): try: mapping = sppasMapping(mapping_filename) except Exception: mapping = sppasMapping() else: mapping = sppasMapping() # Manager of the interval tracks self.alignio = AlignIO(mapping, model)
def __init__(self, model): """ Creates a Chunks instance. :param model: Acoustic model """ self._aligner = aligners.instantiate(model, "julius") self._aligner.set_infersp(False) self._aligner.set_outext("walign") # Map phoneme names from SAMPA model-specific mappingfilename = os.path.join(model, "monophones.repl") if os.path.isfile(mappingfilename): try: self._mapping = sppasMapping(mappingfilename) except Exception: self._mapping = sppasMapping() else: self._mapping = sppasMapping() self._alignerio = AlignerIO() self._spkrate = SpeakerRate() self._radius = 0.005 self.N = 5 # initial N-gram to search the anchors self.NMIN = 3 # minimum N-gram to search the anchors self.W = 6. # initial windows delay to search the anchors self.WMIN = 3. # minimum windows delay to search the anchors self.NBT = 12 # maximum number of tokens for chunks (and holes) self.ANCHORS = True # Append anchors into the result self.SILENCES = False # Search automatically silences before anchors
def __init__(self, model): """ Creates a Chunks instance. :param model: Acoustic model """ self._aligner = aligners.instantiate(model, "julius") self._aligner.set_infersp(False) self._aligner.set_outext("walign") # Map phoneme names from SAMPA model-specific mappingfilename = os.path.join(model, "monophones.repl") if os.path.isfile(mappingfilename): try: self._mapping = sppasMapping(mappingfilename) except Exception: self._mapping = sppasMapping() else: self._mapping = sppasMapping() self._alignerio = AlignerIO() self._spkrate = SpeakerRate() self._radius = 0.005 self.N = 5 # initial N-gram to search the anchors self.NMIN = 3 # minimum N-gram to search the anchors self.W = 6. # initial windows delay to search the anchors self.WMIN = 3. # minimum windows delay to search the anchors self.NBT = 12 # maximum number of tokens for chunks (and holes) self.ANCHORS = True # Append anchors into the result self.SILENCES = False # Search automatically silences before anchors
def __init__(self): """ Create an sppasAcModel instance. """ self.macros = None self.hmms = [] self.tiedlist = sppasTiedList() self.repllist = sppasMapping()
def __init__(self, dict_filename, map_filename=None, logfile=None): """ Create a sppasPhon instance. :param dict_filename: (str) is the pronunciation dictionary file name (HTK-ASCII format, utf8). :param map_filename: (str) is the filename of a mapping table. It is used to generate new pronunciations by mapping phonemes of the dictionary. :param logfile (sppasLog) is a log file utility class member. :raises: ValueError if loading the dictionary fails """ sppasBaseAnnotation.__init__(self, logfile) # Pronunciation dictionary self.maptable = None if map_filename is not None: self.maptable = sppasMapping(map_filename) self.phonetizer = None self.set_dict(dict_filename) # List of options to configure this automatic annotation self._options = dict() self._options['phonunk'] = False # Phonetize missing tokens self._options['usestdtokens'] = False # Phonetize standard spelling
def __init__(self, dict_filename, map_filename=None, logfile=None): """ Create a sppasPhon instance. :param dict_filename: (str) is the pronunciation dictionary file name (HTK-ASCII format, utf8). :param map_filename: (str) is the filename of a mapping table. It is used to generate new pronunciations by mapping phonemes of the dictionary. :param logfile (sppasLog) is a log file utility class member. :raises: ValueError if loading the dictionary fails """ sppasBaseAnnotation.__init__(self, logfile, "Phonetization") # Pronunciation dictionary self.maptable = None if map_filename is not None: self.maptable = sppasMapping(map_filename) self.phonetizer = None self.set_dict(dict_filename) # List of options to configure this automatic annotation self._options = dict() self._options['phonunk'] = False # Phonetize missing tokens self._options['usestdtokens'] = False # Phonetize standard spelling
def test_map_entry(self): mapt = sppasMapping() mapt.add('a', 'A') mapt.add('b', 'B') mapt.add('b', 'v') mapt.add('a-c', 'a-C') self.grph.set_maptable( mapt ) self.assertEqual(self.grph._map_phonentry("c"), "c") self.assertEqual(self.grph._map_phonentry("a"), "a|A") self.assertEqual(self.grph._map_phonentry("b"), "B|b|v") self.assertEqual(self.grph._map_phonentry("c.c"), 'c.c') result = 'a-b|a-B|A-b|A-B|A-v|a-v' self.assertEqual(set(self.grph._map_phonentry("a-b").split("|")), set(result.split("|"))) result = "a-c|a-C" self.assertEqual(set(self.grph._map_phonentry("a-c").split("|")), set(result.split("|"))) result = "a-c-A|a-c-a|a-C-A|a-C-a" self.assertEqual(set(self.grph._map_phonentry("a-c-a").split("|")), set(result.split("|"))) result = "c-a-c|c-a-C" self.assertEqual(set(self.grph._map_phonentry("c-a-c").split("|")), set(result.split("|"))) mapt.add('a', 'a') mapt.add('b', 'b') mapt.add('c', 'c') self.assertEqual(self.grph._map_phonentry("c"), "c") self.assertEqual(self.grph._map_phonentry("a"), "a|A") self.assertEqual(self.grph._map_phonentry("b"), "B|b|v") self.grph.set_maptable(None)
def __init__(self, name=None): """ Create an sppasAcModel instance. """ self._name = None self._macros = None self._hmms = list() self._tiedlist = sppasTiedList() self._repllist = sppasMapping() self.set_name(name)
def __init__(self, pdict, maptable=None): """ Create a sppasDictPhonetizer instance. :param pdict: (sppasDictPron) The pronunciation dictionary. :param maptable: (Mapping) A mapping table for phones. """ self._pdict = None self._phonunk = None self._map_table = sppasMapping() self._dag_phon = sppasDAGPhonetizer() self.set_dict(pdict) self.set_maptable(maptable)
def set_maptable(self, map_table): """ Set the mapping table dictionary. :param map_table: (Mapping) The mapping table dictionary. """ if map_table is not None: if isinstance(map_table, sppasMapping) is False: raise TypeError('Expected a Mapping instance.') else: map_table = sppasMapping() self._map_table = map_table self._map_table.set_keep_miss(False)
def __init__(self, model, model_L1=None, logfile=None): """ Create a new sppasAlign instance. :param model: (str) Name of the directory of the acoustic model of the language of the text :param model_L1: (str) Name of the directory of the acoustic model of the mother language of the speaker :param logfile: (sppasLog) """ sppasBaseAnnotation.__init__(self, logfile) self.mapping = sppasMapping() self.alignio = None self.fix_segmenter(model, model_L1) self.reset()
def test_data(self): dictfile = os.path.join(RESOURCES_PATH, "dict", "eng.dict") map_table = os.path.join(RESOURCES_PATH, "dict", "eng-fra.map") mapt = sppasMapping(map_table) dd = sppasDictPron(dictfile) grph = sppasDictPhonetizer(dd) self.assertEqual(grph.get_phon_entry("THE"), "D-@|D-V|D-i:") self.assertEqual(grph.get_phon_entry("UR"), "3:r|U-r\\") self.assertEqual(grph.get_phon_entry("ARE"), "A-r\|3:r") self.assertEqual(grph.get_phon_entry("BANC"), "b-{-N-k") grph.set_maptable(mapt) the = "z-@|D-@|v-@|v-V|D-V|z-V|z-9|D-9|v-9|z-i:|z-i|D-i|v-i|D-i:|v-i:" ur = "3:r|9-R|u-r\|U-w|u-w|U-R|U-r\|u-R" are = "a-R|A-R|a-w|A-w|a-r\|A-r\|3:r|9-R" self.assertEqual(set(grph.get_phon_entry("THE").split("|")), set(the.split("|"))) self.assertEqual(set(grph.get_phon_entry("UR").split("|")), set(ur.split("|"))) self.assertEqual(set(grph.get_phon_entry("ARE").split("|")), set(are.split("|")))
def __init__(self, mapping, model): """ Creates a new AlignIO instance. :param mapping: (Mapping) a mapping table to convert the phone set """ # Mapping system for the phonemes if mapping is None: mapping = sppasMapping() if isinstance(mapping, sppasMapping) is False: raise TypeError('Aligner expected a Mapping() as argument.') self._mapping = mapping # The automatic alignment system self.aligntrack = AlignTrack(model) # The file names of tracks generator self._tracknames = TrackNamesGenerator()
# ---------------------------------------------------------------------------- if not args.quiet: setup_logging(1, None) # ---------------------------------------------------------------------------- # Automatic Phonetization is here: # ---------------------------------------------------------------------------- unkopt = True if args.nounk: unkopt = False mapfile = None if args.map: mapfile = args.map if args.i: p = sppasPhon(args.dict, mapfile) p.set_unk(unkopt) p.set_usestdtokens(False) p.run(args.i, args.o) else: pdict = sppasDictPron(args.dict, nodump=False) maptable = sppasMapping() if mapfile is not None: maptable = sppasMapping(mapfile) phonetizer = sppasDictPhonetizer(pdict, maptable) for line in sys.stdin: print("{:s}".format(phonetizer.phonetize(line, unkopt)))