很抱歉,我上次使用这个网站是我第一次,我没有缩进我的代码。但是这次我尝试这样做。我希望代码是可以理解的。我正在研究由 Joshua Tauberer 编写的 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 n ih t pau g eh l v ae n ih k pau aa p l ay k pau
这些是从语音文件生成的音素。 pau 代表短暂的停顿。然后这个程序对这个输入进行音节化以产生如下输出:
s aa ' m ih ' k l eh k ' t aa ' n ih t ' g eh l ' v ae ' n ih ' k aa ' p l ay k
此输出是音节化版本。但是当我从输入文件中手动删除 pau 时,程序生成了这个输出。由于该程序只识别音素,而 pau 不是一个。所以我需要更改程序,从列表中删除所有现有的 pau。我在这里复制了程序的主要部分。我添加了行 text.remove("pau") 并尝试添加另一个 phoneme.remove("pau")。但是对于这两种情况,我都会收到一条错误消息:str object has no attribute 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
最佳答案
phoneme = phoneme.replace("pau", "")
关于python - 属性错误 : str has no attribute remove,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6747657/