Created
February 17, 2019 14:59
-
-
Save brunomsantiago/3df8650c6e573aa50a5fb6d522158d59 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
# Imports to download the wav file. Not necessary for local files. | |
from requests import get | |
from io import BytesIO | |
# Import to read the wav file. | |
from scipy.io import wavfile | |
# Import to plot the waveform. | |
import matplotlib.pyplot as plt | |
''' | |
Download a wav file | |
For a local file could be a simple | |
filepath == r'/path/to/file.wav' | |
''' | |
url = r'https://www.pacdv.com/sounds/voices/nice-work.wav' | |
response = get(url) | |
file_handler = BytesIO(response.content) | |
# Read the wave file to numpy array | |
fs, signal = wavfile.read(file_handler) | |
channel_0 = signal[:,0] | |
channel_1 = signal[:,1] | |
# Plotting | |
fig, axes = plt.subplots(nrows=2) | |
axes[0].plot(channel_0, 'b') | |
axes[1].plot(channel_1, 'r') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment