Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
musicinformationretrieval-com
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
A.S.
musicinformationretrieval-com
Commits
05569141
Commit
05569141
authored
Jul 06, 2018
by
Steve Tjoa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
real time spectrogram
parent
598cd6da
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
12028 additions
and
10 deletions
+12028
-10
index.html
index.html
+2
-0
index.ipynb
index.ipynb
+2
-0
realtime_spectrogram.html
realtime_spectrogram.html
+11880
-0
realtime_spectrogram.ipynb
realtime_spectrogram.ipynb
+118
-0
realtime_spectrogram.py
realtime_spectrogram.py
+26
-10
No files found.
index.html
View file @
05569141
...
...
@@ -12027,6 +12027,7 @@ div#notebook {
<ol>
<li><a
href=
"pca.html"
>
Principal Component Analysis
</a>
(
<a
href=
"pca.ipynb"
>
ipynb
</a>
)
</li>
<li><a
href=
"nmf.html"
>
Nonnegative Matrix Factorization
</a>
(
<a
href=
"nmf.ipynb"
>
ipynb
</a>
)
</li>
<li><a
href=
"nmf_audio_mosaic.html"
>
NMF Audio Mosaicing
</a>
(
<a
href=
"nmf_audio_mosaic.ipynb"
>
ipynb
</a>
)
</li>
<li><a
href=
"hpss.html"
>
Harmonic-Percussive Source Separation
</a>
(
<a
href=
"hpss.ipynb"
>
ipynb
</a>
)
</li>
</ol>
...
...
@@ -12046,6 +12047,7 @@ div#notebook {
<div
class=
"inner_cell"
>
<div
class=
"text_cell_render border-box-sizing rendered_html"
>
<ol>
<li><a
href=
"realtime_spectrogram.html"
>
Real-time Spectrogram
</a>
(
<a
href=
"realtime_spectrogram.ipynb"
>
ipynb
</a>
)
</li>
<li><a
href=
"thx_logo_theme.html"
>
THX Logo Theme
</a>
(
<a
href=
"thx_logo_theme.ipynb"
>
ipynb
</a>
)
</li>
</ol>
...
...
index.ipynb
View file @
05569141
...
...
@@ -204,6 +204,7 @@
"source": [
"1. [Principal Component Analysis](pca.html) ([ipynb](pca.ipynb))\n",
"1. [Nonnegative Matrix Factorization](nmf.html) ([ipynb](nmf.ipynb))\n",
"1. [NMF Audio Mosaicing](nmf_audio_mosaic.html) ([ipynb](nmf_audio_mosaic.ipynb))\n",
"1. [Harmonic-Percussive Source Separation](hpss.html) ([ipynb](hpss.ipynb))"
]
},
...
...
@@ -218,6 +219,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"1. [Real-time Spectrogram](realtime_spectrogram.html) ([ipynb](realtime_spectrogram.ipynb))\n",
"1. [THX Logo Theme](thx_logo_theme.html) ([ipynb](thx_logo_theme.ipynb))"
]
}
...
...
realtime_spectrogram.html
0 → 100644
View file @
05569141
This diff is collapsed.
Click to expand it.
realtime_spectrogram.ipynb
0 → 100644
View file @
05569141
This diff is collapsed.
Click to expand it.
realtime_spectrogram.py
View file @
05569141
"""
musicinformationretrieval.com/realtime_spectrogram.py
PyAudio example: display a live spectrogram in the terminal.
PyAudio example: display a live
log-
spectrogram in the terminal.
For more examples using PyAudio:
https://github.com/mwickert/scikit-dsp-comm/blob/master/sk_dsp_comm/pyaudio_helper.py
...
...
@@ -11,30 +11,46 @@ import numpy
import
pyaudio
import
time
# Define global variables.
CHANNELS
=
1
RATE
=
44100
FRAMES_PER_BUFFER
=
1000
N_FFT
=
4096
SCREEN_WIDTH
=
178
ENERGY_THRESHOLD
=
0.4
BIN_LO
=
N_FFT
*
librosa
.
note_to_hz
(
'C2'
)
/
RATE
BIN_HI
=
N_FFT
*
librosa
.
note_to_hz
(
'C7'
)
/
RATE
FREQ_BINS
=
numpy
.
geomspace
(
BIN_LO
,
BIN_HI
,
SCREEN_WIDTH
)
.
astype
(
'int'
)
# Choose the frequency range of your log-spectrogram.
F_LO
=
librosa
.
note_to_hz
(
'C2'
)
F_HI
=
librosa
.
note_to_hz
(
'C9'
)
M
=
librosa
.
filters
.
mel
(
RATE
,
N_FFT
,
SCREEN_WIDTH
,
fmin
=
F_LO
,
fmax
=
F_HI
)
p
=
pyaudio
.
PyAudio
()
def
generate_string_from_audio
(
audio_data
):
"""
This function takes one audio buffer as a numpy array and returns a
string to be printed to the terminal.
"""
# Compute real FFT.
x_fft
=
numpy
.
fft
.
rfft
(
audio_data
,
n
=
N_FFT
)
X
=
numpy
.
log10
(
1
+
0.1
*
abs
(
x_fft
))
# Compute mel spectrum.
melspectrum
=
M
.
dot
(
abs
(
x_fft
))
# Initialize output characters to display.
char_list
=
[
' '
]
*
SCREEN_WIDTH
for
i
in
range
(
len
(
FREQ_BINS
)):
b
=
FREQ_BINS
[
i
]
if
X
[
b
]
>
0.3
:
for
i
in
range
(
SCREEN_WIDTH
):
# If there is energy in this frequency bin, display an asterisk.
if
melspectrum
[
i
]
>
ENERGY_THRESHOLD
:
char_list
[
i
]
=
'*'
# Draw frequency axis guidelines.
elif
i
%
30
==
29
:
char_list
[
i
]
=
'|'
# Return string.
return
''
.
join
(
char_list
)
def
callback
(
in_data
,
frame_count
,
time_info
,
status
):
...
...
@@ -45,8 +61,8 @@ def callback(in_data, frame_count, time_info, status):
stream
=
p
.
open
(
format
=
pyaudio
.
paFloat32
,
channels
=
CHANNELS
,
rate
=
RATE
,
input
=
True
,
output
=
True
,
input
=
True
,
# Do record input.
output
=
False
,
# Do not play back output.
frames_per_buffer
=
FRAMES_PER_BUFFER
,
stream_callback
=
callback
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment