Esempio n. 1
0
def doitOneChunk(argv):
    
    if len(argv) != 8 and  len(argv) != 9 :
            print ("usage: {}  <pathToComposition> <URI_recording_no_ext> <withDuration=True> <withSynthesis> <ALPHA> <ONLY_MIDDLE_STATE> <evalLevel> <usePersistentFiles=True>".format(argv[0]) )
            sys.exit();
    
    
    URIrecordingNoExt = argv[2]
    whichSection = getSectionNumberFromName(URIrecordingNoExt) 

    pathToComposition = argv[1]
    withDuration = argv[3]
    if withDuration=='True':
        withDuration = True
    elif withDuration=='False':
        withDuration = False
    else: 
        sys.exit("withDuration can be only True or False")  
    
    withSynthesis = argv[4]
    if withSynthesis=='True':
        withSynthesis = True
    elif withSynthesis=='False':
        withSynthesis = False
    else: 
        sys.exit("withSynthesis can be only True or False")  
    
    
    ALPHA = float(argv[5])
    ONLY_MIDDLE_STATE = argv[6]
    
    evalLevel = tierAliases.wordLevel
    evalLevel = int(argv[7])

    params = Parameters(ALPHA, ONLY_MIDDLE_STATE)
    
    usePersistentFiles = 'True'
    if len(argv) == 9:
        usePersistentFiles =  argv[8]
    
    
    set_printoptions(threshold='nan') 
    
    ################## load lyrics and models 
    htkParser = None
    if withDuration:
        htkParser = HtkConverter()
        htkParser.load(MODEL_URI, HMM_LIST_URI)
    
    alignmentErrors, detectedWordList, grTruthDurationWordList, detectedAlignedfileName = alignDependingOnWithDuration(URIrecordingNoExt, whichSection, pathToComposition, withDuration, withSynthesis, evalLevel, params, usePersistentFiles, htkParser)
        
        
    mean, stDev, median = getMeanAndStDevError(alignmentErrors)
#     writeListOfListToTextFile(detectedWordList, None, '/Users/joro/Downloads/test.txt')
    logger.info("mean : {} st dev: {} ".format( mean,stDev))
Esempio n. 2
0
def loadSmallAudioFragment(lyrics, URIrecordingNoExt, withSynthesis, fromTs=-1, toTs=-1):
    '''
    test duration-explicit HMM with audio features from real recording and htk-loaded model
    asserts it works. no results provided 
    '''
 
     
    htkParser = HtkConverter()
    htkParser.load(MODEL_URI, HMM_LIST_URI)
    lyricsWithModels = LyricsWithModels(lyrics, htkParser, 'False')
     
    observationFeatures = loadMFCCs(URIrecordingNoExt, withSynthesis, fromTs, toTs) #     observationFeatures = observationFeatures[0:1000]
     
    lyricsWithModels.duration2numFrameDuration(observationFeatures, URIrecordingNoExt)
#     lyricsWithModels.printWordsAndStates()
    
    return lyricsWithModels, observationFeatures
def loadModelsForGivenPhoneme(modelBefore, modelAfter, phonemeName):

    # load models
    conv_before = HtkConverter()
    conv_before.load(modelBefore, HMM_LIST_URI)
    conv_after = HtkConverter()
    conv_after.load(modelAfter, HMM_LIST_URI)

    # get models for given phoneme:

    hmmModels = [hmm for hmm in conv_before.hmms if hmm.name == phonemeName]
    hmmModel1 = hmmModels[0]
    hmmModels = [hmm for hmm in conv_after.hmms if hmm.name == phonemeName]
    hmmModel2 = hmmModels[0]
    return hmmModel1, hmmModel2
def loadModelsForGivenPhoneme(modelBefore, modelAfter, phonemeName):
    
    
    # load models
    conv_before = HtkConverter()
    conv_before.load(modelBefore, HMM_LIST_URI)
    conv_after = HtkConverter()
    conv_after.load(modelAfter, HMM_LIST_URI)
    
    # get models for given phoneme:
   
    hmmModels = [hmm for hmm in conv_before.hmms if hmm.name == phonemeName]
    hmmModel1 = hmmModels[0]
    hmmModels = [hmm for hmm in conv_after.hmms if hmm.name == phonemeName]
    hmmModel2 = hmmModels[0]
    return hmmModel1, hmmModel2
            output = output + str(element) + "\t"
        output = output.strip()
        output = output + '\n'
        outputFileHandle.write(output)
    
        outputFileHandle.close()




