def test_tedlium(self):
        transitions = durmodel_utils.read_transitions(os.path.dirname(__file__) + "/test_data/tedlium/transitions.txt")
        nonsilence_phonemes = set()
        for l in open(os.path.dirname(__file__) + "/test_data/tedlium/nonsilence.txt"):
            nonsilence_phonemes.add(l.partition("_")[0])

        word_list = []
        for l in codecs.open(os.path.dirname(__file__) + "/test_data/tedlium/words.txt", encoding="UTF-8"):
            word_list.append(l.split()[0])

        stress_dict = durmodel_utils.load_stress_dict(os.path.dirname(__file__) + "/data/en/cmudict.0.7a.lc")

        # about
        word_id = 437
        frames = [int(s) for s in "1794_2062_2061_2061_2300_5602_5601_5650_5662_5661_5661_4808_4807_4807_4807_4807_4832_4831_4831_4831_4860_4859_4859_22924_22923_22923_23018_23118".split("_")]

        features_and_dur_seq = durmodel_utils.make_local(0, word_id, frames, transitions, word_list, nonsilence_phonemes, language="ENGLISH", stress_dict=stress_dict)
        print features_and_dur_seq
        self.assert_(('syllable', 1) in features_and_dur_seq[0][0])
        self.assert_(('AH', 1) in features_and_dur_seq[0][0])
        self.assert_(('vowel', 1) in features_and_dur_seq[0][0])
        self.assert_(5, features_and_dur_seq[0][1])

        self.assert_(('stress1', 1) in features_and_dur_seq[2][0])

        self.assert_(('syllable', 2) in features_and_dur_seq[1][0])

        self.assert_(('stop', 1) in features_and_dur_seq[-1][0])
        self.assert_(5, features_and_dur_seq[0][-1])
 def test_stress(self):
     word = "abstain"
     phones = "AH B S T EY N".split()
     stress_dict = durmodel_utils.load_stress_dict(os.path.dirname(__file__) + "/data/en/cmudict.0.7a.lc")
     self.assertEqual(['AH', 'B', 'S', 'T', 'EY', 'N'], stress_dict["abstain"][0][0])
     self.assertEqual([0, 0, 0, 0, 1, 0], stress_dict["abstain"][0][1])
     stress = durmodel_utils.get_stress(word, phones, stress_dict)
     self.assertEqual([0, 0, 0, 0, 1, 0], stress)
     # test unknown word
     stress = durmodel_utils.get_stress("tanel", "T AH N EH L".split(), stress_dict)
     self.assertEqual([0, 0, 0, 0, 0], stress)
Exemplo n.º 3
0
 def test_stress(self):
     word = 'abstain'
     phones = 'AH B S T EY N'.split()
     stress_dict = durmodel_utils.load_stress_dict(
         dirname(__file__) + '/data/en/cmudict.0.7a.lc')
     self.assertEqual(['AH', 'B', 'S', 'T', 'EY', 'N'],
                      stress_dict['abstain'][0][0])
     self.assertEqual([0, 0, 0, 0, 1, 0], stress_dict['abstain'][0][1])
     stress = durmodel_utils.get_stress(word, phones, stress_dict)
     self.assertEqual([0, 0, 0, 0, 1, 0], stress)
     # test unknown word
     stress = durmodel_utils.get_stress('tanel', 'T AH N EH L'.split(),
                                        stress_dict)
     self.assertEqual([0, 0, 0, 0, 0], stress)
Exemplo n.º 4
0
 def test_stress(self):
     word = "abstain"
     phones = "AH B S T EY N".split()
     stress_dict = durmodel_utils.load_stress_dict(
         os.path.dirname(__file__) + "/data/en/cmudict.0.7a.lc")
     self.assertEqual(['AH', 'B', 'S', 'T', 'EY', 'N'],
                      stress_dict["abstain"][0][0])
     self.assertEqual([0, 0, 0, 0, 1, 0], stress_dict["abstain"][0][1])
     stress = durmodel_utils.get_stress(word, phones, stress_dict)
     self.assertEqual([0, 0, 0, 0, 1, 0], stress)
     # test unknown word
     stress = durmodel_utils.get_stress("tanel", "T AH N EH L".split(),
                                        stress_dict)
     self.assertEqual([0, 0, 0, 0, 0], stress)
