Course 5 week 3 project 2

Just getting into the Trigger Word Detection project. I looked on here for any post about this assignment so I figured I would start a post about it before i start googling and running down rabbit holes when I am just over-complicating it.

For the first function we have to fill in

Insert Audio clip

I am unsure about the first block of code we fill in:


# Step 1: Use one of the helper functions to pick a random time segment onto which to insert 
# the new audio clip. (≈ 1 line)
segment_time = None

# Step 2: Check if the new segment_time overlaps with one of the previous_segments. If so, keep 
# picking new segment_time at random until it doesn't overlap. To avoid an endless loop
# we retry 5 times(≈ 2 lines)
retry = 5 # @KEEP 
while None and retry >= 0:
    segment_time = None
    retry = retry - 1

What helper do we use to get the initial setting of


I want to use

get_random_time_segment, but when i pass in either one of the parameters i get errors both ways. I know my issue is how i am setting the


variable. But i am completely unsure of what to do with the while loop. Do i just do

while segment_time = None and retries >= 0:

or does something else go into the “None” spot in the while loop.

I hope with that info I will be able to get through the start, but like i said, i am not sure of myself, and I wanted to start a thread for this project before i start searching forums.

This is the error is this:

AssertionError: The segment length must match the audio clip length

After my while statement i print the 'segment_time" and get this:

(3046, 3961)

but the output of my function it goes into the else block which is why it is returning the wrong length.

(<pydub.audio_segment.AudioSegment at 0x7f381644b250>, (10000, 10000))

So there is overlap i assume in my time segments leading me back to the while loop.

Ok so my while loop is fixed. Re read the instructions for the n tenth time and got it right. Now im still getting that error but it is in my if statement:

if not is_overlapping(segment_time, previous_segments):

it is with how i am setting segement_time.

I got an error when i put in segment_ms, so i am thinking i have to put in the previous_segments and index it, but i cant seem to find a combination that works. Tried 0 and -1 in both layers of the previous_segments.

Maybe i am way off base? Im not really sure.

Walked away for awhile and came back to look at it. Found a couple of things that confused me when i re read them again. Is the segment_time variable supposed to be a list or a tuple? i have

segment_time = get_random_time_segment(segment_ms)

in the directions it says

Append the new time segment to the list of existing time segments

But in the set up for the code it had segment_time = None. Do we set it to an empty list?

When its a list or tuple, i get an error on this line:

# Step 4: Superpose audio segment and background
    new_background = background.overlay(audio_clip, position = segment_time)

Which is provided for us, tries to subtract audio_clip from segment_time and its giving me the error:

TypeError: '<' not supported between instances of 'int' and 'tuple'

if i pass in an integer instead of the tuple i get an error from the unit test:

<ipython-input-59-6029f05af541> in insert_audio_clip_test(target) 4 
audio_clip, segment_time = target(backgrounds[0], activates[0], [(0, 4400)])    
5     print(segment_time)
----> 6     duration = segment_time[1] - segment_time[0]
7     assert segment_time[0] > 4400, "Error: The audio clip is overlaping with the first segment"
8     assert duration + 1 == len(activates[0]) , "The segment length must match the audio clip length"

TypeError: 'int' object is not subscriptable

Ok. I got 100/100 on it but i do not know why. I changed something outside of the code block to get the first function working. And my create_training_example function does not pass the unit tests in the notebook. I should not have passed in my opinion but i cant do any better than 100/100 so I guess i’ll just have to take it.