#!/usr/local/bin/python3
# Python Challenge - 25
# http://www.pythonchallenge.com/pc/hex/lake.html
# Username: butter; Password: fly
# Keyword:

import os
import wave
import matplotlib.pyplot as plt
import numpy as np


def main():
    '''
    Hint: imagine how they sound; picture of lake with puzzle pieces overlaid
    can you see the waves; name of image is lake1.jpg
    Download wave files 1-25: http://www.pythonchallenge.com/pc/hex/lake[N].wav
    '''

    source_dir = './waves_chall_25/'

    plt.figure(figsize=(20, 20))
    plot_index = 1
    for filename in os.listdir(source_dir):
        if filename == ".DS_Store":
            continue

        with wave.open(source_dir + filename, "rb") as spf:
            # Extract Raw Audio from File
            signal = spf.readframes(-1)
            signal = np.fromstring(signal, "Int16")

            # Split the data into channels [COMMENTED OUT]
            # channels = [[] for channel in range(spf.getnchannels())]
            # for index, datum in enumerate(signal):
            #     channels[index % len(channels)].append(datum)

            # Get time from indices
            fs = spf.getframerate()  # sampling frequency
            time = np.linspace(0, len(signal) / fs, num=len(signal))
            # Channel time calculation
            # time = np.linspace(0, len(signal) / len(channels) / fs,
            #                    num=len(signal) / len(channels))

        plt.subplot(5, 5, plot_index)
        plt.tight_layout()
        plt.title("Signal: {}".format(filename[:-4]))
        plt.axis(ymin=-9000, ymax=9000)
        plt.plot(time, signal)
        # for channel in channels:
        #     plt.plot(time, channel)
        plot_index += 1

    plt.savefig("SignalWavePlots.pdf")
    plt.show()
    plt.clf()

    return 0


if __name__ == '__main__':
    main()

@@ -453,1343 +453,369 @@
     
-'''%0A%0A    source_dir = './waves_chall_25/'%0A%0A    plt.figure(figsize=(20, 20))%0A    plot_index = 1%0A    for filename in os.listdir(source_dir):%0A        if filename == %22.DS_Store%22:%0A            continue%0A%0A        with wave.open(source_dir + filename, %22rb%22) as spf:%0A            # Extract Raw Audio from File%0A            signal = spf.readframes(-1)%0A            signal = np.fromstring(signal, %22Int16%22)%0A%0A            # Split the data into channels %5BCOMMENTED OUT%5D%0A            # channels = %5B%5B%5D for channel in range(spf.getnchannels())%5D%0A            # for index, datum in enumerate(signal):%0A            #     channels%5Bindex %25 len(channels)%5D.append(datum)%0A%0A            # Get time from indices%0A            fs = spf.getframerate()  # sampling frequency%0A            time = np.linspace(0, len(signal) / fs, num=len(signal))%0A            # Channel time calculation%0A            # time = np.linspace(0, len(signal) / len(channels) / fs,%0A            #                    num=len(signal) / len(channels))%0A%0A        plt.subplot(5, 5, plot_index)%0A        plt.tight_layout()%0A        plt.title(%22Signal: %7B%7D%22.format(filename%5B:-4%5D))%0A        plt.axis(ymin=-9000, ymax=9000)%0A        plt.plot(time, signal)%0A        # for channel in channels:%0A        #     plt.plot(time, channel)%0A        plot_index += 1%0A%0A    plt.s
+Bash command (-o option writes to file vs. stdout, #1 refers to seq val%0A        to name the file, -U is proxy-user login info):%0A%0A        curl -U butter:fly -o %22./waves_chall_25/lake#1.wav%22%0A        %22http://www.pythonchallenge.com/pc/hex/lake%5B1-25%5D.wav%22%0A    '''%0A%0A    source_dir = './waves_chall_25/'%0A    w
 ave
+_
 fi
-g(%22SignalWavePlots.pdf%22)%0A    plt.show()%0A    plt.clf()%0A
+les = %5B'lake%7B%7D.wav'.format(i) for i in range(1, 26)%5D
 %0A   

Add bash command to dl wave files automatically