if __name__ == '__main__':
#     findDiffMean(phonemeName)

    
    
    conv_before = HtkConverter()
    conv_before.load(MODEL_URI, HMM_LIST_URI)
    
    # one phoneme
    phonemeName = 'A'
    hmmModels = [hmm for hmm in conv_before.hmms if hmm.name == phonemeName]
    hmmModel1 = hmmModels[0]
    
    # all phonemes
    for currHmmModel in conv_before.hmms:
#         printModelsMiddleState(currHmmModel, PATH_TO_HMMLIST);
        
        printModelsAllStates(currHmmModel, PATH_TO_HMMLIST);


def doitOneRecording(argv):
    '''
    for a list of recordings, select those which name contains pattern and evlauate total error 
    ''' 
    if len(argv) != 9 and  len(argv) != 10 :
            print ("usage: {}  <pathToComposition>  <pathToRecordings> <pattern> <withDuration=True/False> <withSynthesis> <ALPHA>  <ONLY_MIDDLE_STATE> <evalLevel> <usePersistentFiles=True> ".format(argv[0]) )
            sys.exit();
    
    os.chdir(argv[2])
    
    
        
# get annot files with starting pattern
    pattern = argv[3] + '*'   + AUDIO_EXT
    listAudioFilesAll = glob.glob(pattern) 
        

    for i in range(len(listAudioFilesAll)) :
        listAudioFilesAll[i] = os.path.join(argv[2], listAudioFilesAll[i])
        
#     listAudioFiles = []
#         if not isfile( os.path.splitext(listAudioFilesAll[i])[0] +  ".notUsed"):
#             listAudioFiles.append(listAudioFilesAll[i])
    listAudioFiles = listAudioFilesAll
    
    for file in listAudioFiles:
        logger.debug(file)
        
    pathToComposition  = argv[1]
    withDuration = argv[4]
    if withDuration=='True':
        withDuration = True
    elif withDuration=='False':
        withDuration = False
    else: 
        sys.exit("withDuration can be only True or False")  
    
    withSynthesis = argv[5]
    if withSynthesis=='True':
        withSynthesis = True
    elif withSynthesis=='False':
        withSynthesis = False
    else: 
        sys.exit("withSynthesis can be only True or False")  

    
        
    ALPHA = float(argv[6])
    
     
    ONLY_MIDDLE_STATE = argv[7]
    
    params = Parameters(ALPHA, ONLY_MIDDLE_STATE)
    
    evalLevel = int(argv[8])
    
    usePersistentFiles = 'True'
    if len(argv) == 10:
        usePersistentFiles =  argv[9]
        
         
    totalErrors = []
    
    htkParser = None
    if withDuration:
        htkParser = HtkConverter()
        htkParser.load(MODEL_URI, HMM_LIST_URI)
    
    for  URI_annotation in listAudioFiles :
            URIrecordingNoExt  = os.path.splitext(URI_annotation)[0]
            logger.debug("PROCESSING {}".format(URIrecordingNoExt) )
            whichSection = getSectionNumberFromName(URIrecordingNoExt) 
            
            currAlignmentErrors, detectedWordList, grTruthDurationWordList, detectedAlignedfileName = alignDependingOnWithDuration(URIrecordingNoExt, whichSection, pathToComposition, withDuration, withSynthesis, evalLevel, params, usePersistentFiles, htkParser)

            totalErrors.extend(currAlignmentErrors)
            
#             visualiseInPraat(URIrecordingNoExt, withDuration, detectedWordList, grTruthDurationWordList)

    mean = []
    stDev =  []     
    if len(totalErrors) != 0:    
        mean, stDev, median = getMeanAndStDevError(totalErrors)
        infoA = "Total  mean: "  "," +  str(mean), ", st dev: " + str(stDev) +   " ALPHA: " +  str(ALPHA)

        logger.info(infoA)
    return mean, stDev, totalErrors
    if not headerLine == None:
        outputFileHandle.write(headerLine)

    output = ""
    for element in inputList:
        output = output + str(element) + "\t"
    output = output.strip()
    output = output + '\n'
    outputFileHandle.write(output)

    outputFileHandle.close()


if __name__ == '__main__':
    #     findDiffMean(phonemeName)

    conv_before = HtkConverter()
    conv_before.load(MODEL_URI, HMM_LIST_URI)

    # one phoneme
    phonemeName = 'A'
    hmmModels = [hmm for hmm in conv_before.hmms if hmm.name == phonemeName]
    hmmModel1 = hmmModels[0]

    # all phonemes
    for currHmmModel in conv_before.hmms:
        #         printModelsMiddleState(currHmmModel, PATH_TO_HMMLIST);

        printModelsAllStates(currHmmModel, PATH_TO_HMMLIST)