But in create_training_example function, we are adding 4 random_activate to same background. Everytime insert_audio_clip is called for each of 4 random_activate , the previous_segments passed is to this function is an empty list.
previous_segments is never returned and updated, when it is passed to insert_audio_clip function with next random_activate.
previous_segments is not a global variable. It is defined inside create_training_example. As mentioned in my previous reply, the function insert_audio_clip updates the variable. Python lists are passed by reference and not by value. Since we are interested in the actual training example, there’s no need to return previous_segment corresponding to the constructed x, y pair.
Here are the segment times stored inside previous_segment as part of the test: