Newer
Older
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Audio Tutorial using Scipy"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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",
"metadata": {},
"source": [
"Adapted from https://publish.illinois.edu/augmentedlistening/tutorials/music-processing/tutorial-1-introduction-to-audio-processing-in-python/"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#!pip install jupyterthemes"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#!pip install wavio"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from scipy.io.wavfile import read, write\n",
"from IPython.display import Audio\n",
"from jupyterthemes import jtplot\n",
"import wavio\n",
"\n",
"jtplot.style()\n",
"\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Download Multichannel .wav file"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"\n",
"url = 'http://www.mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Samples/Microsoft/6_Channel_ID.wav'\n",
"file='6_Channel_ID.wav'\n",
"r = requests.get(url, allow_redirects=True)\n",
"open(file, 'wb').write(r.content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Read file and split channels"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Read .wav file and print frequency"
]
},
"source": [
"Fs, data = read('6_Channel_ID.wav')\n",
"print(\"Sampling Frequency is\", Fs)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"source": [
"Audio('6_Channel_ID.wav')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Split audio channels"
]
},
{
"cell_type": "code",
"outputs": [],
"source": [
"FL = data[:,0]\n",
"FR = data[:,1]\n",
RodrigoLaraM
committed
"C = data[:,2]\n",
"LF = data[:,3]\n",
"BL = data[:,4]\n",
"BR = data[:,5]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Play audio in Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Front Left**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Front Right**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
RodrigoLaraM
committed
"**Center**"
RodrigoLaraM
committed
"Audio(C, rate=Fs)"
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Low-frequency effects**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Back Left**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Back Right**"
]
},
"source": [
"Audio(BR, rate=Fs)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Plot the Wave form"
]
},
{
"cell_type": "code",
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
"source": [
"plt.figure()\n",
"plt.plot(data)\n",
"plt.xlabel('Sample Index')\n",
"plt.ylabel('Amplitude')\n",
"plt.title('Waveform of Test Audio')\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### References"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Samples.html\n",
"- https://publish.illinois.edu/augmentedlistening/tutorials/music-processing/tutorial-1-introduction-to-audio-processing-in-python/"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",