InĀ [1]:
import torchaudio
import torch
import holoviews as hv

hv.extension("bokeh")
No description has been provided for this image No description has been provided for this image
InĀ [2]:
def envelope(wav, sr):
    return torch.nn.functional.max_pool1d(wav.abs(), 1001, 500, padding=500)


wav, sr = torchaudio.load("https://catalog.ldc.upenn.edu/desc/addenda/LDC97S42.sph")
env = envelope(wav, sr)
loud_channel = (env[0] > env[1]).to(int)
random_channel = (torch.rand_like(loud_channel, dtype=float) > 0.5).to(int)

(
    hv.Curve(loud_channel, label="Real").opts(responsive=True, height=200)
    + hv.Curve(random_channel, label="Pure random").opts(responsive=True, height=200)
).cols(1)
Out[2]:
InĀ [3]:
def random_walk(scale=10):
    simple_random_walk = (torch.randn_like(loud_channel, dtype=float) / scale).cumsum(
        dim=-1
    ) + torch.rand(1)
    return ((simple_random_walk % 2) - 1).abs()


hv.Curve(random_walk()).opts(
    title="Random walk between 0 and 1", responsive=True, height=300
)
Out[3]:
InĀ [4]:
random_walk_channel = (random_walk() > 0.5).to(int)

(
    hv.Curve(loud_channel, label="Real").opts(responsive=True, height=200)
    + hv.Curve(random_walk_channel, label="Random walk").opts(
        responsive=True, height=200
    )
).cols(1)
Out[4]: