开发者

working with a big list

I have written this code which is,

param_values = {
      'aa' : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.15,1.0], [-1,-1]],     
      'ae' : [[-1,-1], [-1,-1], [0.3,0.4], [-1,-1], [0.15,1.0], [-1,-1]], 
      'ah' : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.15,1.0], [-1,-1]], 
      'ao' : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.3,1.0], [-1,-1]], 
      'b'  : [[-1,-1], [0.2,1.0], [-1,-1], [-1,-1], [0.15,0.2], [-1,-1]], 
      'ch' : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.15,0.4], [-1,-1]], 
      'd'  : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.15,0.4], [-1,-1]], 
      'dh' : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.15,0.35], [-1,-1]], 
      'dx' : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.15,0.35], [-1,-1]], 
      'eh' : [[-1,-1], [-1,-1], [0.1,0.5], [-1,-1], [0.4,0.7], [-1,-1]], 
      'er' : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.15,0.5], [-1,-1]], 
      'ey' : [[-1,-1], [开发者_运维百科-1,-1], [0.3,1.0], [-1,-1], [0.3,0.5], [-1,-1]], 
      'f'  : [[0.5,1.0], [-1,-1], [-1,-1], [-1,-1], [-1,-1], [-1,-1]], 
      'g'  : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.15,0.8], [-1,-1]], 
      'hh' : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.15,0.8], [-1,-1]], 
      'ih' : [[-1,-1], [-1,-1], [0.3,1.0], [-1,-1], [0.05,0.15], [-1,-1]], 
      'iy' : [[-1,-1], [-1,-1], [0.3,1.0], [-1,-1], [0.1,0.15], [-1,-1]], 
      'jh' : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.15,0.6], [-1,-1]], 
      'k'  : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.15,0.8], [-1,-1]], 
      'l'  : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.15,0.6], [-1,-1]], 
      'm'  : [[-1,-1], [0.2,1.0], [-1,-1], [-1,-1], [0.15,0.2], [-1,-1]], 
      'n'  : [[-1,-1], [-1,-1], [-1,-1], [0.3,1.0], [-1,-1], [-1,-1]], 
      'ng' : [[-1,-1], [-1,-1], [0.3,1.0], [-1,-1], [0.09,0.3], [-1,-1]], 
      'p'  : [[-1,-1], [0.2,1.0], [-1,-1], [-1,-1], [0.15,0.2], [-1,-1]], 
      'r'  : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.15,0.6], [-1,-1]], 
      's'  : [[-1,-1], [-1,-1], [-1,-1], [0.3,1.0], [-1,-1], [-1,-1]],
      'sh' : [[-1,-1], [-1,-1], [-1,-1], [0.3,1.0], [-1,-1], [-1,-1]], 
      't'  : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.15,0.4], [-1,-1]], 
      'th' : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.15,0.2], [-1,-1]], 
      'uh' : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.5,1.0]], 
      'uw' : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.5,1.0]], 
      'v'  : [[0.5,1.0], [-1,-1], [-1,-1], [-1,-1], [-1,-1], [-1,-1]], 
      'w'  : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.2,1.0]], 
      'y'  : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.15,0.4], [-1,-1]],  
      'z'  : [[-1,-1], [-1,-1], [-1,-1], [0.3,1.0], [-1,-1], [-1,-1]], 
      'zh' : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.15,0.6], [-1,-1]], 
      'o'  : [[-1,-1], [-1,-1], [-1,-1], [-1,-1], [-1,-1], [0.4,1.0]]
     }

def coart(phonemeFile) :
    """ Coarticulation function where forward and backward coarticulation take place a  and parameter values are generated"""
    with open("syllabifiedPhonemes.txt", "r") as pFile :
        for line in pFile :
            line = line.split()
            if line == "'" :
                continue

param_values is the list of phonemes which has the corresponding lists of each phoneme. The list each phoneme has, relates to a blend shape slider value I got from Maya. I have 6 blendshapes in Maya which are lower_lip_under_upper_teeth,lips_touch,lips_spread, teeth touch,jaw_open and lips_round. So these values are the ranges which a phoneme has for each slider value.

[-1,-1] indicates that particular blendshape is not in use. And the other values are the ranges in which the shapes can move.

The list shows, mostly its just a single lip shape that is active for one phoneme and the rest of them are [-1,-1]. But for some phonemes there are 2 or 3 lip shapes active at the same time. I have manually animated them in Maya. The values for lip shape varies from 0 to 1.

The contents of the input file, syllabifiedPhonemes.txt is,

sh iy ' hh eh ' t er ' t aa r k ' s uw t n ' k r iy s ' hh iy ' w aa ' sh w aa dx ' er ' l ih ' y er

The program should go through all of these phonemes in the file and set the values of its corresponding lip shapes by referring to the list above. Those values should be stored so that further work can be carried out. The single quote represents syllable boundaries. At first the program should go through the phonemes ignoring syllable boundaries and save their lip shape values for all the shapes. Then in the next stage it should start looking inside each boundary.

So far I only have this but I am blank on how to proceed further. I guess I have explained my query properly. Thank you.

The values are the ones for the shapes present inside the shapes list. Could anyone help please. Thank you.


First, some notes ...

  • You missed a comma at the end of the 'zh' line in the dictionary.
  • "tFile" should be "pFile", right?
  • Shouldn't

    if line == " ' ":

    be

    if line =="'":

How about this? ...

def coart(phonemeFile) :
    """ Coarticulation function where forward and backward coarticulation take place a  and parameter values are generated"""

    all_lines = []
    with open(phonemeFile, "r") as pFile :
        for line in pFile :
            next_line = []
            line = line.split()
            for syllable in line:           
                if syllable == "'" :
                    continue
                next_coart = param_values.get(syllable)
                next_line.append( (syllable, next_coart) )
            all_lines.append(next_line)


probably something like this would work:

def coart(phonemeFile) :

    results = {}

    f = open("syllabifiedPhonemes.txt", "r")
    for line in f.readlines():
      syllables = line.split("'") 
      for syllable in syllables:
        phonemes = list(map( lambda x: x.strip(), syllable.split()))
        data = []
        for phoneme in phonemes:
          data.append( param_values[phoneme] )

        results[' '.join(phonemes)] =  data    

    print(results)
    f.close()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