Beispiel #1
0
    def testMix(self):
        acmodel1 = sppasAcModel()
        hmm1 = sppasHMM()
        hmm1.create_proto(25)
        hmm1.set_name("y")
        acmodel1.append_hmm(hmm1)
        acmodel1.get_repllist().add("y", "j")

        acmodel2 = sppasAcModel()
        hmm2 = sppasHMM()
        hmm2.create_proto(25)
        hmm2.set_name("j")
        hmm3 = sppasHMM()
        hmm3.create_proto(25)
        hmm3.name = "y"
        acmodel2.get_hmms().append(hmm2)
        acmodel2.get_hmms().append(hmm3)
        acmodel2.get_repllist().add("y", "y")
        acmodel2.get_repllist().add("j", "j")

        modelmixer = sppasModelMixer()
        modelmixer.set_models(acmodel1, acmodel2)

        outputdir = os.path.join(MODELDIR, "models-test")
        modelmixer.mix(outputdir, gamma=1.)
        self.assertTrue(os.path.exists(outputdir))
        model = sppasACMRW(outputdir).read()
        shutil.rmtree(outputdir)
Beispiel #2
0
    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)
Beispiel #3
0
    def testMix(self):
        acmodel1 = sppasAcModel()
        hmm1 = sppasHMM()
        hmm1.create_proto(25)
        hmm1.name = "y"
        acmodel1.append_hmm(hmm1)
        acmodel1.repllist.add("y", "j")

        acmodel2 = sppasAcModel()
        hmm2 = sppasHMM()
        hmm2.create_proto(25)
        hmm2.name = "j"
        hmm3 = sppasHMM()
        hmm3.create_proto(25)
        hmm3.name = "y"
        acmodel2.hmms.append(hmm2)
        acmodel2.hmms.append(hmm3)
        acmodel2.repllist.add("y", "y")
        acmodel2.repllist.add("j", "j")

        modelmixer = sppasModelMixer()
        modelmixer.set_models(acmodel1, acmodel2)

        outputdir = os.path.join(MODELDIR, "models-test")
        modelmixer.mix(outputdir, gamma=1.)
        mixedh1 = sppasAcModel()
        mixedh1.load(outputdir)
        shutil.rmtree(outputdir)
Beispiel #4
0
    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)
Beispiel #5
0
 def testMixData(self):
     modelmixer = sppasModelMixer()
     modelmixer.read(self._model_L2dir, self._model_L1dir)
     outputdir = os.path.join(MODELDIR, "models-eng-fra")
     modelmixer.mix(outputdir, gamma=0.5)
     self.assertTrue(os.path.exists(outputdir))
     acmodel1 = sppasACMRW(self._model_L2dir).read()
     acmodel1_mono = acmodel1.extract_monophones()
     acmodel2 = sppasACMRW(os.path.join(MODELDIR, "models-eng-fra")).read()
     shutil.rmtree(outputdir)
Beispiel #6
0
 def testMixData(self):
     modelmixer = sppasModelMixer()
     modelmixer.load(self._model_L2dir, self._model_L1dir)
     outputdir = os.path.join(MODELDIR, "models-eng-fra")
     modelmixer.mix(outputdir, gamma=0.5)
     self.assertTrue(os.path.exists(outputdir))
     acmodel1 = sppasAcModel()
     acmodel1.load_htk(os.path.join(self._model_L2dir, "hmmdefs"))
     acmodel1 = acmodel1.extract_monophones()
     acmodel2 = sppasAcModel()
     acmodel2.load_htk(os.path.join(os.path.join(MODELDIR, "models-eng-fra"), "hmmdefs"))
     shutil.rmtree(outputdir)
Beispiel #7
0
    def load_resources(self, model, model_L1=None, **kwargs):
        """Fix the acoustic model directory.

        Create a SpeechSegmenter and AlignerIO.

        :param model: (str) Directory of the acoustic model of the language
        of the text
        :param model_L1: (str) Directory of the acoustic model of
        the mother language of the speaker

        """
        if model_L1 is not None:
            try:
                model_mixer = sppasModelMixer()
                model_mixer.read(model, model_L1)
                output_dir = os.path.join(paths.resources, "models",
                                          "models-mix")
                model_mixer.mix(output_dir, gamma=0.6)
                model = output_dir
            except Exception as e:
                self.logfile.print_message(MSG_MODEL_L1_FAILED.format(str(e)),
                                           indent=2,
                                           status=annots.warning)

        # 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:
                mapping = sppasMapping()
                logging.warning('No mapping file was found in model {:s}'
                                ''.format(model))
        else:
            mapping = sppasMapping()

        # Managers of the automatic alignment task
        self._tracksrw = TracksReaderWriter(mapping)
        self._segmenter.set_model(model)