Skip to content
Snippets Groups Projects
Commit 2c6bfc60 authored by Colbry, Dirk's avatar Colbry, Dirk
Browse files

Merge branch 'kimbri10-main-patch-46245' into 'main'

Update AudioDataTutorial.ipynb

Closes #31

See merge request CMSE/datatools_tutorial_demo!5
parents b4e5ea53 5df9293a
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Audio Tutorial using Scipy # Audio Tutorial using Scipy
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Adapted from https://publish.illinois.edu/augmentedlistening/tutorials/music-processing/tutorial-1-introduction-to-audio-processing-in-python/ Adapted from https://publish.illinois.edu/augmentedlistening/tutorials/music-processing/tutorial-1-introduction-to-audio-processing-in-python/
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
#!pip install jupyterthemes #!pip install jupyterthemes
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
#!pip install wavio #!pip install wavio
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from scipy.io.wavfile import read, write from scipy.io.wavfile import read, write
from IPython.display import Audio from IPython.display import Audio
from jupyterthemes import jtplot from jupyterthemes import jtplot
import wavio import wavio
jtplot.style() jtplot.style()
%matplotlib inline %matplotlib inline
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
### Download Multichannel .wav file ### Download Multichannel .wav file
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Download audio file *6_Channel_ID.wav* from http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Samples/Microsoft/6_Channel_ID.wav Download audio file *6_Channel_ID.wav* from http://www.mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Samples/Microsoft/6_Channel_ID.wav
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import requests import requests
url = 'http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Samples/Microsoft/6_Channel_ID.wav' url = 'http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Samples/Microsoft/6_Channel_ID.wav'
file='6_Channel_ID.wav' file='6_Channel_ID.wav'
r = requests.get(url, allow_redirects=True) r = requests.get(url, allow_redirects=True)
open(file, 'wb').write(r.content) open(file, 'wb').write(r.content)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
### Read file and split channels ### Read file and split channels
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Read .wav file and print frequency Read .wav file and print frequency
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
Fs, data = read('6_Channel_ID.wav') Fs, data = read('6_Channel_ID.wav')
print("Sampling Frequency is", Fs) print("Sampling Frequency is", Fs)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Listen to full audio file Listen to full audio file
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
Audio('6_Channel_ID.wav') Audio('6_Channel_ID.wav')
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Split audio channels Split audio channels
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
FL = data[:,0] FL = data[:,0]
FR = data[:,1] FR = data[:,1]
FC = data[:,2] FC = data[:,2]
LF = data[:,3] LF = data[:,3]
BL = data[:,4] BL = data[:,4]
BR = data[:,5] BR = data[:,5]
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
### Play audio in Notebook ### Play audio in Notebook
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
**Front Left** **Front Left**
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
Audio(FL, rate=Fs) Audio(FL, rate=Fs)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
**Front Right** **Front Right**
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
Audio(FR, rate=Fs) Audio(FR, rate=Fs)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
**Front Center** **Front Center**
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
Audio(FC, rate=Fs) Audio(FC, rate=Fs)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
**Low-frequency effects** **Low-frequency effects**
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
Audio(LF, rate=Fs) Audio(LF, rate=Fs)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
**Back Left** **Back Left**
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
Audio(BL, rate=Fs) Audio(BL, rate=Fs)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
**Back Right** **Back Right**
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
Audio(BR, rate=Fs) Audio(BR, rate=Fs)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
### Plot the Wave form ### Plot the Wave form
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
plt.figure() plt.figure()
plt.plot(data) plt.plot(data)
plt.xlabel('Sample Index') plt.xlabel('Sample Index')
plt.ylabel('Amplitude') plt.ylabel('Amplitude')
plt.title('Waveform of Test Audio') plt.title('Waveform of Test Audio')
plt.show() plt.show()
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
### References ### References
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
- http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Samples.html - http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Samples.html
- https://publish.illinois.edu/augmentedlistening/tutorials/music-processing/tutorial-1-introduction-to-audio-processing-in-python/ - https://publish.illinois.edu/augmentedlistening/tutorials/music-processing/tutorial-1-introduction-to-audio-processing-in-python/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment