我写了这段代码,
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获得的混合形状滑块值有关。我在Maya中有6个混合形状,分别是lower_lip_under_upper_teeth,lips_touch,lips_spread,牙齿触摸,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 :(得分:2)
首先,一些注释......
不应该
如果行==“'”:
是
如果行==“'”:
这个怎么样? ...
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)
答案 1 :(得分: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()