def evalAccuracyTest(): ######### for test logic see WordLevelEvaluator instead PATH_TEST_DATASET = '../example/' annotationURI = os.path.join(PATH_TEST_DATASET, 'grTruth.TextGrid') # load from file # detectedURI = os.path.join(PATH_TEST_DATASET, audioName + '.phrasesDurationAligned') detectedTokenList = readListOfListTextFile(os.path.join(PATH_TEST_DATASET, 'detected.aligned')) ############### annotationURI = '/Users/joro/Documents/Phd/UPF/arias_dev_01_t_70//laosheng-erhuang_04.TextGrid' detectedTokenList = readListOfListTextFile('/Users/joro/Documents/Phd/UPF/arias_dev_01_t_70/laosheng-erhuang_04_49.8541936425_108.574785469.syllables') startIdx=1; endIdx=13 ################# annotationURI = '/Users/joro/Documents/Phd/UPF/arias_dev_01_t_70/laosheng-erhuang_04.TextGrid' detectedTokenList = readListOfListTextFile('/Users/joro/Documents/Phd/UPF/arias_dev_01_t_70/laosheng-erhuang_04_134.647686205_168.77679257.syllables') startIdx=15; endIdx=26 whichTier=3 durationCorrect, totalLength = _evalAccuracy(annotationURI, detectedTokenList,whichTier , startIdx, endIdx) print durationCorrect print totalLength print durationCorrect/totalLength
def testReadListOfListTextFile(self): ''' this is a unit test ''' URIfile = '04_Hamiyet_Yuceses_-_Bakmiyor_Cesm-i_Siyah_Feryade_1_zemin_from_11_593270_to_22_910647.phrasesDurationSynthAligned' detectedTokenList = readListOfListTextFile(URIfile) print detectedTokenList
def test_oracle_jingju(URIrecordingNoExt, whichSentence, fromPhonemeIdx, toPhonemeIdx): ''' read phoneme-level ground truth and test with dan-xipi_02 ''' ANNOTATION_EXT = '.TextGrid' listSentences = divideIntoSentencesFromAnno(URIrecordingNoExt + ANNOTATION_EXT) #uses TextGrid annotation to derive structure. TODO: instead of annotation, uses score withSynthesis = False currSentence = listSentences[whichSentence] # consider only part of audio fromTs = currSentence[0] toTs = currSentence[1] lyrics = loadLyricsFromTextGridSentence(currSentence) tokenLevelAlignedSuffix = '.syllables_oracle' detectedAlignedfileName = URIrecordingNoExt + '_' + str(fromTs) + '_' + str(toTs) + '_' + tokenLevelAlignedSuffix if os.path.isfile(detectedAlignedfileName): print "{} already exists. No decoding".format(detectedAlignedfileName) from Utilz import readListOfListTextFile detectedTokenList = readListOfListTextFile(detectedAlignedfileName) else: detectedTokenList = decodeWithOracle(lyrics, URIrecordingNoExt, fromTs, toTs, fromPhonemeIdx, toPhonemeIdx) if not os.path.isfile(detectedAlignedfileName): from PraatVisualiser import tokenList2TabFile detectedAlignedfileName = tokenList2TabFile(detectedTokenList, URIrecordingNoExt, tokenLevelAlignedSuffix) # eval on phrase level evalLevel = 2 fromSyllable = currSentence[2] toSyllable = currSentence[3] correctDuration, totalDuration = _evalAccuracy(URIrecordingNoExt + ANNOTATION_EXT, detectedTokenList, evalLevel, fromSyllable, toSyllable ) print "accuracy= {}".format(correctDuration / totalDuration) return detectedTokenList
nextBeginDetected = detectedTokenListNoPauses[currentWordNumber + numWordsInPhrase][0] correct += max(0,min(nextBeginAnno,nextBeginDetected) - max(currEndAnno, currEndDetected)) else: if (currEndAnno > finalTsDetected): sys.exit("currEndAnno > finalTsDetected") if (currEndDetected > finallTsAnno ): # WORKAROUND currEndDetected = finallTsAnno logging.warn("currEndDetected > finallTsAnno") correct += max(0,min(finallTsAnno,finalTsDetected) - max(currEndAnno, currEndDetected)) return correct if __name__ == '__main__': ######### for test logic see WordLevelEvaluator instead PATH_TEST_DATASET = 'example/' annotationURI = os.path.join(PATH_TEST_DATASET, 'grTruth.TextGrid') # load from file # detectedURI = os.path.join(PATH_TEST_DATASET, audioName + '.phrasesDurationAligned') detectedTokenList = readListOfListTextFile(os.path.join(PATH_TEST_DATASET, 'detected.aligned')) durationCorrect, totalLength = _evalAccuracy(annotationURI, detectedTokenList, whichTier=2 ) print durationCorrect / totalLength
def doitOneChunkAlign(URIrecordingNoExt, musicXMLParser, whichSentence, currSentence, withScores, withVocalPrediction): ''' align one chunk only. @param musicXMLParser: parsed score for whole recording @param whichSentence: sentence number to process ''' fromTs = currSentence[0] toTs = currSentence[1] listNonVocalFragments = [] if withVocalPrediction: listNonVocalFragments = getListNonVocalFragments(URIrecordingNoExt, fromTs, toTs) URIRecordingChunkNoExt = URIrecordingNoExt + "_" + str(fromTs) + '_' + str(toTs) if (withScores): tokenLevelAlignedSuffix = '.syllables_dur' else: tokenLevelAlignedSuffix = '.syllables' detectedAlignedfileName = URIRecordingChunkNoExt + tokenLevelAlignedSuffix fromSyllable = currSentence[2] toSyllable = currSentence[3] # already decoded if os.path.isfile(detectedAlignedfileName): print "{} already exists. No decoding".format(detectedAlignedfileName) detectedTokenList = readListOfListTextFile(detectedAlignedfileName) correctDuration, totalDuration = _evalAccuracy(URIrecordingNoExt + ANNOTATION_EXT, detectedTokenList, evalLevel, fromSyllable, toSyllable ) # correctDuration= 0; totalDuration=1 return correctDuration, totalDuration ###### 1) load Lyrics lyrics = loadLyricsFromTextGridSentence(currSentence) # if logger.level == logging.DEBUG: # lyrics.printSyllables() if withScores: # load from score instead lyrics = musicXMLParser.getLyricsForSection(whichSentence) # indexing in python withSynthesis = True # 2) load features lyricsWithModels, obsFeatures, dummyChunkURI = loadSmallAudioFragment(lyrics, URIrecordingNoExt, withSynthesis, fromTs, toTs) # lyricsWithModels.printWordsAndStates() ##### align usePersistentFiles = 'False' alpha = 0.97 from hmm.Parameters import Parameters ONLY_MIDDLE_STATE = False params = Parameters(alpha, ONLY_MIDDLE_STATE) alignmentErrors, detectedTokenList, detectedPath = alignOneChunk(obsFeatures, lyricsWithModels, listNonVocalFragments, alpha, evalLevel, usePersistentFiles, tokenLevelAlignedSuffix, URIRecordingChunkNoExt) correctDuration, totalDuration = _evalAccuracy(URIrecordingNoExt + ANNOTATION_EXT, detectedTokenList, evalLevel, fromSyllable, toSyllable ) acc = correctDuration / totalDuration print "result is: " + str(acc) return correctDuration, totalDuration