Week 3 - Assignment 2 (#DLS # Course 5)

In the function “create_training_example”

“previous_segment” list is not updated everytime it loops throught “random_activates” list.

So when positive audio sample are added to the background sample, a later audio sample might replace a previously added positive audio sample.

Is it okay?

insert_audio_clip updates previous_segments to avoid overlap of the audio signals inserted over background.

Yes, insert_audio_clip updates previous_segments.

Is previous_segments a global variable?

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.

Am I missing something here?

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:

(2885, 3793)
(1726, 2450)
(6882, 7460

Thanks! I was missing the following part
“Python lists are passed by reference and not by value”.

Thanks again for clarification!

1 Like