</>

Quick Guide

How to use modusa?

modusa comes with bunch of useful utility tools particulary for audio but not limited to.

Installation

You need python version \(\ge 3.10\)

To install run the command:

[ ]:
pip install modusa

Loading an audio signal

You can load audio signal from local file or directly from youtube.

[1]:
import modusa as ms
import numpy as np
[2]:
# Local path
y1, sr1, title1 = ms.load("../audio/Ankit Anand Music - Tu Hi Bta.wav", sr=None)
y1 = y1[:int(10 * sr1)] # First 10 seconds
ms.play(y1, sr1, title=title1)

Ankit Anand Music - Tu Hi Bta

[2]:
Clip 1
Timing 0.00s → 10.00s
Player
[5]:
# Youtube
y2, sr2, title2 = ms.load("https://www.youtube.com/watch?v=DIU_vmElPkU", sr=None)
y2 = y2[:int(10 * sr2)] # First 10 seconds
ms.play(y2, sr2, title=title2)

Ankit Anand Music - Laut Aao Na (लौट आओ ना) [Official Lyrical Video]

[5]:
Clip 1
Timing 0.00s → 10.00s
Player

Plotting

1D/2D Mix

[1]:
import modusa as ms
import numpy as np

y = np.random.random(100)
M = np.random.random((100, 200))

fig = ms.fig("aasms", xlim=(0, 100)) # a => aux plot, s => signal plot, m => matrix plot
fig.add_annotation([(0, 5, "Ankit")])
fig.add_events([0, 1, 2, 3, 10, 100])
fig.add_signal(y, ylabel="Test", label="Signal 1", ylim=(-1, 1))
fig.add_signal(y*20, ylabel="Test", ax=4, label="Signal 2")
fig.add_matrix(M, label="Matrix", ylabel="Ylabel")
fig.add_signal(2*y, m="o", label="Signal 3")
fig.add_title("Title")
fig.add_xlabel("Time (sec)")
fig.add_legend()
fig.save("./test.png")
../_images/quicktour_qg_10_0.png

Distribution

[18]:
y = np.random.randn(1000)

ms.plot_dist(
    (y, ),
    title="Distribution",
    ylabel="Prob. Density",
    xlabel="x",
)
[18]:
../_images/quicktour_qg_12_0.png

Audio Player

[19]:
ms.play(y1, sr1, title=title1, regions=[(2, 4, "A"), (8, 10, "B")])

Ankit Anand Music - Tu Hi Bta

[19]:
Clip AB
Timing 2.00s → 4.00s8.00s → 10.00s
Player

Audio Recorder

[20]:
result = ms.record()
[ ]:
# After recording, you can run this
# to get the recorder signal array
y, sr, title = result()

Audio Converter

To convert any audio file from one format to another using ffmpeg.

[ ]:
ms.convert("path/to/audio.mp3", "path/to/audio.wav", mono=False)

Download from YouTube

Download your content from YouTube.

[ ]:
ms.download(url="link", content_type="audio", output_dir="path/to/outputdir")