2011-08-03 36 views
0

我寫了這個代碼,這是工作,有一個大名單

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是具有每個音素的相應名單音素的列表。每個音素都有的列表涉及到我從Maya獲得的混合形狀滑塊值。我在瑪雅有6種混合形狀,分別是lower_lip_under_upper_teeth,lips_touch,lips_spread,tooth touch,jaw_open和lips_round。所以這些值是音素對每個滑塊值的範圍。

[-1,-1]表示特定的混合形狀未被使用。其他值是形狀可以移動的範圍。

該列表顯示了,其中大部分只是其中一個音素處於活動狀態的單脣形狀,其餘部分都是[-1,-1]。但對於一些音位,同時有2或3個脣形活動。我已經在Maya中手動對它們進行了動畫處理。脣形狀的值從0變化到1。

輸入文件的內容,是syllabifiedPhonemes.txt,

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 

方案應經過的所有文件中的這些音素的和設置的值通過參考上面的列表來查看其對應的脣形。應該存儲這些值,以便進一步開展工作。單引號代表音節邊界。首先,程序應該通過忽略音節邊界的音素並保存所有形狀的脣形值。然後在下一階段,它應該開始尋找每個邊界內。

到目前爲止,我只有這一點,但我對如何進一步進行了空白。我想我已經正確解釋了我的查詢。謝謝。

這些值是形狀列表中存在的形狀的值。任何人都可以幫忙請。謝謝。

+0

這功課嗎? – wberry

+0

這是我的項目。我是Python的初學者。 – zingy

回答

2

首先,一些筆記...

  • 你在字典中的「深航行的結尾錯過了一個逗號。
  • 「tFile」應該是「pFile」,對吧?
  • 不應該

    如果線== 「 ' 」:

    如果線==「'」:

這個怎麼樣? ...

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) 
+0

這工作完美。感謝您的更正。 – zingy

+0

現在我收到了更多與此相關的問題。我是否有帖子的另一個問題,或者我必須編輯我的問題? – zingy

+0

另外,當我得到新的列表時,十進制值比全局列表中的長。新的列表從那裏開始,那價值如何變化? – zingy

0

可能像這樣的工作:

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

謝謝你的作品 – zingy