Skip to content

Commit c7f42f6

Browse files
Merge pull request #2559 from singhchanmeet/audio-spectrogram
Added Audio to Spectrogram Script
2 parents ebe466b + 279b24f commit c7f42f6

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

Audio-to-Spectrogram/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Audio-Spectrogram
2+
3+
## 📝 Description
4+
* This Python script takes an audio file (.wav, .mp3) as an input and draws its Spectrogram (Frequency vs Time)
5+
<br>
6+
* The script uses <a href="https://librosa.org/doc/latest/index.html">Librosa</a> Library for audio processing and <a href="https://matplotlib.org/">MatPlotLib</a> Library for plotting the graph.
7+
8+
<br>
9+
10+
## ⚙️ How To Use
11+
12+
Navigate to the project directory and run the following commands :
13+
```bash
14+
pip install -r requirements.txt
15+
```
16+
Replace audio="path" on line 4 with the path to your audio file
17+
18+
```bash
19+
python audio-to-spectrogram.py
20+
```
21+
22+
## Output
23+
24+
25+
https://github.com/singhchanmeet/Amazing-Python-Scripts/assets/119502048/be8fcebb-6429-4d0a-b8b8-86397f53290e
26+
27+
28+
29+
## Author
30+
31+
32+
* <a href="https://github.com/singhchanmeet"> Chanmeet Singh </a>
33+
* References : https://analyticsindiamag.com/hands-on-tutorial-on-visualizing-spectrograms-in-python/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import librosa
2+
import matplotlib.pyplot as plt
3+
4+
audio = 'path/to/your/audio/file' #replace this with the path to your file
5+
6+
x, sr = librosa.load(audio)
7+
X = librosa.stft(x)
8+
Xdb = librosa.amplitude_to_db(abs(X))
9+
plt.figure(figsize = (10, 5))
10+
librosa.display.specshow(Xdb, sr = sr, x_axis = 'time', y_axis = 'hz')
11+
plt.colorbar()
12+
plt.title('Spectrogram of '+ audio)
13+
plt.show() # This will show the plot

Audio-to-Spectrogram/requirements.txt

82 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)