attribute error : str has no attribute remove
I am sorry the last time I had used this website was my first time and I did not indent my code and all. But this time I tried to do so. I hope the code is understandable. I am working on a python program syllabifier.py written by Joshua Tauberer available from https://p2tk.svn.sourceforge.net/svnrooot/p2tk/python/syllabify/syllabifier.py. This progra开发者_如何学Pythonm is free to use and also I have referenced the source in my project. I am using this program to syllabify the list of phonemes I have as an input. This program takes in an input file whose contents is like the following:
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
These are the phonemes generated from a speech file. pau stands for short pauses. Then this program syllabifies this input to produce an output like the following :
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
This output is the syllabified version. But the program generated this output when I manually deleted pau from the input file. As the program only recognizes phonemes and pau is not one. So I need to make a change in the program that would delete all existing pau from the list. I have copied here the main part of the program. I added the lines text.remove("pau") and also tried by adding another one which is phoneme.remove("pau"). But with both cases I get an error saying: str object has no attribute remove. I do not understand where am I going wrong. Please help. Thank you very much.
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", "")
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
精彩评论