Example #1
0
def runWithParameters(argv):
    
    if len(argv) != 6:
            print ("Tool to get alignment accuracy of of one jingju aria with different parameters ")
            print ("usage: {}   <pathToRecordings> <withScores> <deviation_INSeconds> <recordingName_noExtension> <withVocalPrediciton> ".format(argv[0]) )
            sys.exit()
    
    rootURI = argv[1]
#     rootURI = '/Users/joro/Documents/Phd/UPF/arias/'
    
#     URIrecordingNoExt =  rootURI + 'laosheng-erhuang_04'
#     URIrecordingNoExt =  rootURI + 'laosheng-xipi_02'
#     URIrecordingNoExt =  rootURI + 'dan-xipi_01'
#     URIrecordingNoExt =  rootURI + 'dan-xipi_02'

    URIrecordingNoExt = rootURI + argv[4]
    lyricsTextGrid = URIrecordingNoExt + '.TextGrid'

    # load total # different sentences + their rspective ts
#         fromTss, toTss = loadSectionTimeStamps(sectionAnnoURI)
    listSentences = divideIntoSentencesFromAnno(lyricsTextGrid) #uses TextGrid annotation to derive structure. TODO: instead of annotation, uses score
    
    withScores  = int(argv[2])
    ParametersAlgo.DEVIATION_IN_SEC = float(argv[3])
    musicXMLParser = None
    
    if withScores:
        musicXmlURI = URIrecordingNoExt + '_score.xml'
        musicXMLParser = MusicXMLParser(musicXmlURI, lyricsTextGrid)
    
    correctDuration = 0
    totalDuration = 0
    accuracyList = []
    
    withVocalPrediction = int(argv[5])
#     for whichSentence, currSentence in  reversed(list(enumerate(listSentences))):
    for whichSentence, currSentence in  enumerate(listSentences):
        currCorrectDuration, currTotalDuration = doitOneChunkAlign(URIrecordingNoExt, musicXMLParser,  whichSentence, currSentence, withScores, withVocalPrediction)  
        
        currAcc = currCorrectDuration / currTotalDuration
        accuracyList.append(currAcc)
        print "sentence {}: acc ={:.2f}".format(whichSentence, currAcc)
        
        correctDuration += currCorrectDuration
        totalDuration += currTotalDuration

##### TRICK: take only first three sentences:
#         if whichSentence == 2:
#             break
    print "final: {:.2f}".format(correctDuration / totalDuration * 100)     
    import matplotlib.pyplot as plt
    plt.plot(accuracyList, 'ro')
    plt.show()  
def doitOneChunkTest():
    '''
    meant to be run for withScores = 0
    '''
    URIrecordingNoExt = os.path.abspath('dan-xipi_01')
    URIrecordingNoExt = '/Users/joro/Documents/Phd/UPF/arias_dev_01_t_70/dan-xipi_02'
     
    lyricsTextGrid = URIrecordingNoExt + '.TextGrid'
    whichSentence = 0
         
    listSentences = divideIntoSentencesFromAnno(lyricsTextGrid) #uses TextGrid annotation to derive structure. TODO: instead of annotation, uses score
    musicXMLParser = 'dummy'
    sentence = listSentences[whichSentence]

#   meant to be run for withScores = 0
    withScores = 0
    withVocalPrediction = 0
    currCorrectDuration, currTotalDuration = doitOneChunkAlign(URIrecordingNoExt, musicXMLParser,  whichSentence, sentence, withScores, withVocalPrediction)  
 
    currAcc = currCorrectDuration / currTotalDuration
    print "sentence {}: acc ={:.2f}".format(whichSentence, currAcc)
Example #3
0
def runWithParameters(argv):

    if len(argv) != 6:
        print(
            "Tool to get alignment accuracy of jingu with different parameters. Sort all results according to tempo"
        )
        print(
            "usage: {}   <pathToRecordings> <withScores> <deviationINSec> <whichTempo>  <withVocalPrediction>"
            .format(argv[0]))
        sys.exit()

    rootURI = argv[1]
    #     rootURI = '/Users/joro/Documents/Phd/UPF/arias/'

    listRecordingURIs = [
        rootURI + 'laosheng-erhuang_04', rootURI + 'laosheng-xipi_02',
        rootURI + 'dan-xipi_01'
    ]
    withScores = int(argv[2])
    ParametersAlgo.DEVIATION_IN_SEC = float(argv[3])
    tempo = argv[4]
    withVocalPrediction = int(argv[5])

    # hard-code tempo sections for 3 arias
    tempiDict = {}
    tempiDict["slow"] = [(14, 202), (163, 173), ()]
    tempiDict["mid"] = [(212, 420), (29, 112), (11, 72)]
    tempiDict["fast"] = [(), (124, 161), (80, 423)]

    correctDuration = 0
    totalDuration = 0

    for i, URIrecordingNoExt in enumerate(listRecordingURIs):
        lyricsTextGrid = URIrecordingNoExt + '.TextGrid'
        tempoIndices = tempiDict[tempo][i]  # tempoIndices for the recording
        if len(tempoIndices) == 0:
            continue

        # load ts for different sentences
    #         fromTss, toTss = loadSectionTimeStamps(sectionAnnoURI)
        listSentences = divideIntoSentencesFromAnnoWithSil_andCreateLyrics(
            lyricsTextGrid)

        musicXMLParser = None

        if withScores:
            musicXmlURI = URIrecordingNoExt + '_score.xml'
            musicXMLParser = MusicXMLParser(musicXmlURI, lyricsTextGrid)

        for whichSentence, currSentence in enumerate(listSentences):
            currToSyllable = currSentence[3]
            print "currToSyllable {}".format(currToSyllable)

            if currToSyllable < tempoIndices[
                    0] - 1 or currToSyllable > tempoIndices[1] - 1:
                continue
            currCorrectDuration, currTotalDuration = doitOneChunkAlign(
                URIrecordingNoExt, lyricsTextGrid, musicXMLParser,
                whichSentence, currSentence, withScores, withVocalPrediction)
            currAcc = currCorrectDuration / currTotalDuration
            print "sentence {}: acc ={:.2f}".format(whichSentence, currAcc)
            correctDuration += currCorrectDuration
            totalDuration += currTotalDuration

    print "final: {:.2f}".format(correctDuration / totalDuration * 100)