1. Learn
  2. /
  3. Courses
  4. /
  5. Spoken Language Processing in Python

Exercise

Chopping and changing audio files

Some of your audio files may have sections of redundancy. For example, you might find at the beginning of each file, there's a few seconds of static.

Instead of wasting compute trying to transcribe static, you can remove it.

Since an AudioSegment is iterable, and measured in milliseconds, you can use slicing to alter the length.

To get the first 3-seconds of wav_file, you'd use wav_file[:3000].

You can also add two AudioSegment's together using the addition operator. This is helpful if you need to combine several audio files.

To practice both of these, we're going to remove the first four seconds of part1.wav, and add the remainder to part2.wav. Leaving the end result sounding like part_3.wav.

Instructions

100 XP
  • Import part_1.wav and part_2.wav and save them to part_1 and part_2 respectively.
  • Remove the first 4-seconds of part_1 using slicing and save the new audio to part_1_removed.
  • Add part_1_removed to part_2 and save it to part_3.