@@ -0,0 +1,2417 @@
+import wave%0Aimport audioop%0Aimport sys%0Aimport os%0Aimport math%0A%0Afrom pydub import AudioSegment%0A%0A%0Adef sampleIndexToSeconds(index, chunk_size, rate):%0A    return index * (chunk_size) / rate%0A%0Adef printTime(timeInSeconds):%0A    seconds = timeInSeconds %25 60%0A    minutes = timeInSeconds / 60%0A%0A    if seconds %3C 10:%0A        sys.stdout.write('%7B%7D:0%7B%7D '.format(minutes, seconds))%0A    else:%0A        sys.stdout.write('%7B%7D:%7B%7D '.format(minutes, seconds))%0A%0A%0A%0Aif __name__ == %22__main__%22:%0A    %22%22%22%0A        This should be ran with a single arguement which is the path to mp3 file that needs to be segmented%0A    %22%22%22%0A    mp3Name = sys.argv%5B1%5D%0A    wavName = mp3Name%5B:-4%5D + '.wav'%0A%0A    song = AudioSegment.from_mp3(mp3Name)%0A    song.export(wavName, format='wav')%0A%0A    wav = wave.open(wavName, 'r')%0A%0A    frames = wav.getnframes()%0A    rate = wav.getframerate()%0A    width = wav.getsampwidth()%0A%0A    numSeconds = frames / float(rate)%0A%0A    THRESHOLD = 50%0A    CHUNK_SIZE = 64%0A%0A    rms_vals = %5B%5D%0A%0A    for chunk_num in range(frames/CHUNK_SIZE):%0A        sample = wav.readframes(CHUNK_SIZE)%0A        rms_vals.append(audioop.rms(sample, width))%0A%0A    longest_start = 0%0A    longest_end = 0%0A%0A    cur_len = 0%0A    cur_start = 0%0A%0A    segment_count = 0%0A    while(True):%0A        longest_len = 0%0A        start_search = longest_end + (240 * rate / CHUNK_SIZE)%0A        end_search = start_search + (120 * rate / CHUNK_SIZE)%0A%0A        start_time = sampleIndexToSeconds(start_search, CHUNK_SIZE, rate)%0A        end_time = sampleIndexToSeconds(end_search, CHUNK_SIZE, rate)%0A%0A        if start_time %3E numSeconds or (start_time %3C= numSeconds and end_time %3E= numSeconds):%0A            printTime(int(math.floor(numSeconds)))%0A            break%0A%0A        for chunk_index in range(start_search, end_search):%0A            # if sound below threshold then continue quiet streak%0A            if rms_vals%5Bchunk_index%5D %3C THRESHOLD:%0A                cur_len += 1%0A            else:%0A                if cur_len %3E longest_len:%0A                    longest_len = cur_len%0A                    longest_start = cur_start%0A                    longest_end = chunk_index%0A%0A                cur_start = chunk_index + 1%0A                cur_len = 0%0A%0A        if cur_len %3E longest_len:%0A            longest_len = cur_len%0A            longest_start = cur_start%0A            longest_end = chunk_index%0A%0A        segment_count += 1%0A        printTime(sampleIndexToSeconds(longest_end, CHUNK_SIZE, rate))%0A%0A    os.remove(wavName)%0A

add script to find segmentation boundaries for a lecture's mp3