很抱歉,上次我使用这个网站是我第一次,我没有缩进我的代码和所有。但这一次我试着这么做。我希望密码是可以理解的。我正在编写一个python程序syllabifier.py,它是由乔舒亚·陶伯尔编写的,可以从https://p2tk.svn.sourceforge.net/svnrooot/p2tk/python/syllabify/syllabifier.py获得。这个程序是免费使用的,而且我在我的项目中引用了源代码。我正在使用这个程序来音节的音素列表,我有一个输入。此程序接受一个输入文件,其内容如下:
pau s aa m ih k l eh k t aa t pau g h l v ae n ih k aa p l ay k
这些是从语音文件中生成的音素。pau代表短暂的停顿。然后,这个程序音节化这个输入,以产生如下的输出:
s aa是ih‘k l eh k t aa’g h l‘v ae n k aa’p l l k
这个输出是音节版本。但是当我从输入文件中手动删除pau时,程序生成了这个输出。因为程序只识别音素,所以pau不是一个音素。因此,我需要在程序中做一个改变,从列表中删除所有现有的pau。我在这里复制了程序的主要部分。我添加了text.remove("pau")行,并添加了另一个行,即phoneme.remove("pau")。但是在这两种情况下,我都会看到一个错误: str对象没有属性remove。我不明白我哪里出了问题。请帮帮忙。非常感谢。
def syllabify(language, text) :
text.remove("pau")
if type(text) == str :
text = text.split()
syllables = [] # This is the returned data structure.
internuclei = [] # This maintains a list of phonemes between nuclei.
for phoneme in text :
#phoneme.remove("pau")
phoneme = phoneme.strip()
if phoneme == "" :
continue
stress = None发布于 2011-07-19 13:25:44
def syllabify(language, text) :
#These lines will take any list of phonemes or string of phonemes
#and strip all of the whitespace and 'pau's
#and won't return any empty phonemes
if type(text) is not str:
text = ' '.join(text)
text.replace("pau", "")
text = text.split()
syllables = [] # This is the returned data structure.
internuclei = [] # This maintains a list of phonemes between nuclei.
for phoneme in text:
# so you don't have to check for empty phonemes,
# delete 'pau's, or strip whitespace here
stress = None
# whatever else you do发布于 2011-07-19 13:09:54
phoneme = phoneme.replace("pau", "")https://stackoverflow.com/questions/6747657
复制相似问题