Skip to content

Commit

Permalink
Merge pull request #5 from libAudioFlux/dev1
Browse files Browse the repository at this point in the history
Dev1
  • Loading branch information
wtq2255 authored Feb 11, 2023
2 parents 78f881e + 40157db commit fca48a2
Show file tree
Hide file tree
Showing 25 changed files with 287 additions and 217 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
build/
scripts/android
scripts/windows
audioflux/lib/*
audioflux/lib

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
52 changes: 24 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,11 @@ To install the **`audioFlux`** package, Python >=3.6, using the released python
Mel spectrogram and Mel-frequency cepstral coefficients

```python
# Feature extraction example
import numpy as np
import matplotlib.pyplot as plt

import audioflux as af

import matplotlib.pyplot as plt
from audioflux.display import fill_spec
from audioflux.type import SpectralFilterBankScaleType

# Get a 220Hz's audio file path
sample_path = af.utils.sample_path('220')
Expand All @@ -164,29 +162,28 @@ sample_path = af.utils.sample_path('220')
audio_arr, sr = af.read(sample_path)

# Extract mel spectrogram
bft_obj = af.BFT(num=128, radix2_exp=12, samplate=sr,
scale_type=SpectralFilterBankScaleType.MEL)
spec_arr = bft_obj.bft(audio_arr)
spec_arr, mel_fre_band_arr = af.mel_spectrogram(audio_arr, num=128, radix2_exp=12, samplate=sr)
spec_arr = np.abs(spec_arr)

# Create XXCC object and extract mfcc
xxcc_obj = af.XXCC(bft_obj.num)
xxcc_obj.set_time_length(time_length=spec_arr.shape[1])
mfcc_arr = xxcc_obj.xxcc(spec_arr)
# Extract mfcc
mfcc_arr, _ = af.mfcc(audio_arr, cc_num=13, mel_num=128, radix2_exp=12, samplate=sr)

# Display
audio_len = audio_arr.shape[0]
# calculate x/y-coords
x_coords = np.linspace(0, audio_len / sr, spec_arr.shape[1] + 1)
y_coords = np.insert(mel_fre_band_arr, 0, 0)
fig, ax = plt.subplots()
img = fill_spec(spec_arr, axes=ax,
x_coords=bft_obj.x_coords(audio_len),
y_coords=bft_obj.y_coords(),
x_axis='time', y_axis='log',
title='Mel Spectrogram')
x_coords=x_coords, y_coords=y_coords,
x_axis='time', y_axis='log',
title='Mel Spectrogram')
fig.colorbar(img, ax=ax)

fig, ax = plt.subplots()
img = fill_spec(mfcc_arr, axes=ax,
x_coords=bft_obj.x_coords(audio_len), x_axis='time',
title='MFCC')
x_coords=x_coords, x_axis='time',
title='MFCC')
fig.colorbar(img, ax=ax)

plt.show()
Expand All @@ -199,15 +196,14 @@ plt.show()
Continuous Wavelet Transform spectrogram and its corresponding synchrosqueezing reassignment spectrogram

```python
# Feature extraction example
import numpy as np
import matplotlib.pyplot as plt

import audioflux as af
from audioflux.display import fill_spec
from audioflux.type import SpectralFilterBankScaleType, WaveletContinueType
from audioflux.utils import note_to_hz

import matplotlib.pyplot as plt
from audioflux.display import fill_spec

# Get a 220Hz's audio file path
sample_path = af.utils.sample_path('220')

Expand All @@ -230,15 +226,15 @@ synsq_arr = synsq_obj.synsq(cwt_spec_arr,
fre_arr=cwt_obj.get_fre_band_arr())

# Show CWT
fig, ax = plt.subplots(figsize=(7,4))
fig, ax = plt.subplots(figsize=(7, 4))
img = fill_spec(np.abs(cwt_spec_arr), axes=ax,
x_coords=cwt_obj.x_coords(),
y_coords=cwt_obj.y_coords(),
x_axis='time', y_axis='log',
title='CWT')
fig.colorbar(img, ax=ax)
# Show Synsq
fig, ax = plt.subplots(figsize=(7,4))
fig, ax = plt.subplots(figsize=(7, 4))
img = fill_spec(np.abs(synsq_arr), axes=ax,
x_coords=cwt_obj.x_coords(),
y_coords=cwt_obj.y_coords(),
Expand Down Expand Up @@ -276,11 +272,11 @@ Using PyPI:
$ pip install audioflux
```

<!--Using Anaconda:
Using Anaconda:

```
$ conda install -c conda-forge audioflux
```-->
$ conda install -c tanky25 -c conda-forge audioflux
```


<!--Read installation instructions:
Expand All @@ -303,7 +299,7 @@ Enter the **`audioFlux`** project **`scripts`** directory and switch to the curr
$ ./build_iOS.sh
```

Build and compile successfully, the project build compilation results are in the **`build`** folder
Build and compile successfully, the project build compilation results are in the **`build`** folder

### Android build

Expand All @@ -324,7 +320,7 @@ Enter the **`audioFlux`** project **`scripts`** directory and switch to the curr
$ ./build_android.sh
```

Build and compile successfully, the project build compilation results are in the **`build`** folder
Build and compile successfully, the project build compilation results are in the **`build`** folder


### Building from source
Expand Down
2 changes: 1 addition & 1 deletion audioflux/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__title__ = 'audioflux'
__description__ = 'A library for audio and music analysis, feature extraction.'
__version__ = '0.1.1'
__version__ = '0.1.2'
1 change: 1 addition & 0 deletions audioflux/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,7 @@ def vqt(X, num=84, samplate=32000, low_fre=note_to_hz('C1'), bin_per_octave=12,
>>> audio_arr, sr = af.read(audio_path)
Extract spectrogram of dB
>>> low_fre = af.utils.note_to_hz('C1')
>>> spec_arr, fre_band_arr = af.vqt(audio_arr, samplate=sr, low_fre=low_fre)
>>> spec_dB_arr = af.utils.power_to_db(spec_arr ** 2)
Expand Down
Loading

0 comments on commit fca48a2

Please sign in to comment.