C5W3 Trigger Word - Wrong segment. Expected: (7286, 8201) got:(7286, 8194)

Hello! I exported the files for the trigger word assignment and tried to run the notebook locally, but it fails with the following error:

Does anyone know how to fix it? Please note that I already submitted the assignment and received maximum score for it.


Hi @narcisap , welcome to the community!

Based on the output, I would suspect the “is_overlapping” function implementation. I suggest adding some print commands in these 2 functions (is_overlapping and insert_audio_clip) to keep track of the pointer (start and end).

Please try something like this and let me know how it goes.


Hi Juan! Thanks for the suggestion!

I think it might be more like a problem with the versions of python and/or dependences I use locally. All tests pass on Coursera (I’ve just rechecked), but not on my laptop, including this one for the insert_audio_clip method. My plan is to align my setup with the one on Coursera (downgrade to python 3.7, export the dependencies used on Coursera in a requirements.txt file and use it locally).

That makes sense. The versions may be impacting your results. Please keep me in the loop as to how it goes after you replicate the coursera stack.

Unfortunately, this approach was not successful. I couldn’t replicate the Coursera stack because of multiple errors I got while trying to install the requirements I exported from the notebook.

I also tried another approach: use python 3.7 and install just a subset of the dependencies (tensorflow 2.3.0, pydub 0.24.0, matplotlib 3.2.1, kiwisolver 1.2.0, Pillow - no version provided because of errors while trying to install the version used on the Coursera stack). With this approach, I get again the error Wrong segment. Expected: (7286, 8201) got:(7286, 8194).

What happens if you run it directly in Coursera? does it work?

If not: Could you send me a private message with your code? I’d like to take a look at it.

It works when I run it directly in Coursera and I received the maximum grade for this assignment.
The issue manifests itself only when I run it locally. I’ve just sent you my code in a private message. Looking forward to hearing back from you and thanks for looking into this! :slight_smile:

Thanks. I’ll check it out and see if I can spot the issue. Now, since it is working fine in Coursera, we know your code is fine. I’ll review the dependencies.


This also happens to me (insert_audio_clip locally fails but works on Coursera).

Also, my resulting clip is different.

Since it uses backgrounds and activatesand those are loaded from the OS, I guess the file listing (retrieving) is done in a different order and that creates the mismatch in the assert.

I guess the problem could be solved by sorting the results from os.listdir(*) in the load_raw_audio function (td_utils.py).

Please let me know if your idea works - thanks @Felipe_Caballero !

@Juan_Olano it does work. I just tested it by running a cell on Coursera with this code:

os.listdir('./raw_data/' + "activates"), os.listdir('./raw_data/' + "backgrounds"), os.listdir('./raw_data/' + "negatives")

which returns:

 ['2.wav', '1.wav'],

I then changed on my computer the result from os.listdir to this list and all asserts pass. That means that the order returned by os.listdir differs between my computer and Coursera.

So, the solution is to change the function load_raw_audio (on td_utils.py) to the following (notice that each os.listdir is enclosed by a sorted as sorted(os.listdir(***))):

# Load raw audio files for speech synthesis
def load_raw_audio(path):
    activates = []
    backgrounds = []
    negatives = []
    for filename in sorted(os.listdir(path + "activates")):
        if filename.endswith("wav"):
            activate = AudioSegment.from_wav(path + "activates/" + filename)
    for filename in sorted(os.listdir(path + "backgrounds")):
        if filename.endswith("wav"):
            background = AudioSegment.from_wav(path + "backgrounds/" + filename)
    for filename in sorted(os.listdir(path + "negatives")):
        if filename.endswith("wav"):
            negative = AudioSegment.from_wav(path + "negatives/" + filename)
    return activates, negatives, backgrounds

After doing this change you need to fix the asserts according to what you want to test. For instance in the the function def insert_audio_clip_test(target): (on notebook), you would need to change background[0] to background[1] and activates[0] to activates[7]. Also you should check other tests using an assert and some of the files created by the os.listdir.

It’s a very easy fix, hope you can implement it on production.

Thanks @Felipe_Caballero for getting back on this! Very clear. I’ll pass this information to the group in charge of this.

Thanks a lot!