Skip to content
Snippets Groups Projects
Commit 7b3321bc authored by goodm215's avatar goodm215
Browse files

Merge branch 'Issue71' into 'main'

Issue 71-audio-data-tutorial-sslerror-certificateerror

See merge request CMSE/datatools_tutorial_demo!127
parents 05a06064 10b5e4d9
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Audio Tutorial using Scipy
%% Cell type:markdown id: tags:
Audio channels can be separated into multiple locatities to give the impression on the viewer of a two or three dimensional space. For instance, most cars have multiple speakers to surround the passengers with sound. This reduces listening fatigue and makes for a more immersive experience. In machine learning, it can be useful to separate audio files into multiple channels so they can be more useful features for locating labels more closely tied to a certain channel.
%% Cell type:markdown id: tags:
Adapted from https://publish.illinois.edu/augmentedlistening/tutorials/music-processing/tutorial-1-introduction-to-audio-processing-in-python/
%% Cell type:code id: tags:
``` python
#!pip install jupyterthemes
```
%% Cell type:code id: tags:
``` python
#!pip install wavio
```
%% Cell type:code id: tags:
``` python
import numpy as np
import matplotlib.pyplot as plt
from scipy.io.wavfile import read, write
from IPython.display import Audio
from jupyterthemes import jtplot
import wavio
jtplot.style()
%matplotlib inline
```
%% Cell type:markdown id: tags:
### Download Multichannel .wav file
%% 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
%% Cell type:code id: tags:
``` python
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'
r = requests.get(url, allow_redirects=True)
open(file, 'wb').write(r.content)
```
%% Cell type:markdown id: tags:
### Read file and split channels
%% Cell type:markdown id: tags:
Read .wav file and print frequency
%% Cell type:code id: tags:
``` python
Fs, data = read('6_Channel_ID.wav')
print("Sampling Frequency is", Fs)
```
%% Cell type:markdown id: tags:
Listen to full audio file
%% Cell type:code id: tags:
``` python
Audio('6_Channel_ID.wav')
```
%% Cell type:markdown id: tags:
Split audio channels
%% Cell type:code id: tags:
``` python
FL = data[:,0]
FR = data[:,1]
C = data[:,2]
LF = data[:,3]
BL = data[:,4]
BR = data[:,5]
```
%% Cell type:markdown id: tags:
### Play audio in Notebook
%% Cell type:markdown id: tags:
**Front Left**
%% Cell type:code id: tags:
``` python
Audio(FL, rate=Fs)
```
%% Cell type:markdown id: tags:
**Front Right**
%% Cell type:code id: tags:
``` python
Audio(FR, rate=Fs)
```
%% Cell type:markdown id: tags:
**Center**
%% Cell type:code id: tags:
``` python
Audio(C, rate=Fs)
```
%% Cell type:markdown id: tags:
**Low-frequency effects**
%% Cell type:code id: tags:
``` python
Audio(LF, rate=Fs)
```
%% Cell type:markdown id: tags:
**Back Left**
%% Cell type:code id: tags:
``` python
Audio(BL, rate=Fs)
```
%% Cell type:markdown id: tags:
**Back Right**
%% Cell type:code id: tags:
``` python
Audio(BR, rate=Fs)
```
%% Cell type:markdown id: tags:
### Plot the Wave form
%% Cell type:code id: tags:
``` python
plt.figure()
plt.plot(data)
plt.xlabel('Sample Index')
plt.ylabel('Amplitude')
plt.title('Waveform of Test Audio')
plt.show()
```
%% Cell type:markdown id: tags:
### References
%% Cell type:markdown id: tags:
- 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/
......
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