Exemplo n.º 5
0
    def test_tedlium(self):
        transitions = durmodel_utils.read_transitions(
            os.path.dirname(__file__) + "/test_data/tedlium/transitions.txt")
        nonsilence_phonemes = set()
        for l in open(
                os.path.dirname(__file__) +
                "/test_data/tedlium/nonsilence.txt"):
            nonsilence_phonemes.add(l.partition("_")[0])

        word_list = []
        for l in codecs.open(os.path.dirname(__file__) +
                             "/test_data/tedlium/words.txt",
                             encoding="UTF-8"):
            word_list.append(l.split()[0])

        stress_dict = durmodel_utils.load_stress_dict(
            os.path.dirname(__file__) + "/data/en/cmudict.0.7a.lc")

        # about
        word_id = 437
        frames = [
            int(s) for s in
            "1794_2062_2061_2061_2300_5602_5601_5650_5662_5661_5661_4808_4807_4807_4807_4807_4832_4831_4831_4831_4860_4859_4859_22924_22923_22923_23018_23118"
            .split("_")
        ]

        features_and_dur_seq = durmodel_utils.make_local(
            0,
            word_id,
            frames,
            transitions,
            word_list,
            nonsilence_phonemes,
            language="ENGLISH",
            stress_dict=stress_dict)
        print features_and_dur_seq
        self.assert_(('syllable', 1) in features_and_dur_seq[0][0])
        self.assert_(('AH', 1) in features_and_dur_seq[0][0])
        self.assert_(('vowel', 1) in features_and_dur_seq[0][0])
        self.assert_(5, features_and_dur_seq[0][1])

        self.assert_(('stress1', 1) in features_and_dur_seq[2][0])

        self.assert_(('syllable', 2) in features_and_dur_seq[1][0])

        self.assert_(('stop', 1) in features_and_dur_seq[-1][0])
        self.assert_(5, features_and_dur_seq[0][-1])
Exemplo n.º 6
0
    print >> sys.stderr, "DEBUG: transitions[%d] = %s" % (len(transitions) -1,  transitions[-1])

    print >> sys.stderr, "Reading non-silence phonemes"
    nonsilence_phonemes = set()
    for l in open(args.nonsilence):
        nonsilence_phonemes.add(l.partition("_")[0])

    print >> sys.stderr, "Reading words.txt"
    word_list = []
    for l in codecs.open(args.words, encoding="UTF-8"):
        word_list.append(l.split()[0])

    stress_dict = None
    if args.stress_dict_filename:
        print >> sys.stderr, "Reading stress dictionary"
        stress_dict = durmodel_utils.load_stress_dict(args.stress_dict_filename)


    num_sentences_read = 0
    full_features_and_durs = []
    sentence_lines = []

    print >> sys.stderr, "Processing alignements..."
    for l in gzip.open(args.train_lattice):
        if len(l.strip()) > 0:
            sentence_lines.append(l)
        elif len(sentence_lines) > 0:
            try:
                lat = lattice.parse_aligned_lattice(sentence_lines)
                #print >> sys.stderr, "Processing lattice %s" % lat.name
                features_and_durs = []
Exemplo n.º 7
0
    nonsilence_phonemes = set()
    for l in open(args.nonsilence):
        nonsilence_phonemes.add(l.partition("_")[0])

    print >> sys.stderr, "Reading words.txt"
    word_list = []
    for l in codecs.open(args.words, encoding="UTF-8"):
        word_list.append(l.split()[0])

    filler_words = ["<eps>"] + args.fillers.split(",")
    print >> sys.stderr, "Fillers: ", filler_words

    stress_dict = None
    if args.stress_dict_filename:
        print >> sys.stderr, "Reading stress dictionary"
        stress_dict = durmodel_utils.load_stress_dict(
            args.stress_dict_filename)

    feature_dict = OrderedDict()
    if args.read_features_filename:
        print >> sys.stderr, ".. Reading features from %s" % args.read_features_filename
        feature_dict = OrderedDict()
        for (i, feature) in enumerate(
                codecs.open(args.read_features_filename, encoding="UTF-8")):
            feature_dict[feature.strip()] = i

    speaker_ids = None
    if args.speakers:
        print >> sys.stderr, ".. Reading speakers from %s" % args.speakers
        speaker_ids = {}
        for l in open(args.speakers):
            ss = l.split()