C5W3 Assignment 2 - Exercice 2

I did this exercise sucessfuly and I got the ‘All tests passed!’ message but when I run the subsequent cell I got an error message.

np.random.seed(5)
audio_clip, segment_time = insert_audio_clip(backgrounds[0], activates[0], [(3790, 4400)])
audio_clip.export(“insert_test.wav”, format=“wav”)
print("Segment Time: ", segment_time)
IPython.display.Audio(“insert_test.wav”)


RecursionError Traceback (most recent call last)
in
1 np.random.seed(5)
----> 2 audio_clip, segment_time = insert_audio_clip(backgrounds[0], activates[0], [(3790, 4400)])
3 audio_clip.export(“insert_test.wav”, format=“wav”)
4 print("Segment Time: ", segment_time)
5 IPython.display.Audio(“insert_test.wav”)

in insert_audio_clip(background, audio_clip, previous_segments)
37 ### START CODE HERE ###
38 # Step 3: Append the new segment_time to the list of previous_segments (≈ 1 line)
—> 39 insert_audio_clip(background, audio_clip, previous_segments)
40 ### END CODE HERE ###
41 # Step 4: Superpose audio segment and background

… last 1 frames repeated, from the frame below …

in insert_audio_clip(background, audio_clip, previous_segments)
37 ### START CODE HERE ###
38 # Step 3: Append the new segment_time to the list of previous_segments (≈ 1 line)
—> 39 insert_audio_clip(background, audio_clip, previous_segments)
40 ### END CODE HERE ###
41 # Step 4: Superpose audio segment and background

RecursionError: maximum recursion depth exceeded while calling a Python object

Can anyone tell me why this is happening?

HI @Dalton_Lintz

There is in the step 3 in function insert_audio_clip() because you should append the segment_time that you got in the list previous_segments because this keeps track of all the segments you’ve inserted.

Cheers!
Abdelrahman

The “max recursion depth” error means that you’ve written code that calls itself. That’s a bad thing.

I fix it and it is fine now.

Thank you