Last active
September 14, 2015 16:28
-
-
Save bitoffdev/27617a3c11dccb3cc400 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wave | |
import matplotlib.path as mpath | |
import matplotlib.patches as mpatches | |
import matplotlib.pyplot as plt | |
fig, ax = plt.subplots() | |
Path = mpath.Path | |
path_data = [] | |
path_data.append((Path.MOVETO, (0.00, 0.00))) | |
wf = wave.open('Bowed-Bass-C2.wav', 'rb') | |
for i in range(1024): | |
data = wf.readframes(4) | |
val = 256*ord(data[0]) + ord(data[1]) | |
path_data.append((Path.LINETO, (i, val/256.0))) | |
codes, verts = zip(*path_data) | |
path = mpath.Path(verts, codes) | |
# plot control points and connecting lines | |
x, y = zip(*path.vertices) | |
line, = ax.plot(x, y, 'go-') | |
ax.grid() | |
ax.axis('equal') | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyaudio | |
import wave | |
import sys | |
CHUNK = 1024 | |
def SteroToMono(data, samplewidth): | |
new_data = '' | |
for i in range(0, len(data), 2 * samplewidth): | |
new_data += data[i:i+samplewidth] | |
return new_data | |
def PlayWave(path): | |
wf = wave.open(path, 'rb') | |
p = pyaudio.PyAudio() | |
stream = p.open(format=p.get_format_from_width(wf.getsampwidth()), | |
channels=wf.getnchannels(), | |
rate=wf.getframerate(), | |
output=True) | |
data = wf.readframes(CHUNK) | |
while data != '': | |
stream.write(data) | |
data = wf.readframes(CHUNK) | |
stream.stop_stream() | |
stream.close() | |
p.terminate() | |
if __name__ == "__main__": | |
if len(sys.argv) < 2: | |
print("Plays a wave file.\n\nUsage: %s filename.wav" % sys.argv[0]) | |
sys.exit(-1) | |
PlayWave(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment