r/moviepy • u/Equal_Eye_346 • 22d ago
compute_position error when passing "with_position(width,height)" to TextClip
Working on something to visualize pronunciation of written indigenous languages. Not a python expert ..
Syllables in a word presented as individual textclips. A word is presented as a series of textclips. As recorded word audio is spoken, each syllable textclip changes its appearance corresponding to when it is spoken.
I need to graphically position the clips (left to right for the language I work with)
I'm trying to create a list of TextClip objects from a class inheriting TextClip in a loop.
I can pass text, start and end duration variables without issue. But when I pass with_position parameters in my loop I get a compute_position error:
tools.py", line 289, in compute_position pos = list(pos)
"TypeError: 'int' object is not iterable
I use the [-1] tool to identify eachTextGrid item as they are created and get its width.
I use this width to set the x position of the next TextGrid item.
BUT doing this creates an error.
I confirmed that data passed are integers,
I can setup the position values within the nested array, that I use to hold to test values without generating an error
but the long term goal is to be able to pass both the text, the syllables and their timing as a praat textgrid file, and use MoviePy to figure out and set their positioning.
And pass a spoken word audio file that has had its syllable pronunciation timing documented with Praat. https://www.fon.hum.uva.nl/praat/, https://pypi.org/project/praatio/
My goal is a MoviePy script that generates video illustration of a words pronunciation as the word is spoken, by passing the audio file and an appropriate textgrid file.
Many/most indigenous languages use sounds (phonemes) not used in western languages and represent them with different sets of lettering, graphemes or syllabics, depending on the language. MoviePy could offer a way of illustrating this by changing the visual parameters of a TextClip, or overlaying differently configured TextClips as a word is spoken.
My testing code is:
font_size = 42
class Syltext(TextClip): # a class for the syllable presentation
def __init__(self,*args, **kwargs):
super().__init__(
font_size = font_size,
color="black",
stroke_color="black",
bg_color="white",
stroke_width=2,
*args, **kwargs
)
mtrix = [ #array to hold syllable data (will be replaced with passing Praat textgrid data)
[.5,2,"Must'"],#start time, duration, text
[2,2,"i'"],
[4,1.5,"muhw"]
]
#Must'i'muhw - People
cliplist = [] # a list to hold all the clips
sylw = 0 #width position of syllables, start at zero, increment by width of syllables
totw = 0 #variable for total width, taken from last syllable width
for i in range (3):
#put syllable clips in a list of Syltext objects
cliplist.append(Syltext(text=(mtrix[i][2])).with_start(mtrix[i][0]).with_duration(mtrix[i][1]).with_position(sylw,100))
sylw = cliplist[-1].w # get width of last syllable created
if i == 2:
totw = cliplist[-1].w # get the total width of the entire word.
bgclip = ColorClip(size =(totw,100),color = white ,duration = 6) # a background clip with size, color and duration
cliplist.insert(0,bgclip) # add the color clip to 1st in clip list
audioclip = AudioFileClip("audio.wav")
video = CompositeVideoClip(cliplist)
video.preview()
final = video.with_audio(audioclip)
final.write_videofile("videofile.mp4",fps=12,audio_codec="aac")


