Course 5 Week 3 Assignment 2 Exercise 4 Create Training Example- Trigger Word Detection v2a

All of my previous exercises in this assignment pass {overlapping, insert_audio, insert_ones} but exercise 4 {create_training example} blows up during unit testing.

AttributeError                            Traceback (most recent call last)
<ipython-input-112-6643a2b10ec5> in <module>
     17     print("\033[92m All tests passed!")
     18 
---> 19 create_training_example_test(create_training_example)

<ipython-input-112-6643a2b10ec5> in create_training_example_test(target)
      2 def create_training_example_test(target):
      3     np.random.seed(18)
----> 4     x, y = target(backgrounds[0], activates, negatives, 1375)
      5 
      6     assert type(x) == np.ndarray, "Wrong type for x"

<ipython-input-103-b85b4cc64b72> in create_training_example(background, activates, negatives, Ty)
     38         # Insert the audio clip on the background
     39         # insert_audio_clip(background, audio_clip, previous_segments)
---> 40         background, segment_time = insert_audio_clip(background, random_activates, previous_segments)
     41         # Retrieve segment_start and segment_end from segment_time
     42         segment_start, segment_end = segment_time

<ipython-input-111-01c3c5cfc345> in insert_audio_clip(background, audio_clip, previous_segments)
     43         # Step 4: Superpose audio segment and background
     44         print("creating new_background")
---> 45         new_background = background.overlay(audio_clip, position = segment_time[0])
     46         print("new_background created")
     47     else:

/opt/conda/lib/python3.7/site-packages/pydub/audio_segment.py in overlay(self, seg, position, loop, times, gain_during_overlay)
   1151         output = StringIO()
   1152 
-> 1153         seg1, seg2 = AudioSegment._sync(self, seg)
   1154         sample_width = seg1.sample_width
   1155         spawn = seg1._spawn

/opt/conda/lib/python3.7/site-packages/pydub/audio_segment.py in _sync(cls, *segs)
    434     @classmethod
    435     def _sync(cls, *segs):
--> 436         channels = max(seg.channels for seg in segs)
    437         frame_rate = max(seg.frame_rate for seg in segs)
    438         sample_width = max(seg.sample_width for seg in segs)

/opt/conda/lib/python3.7/site-packages/pydub/audio_segment.py in <genexpr>(.0)
    434     @classmethod
    435     def _sync(cls, *segs):
--> 436         channels = max(seg.channels for seg in segs)
    437         frame_rate = max(seg.frame_rate for seg in segs)
    438         sample_width = max(seg.sample_width for seg in segs)

AttributeError: 'list' object has no attribute 'channels'

I’m not really doing anything in insert_audio_clip other than previous_segments.append(…)

It does seem that the empty list scenario is somehow broken. Any insights would be appreciated.

A little extra detail, it is blowing up in insert_audio_clip but at part of the provided code, specifically; new_background = background.overlay(audio_clip, position = segment_time[0])

RESOLVED
I was passing random_activates and random_negatives to insert_audio_clip.

1 Like

Hi,
I got same error. What do you mean about “passing random_activates and random_negatives to insert_audio_clip”? Shouldn’t it be random_activates and random_negatives?

For anyone interested, it should be random_activate, not random_activates, as the latter is a list.