Skip to main content

Explore a waveform with slang

Project description

peruse

Explore a waveform with slang

To install: pip install peruse

Example

from numpy import *
from hum import disp_wf, plot_wf
import soundfile as sf
from peruse.single_wf_snip_analysis import TaggedWaveformAnalysisExtended
import os
import pickle

try:
    from slang.util_data import displayable_unichr
    unichr_code_of_snip = array(displayable_unichr
                                + list(unique(list(set(range(33, 20000)).difference(displayable_unichr)))))
    snip_of_unichr_code = (nan * empty(unichr_code_of_snip.max() + 1)).astype(int)
    snip_of_unichr_code[unichr_code_of_snip] = arange(len(unichr_code_of_snip))

    def snip_to_str(snip):
        return chr(unichr_code_of_snip[snip])
except ImportError as e:
    def snip_to_str(snip):
        return chr(33 + snip)

def string_of_snips(snips):
    return "".join(map(snip_to_str, snips))
filepath = "Enter audio filepath here"
wf, sr = sf.read(filepath)
disp_wf(wf, sr)

Unsupervised

Perhaps you just want to get a perspective on your sound, without specifying annotations.

Perhaps you don't know what to annotate and you want snips to help you find patterns to annotate.

Fit the snipper

from peruse.single_wf_snip_analysis import TaggedWaveformAnalysisExtended

tw = TaggedWaveformAnalysisExtended(sr=sr, 
                                    tile_size_frm=2048, 
                                    chk_size_frm=43008, 
                                    prior_count=1)
tw.fit(wf)

Get the snips of a waveform (here the same as fit with, but could be another)

snips = tw.snips_of_wf(wf)
len(snips), len(unique(snips))

View them as characters

print(string_of_snips(snips))
annkncckkobbjhihjacjcjeneijaeofgibiecikjjkdnhajekachbobchoadkjjjjknkkkjofglmijaiinieajdccnkjnollil
hjhkokejkeacdkcofgaldikljnekdijekkjieoboocinchjadannadnnjofgiiielaekheiccnkkeejlbbllichckkinojaeoa
aofgllllnadkdkcneian

Plot (inverse of) snip probabilities (says how rare they are (outliers) from the perspective of the wf that was used to fit, and gives SOME view of the sound)

tw.plot_tiles(1 / array(list(map(tw.prob_of_snip.get, snips))));
tw.plot_tiles(log(1 / array(list(map(tw.prob_of_snip.get, snips)))));

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

peruse-0.0.13.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

peruse-0.0.13-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file peruse-0.0.13.tar.gz.

File metadata

  • Download URL: peruse-0.0.13.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for peruse-0.0.13.tar.gz
Algorithm Hash digest
SHA256 00765f7ecba32b70509778468007ea5536d0c9bd14baf0a560cf0d8ead8adcd0
MD5 29d33e412f94982b2c2941bdc95046c5
BLAKE2b-256 49fe24069655228ad758b5392412093739320f1c9114de3a014b2c6f0eeb2e93

See more details on using hashes here.

File details

Details for the file peruse-0.0.13-py3-none-any.whl.

File metadata

  • Download URL: peruse-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for peruse-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 c2074de154260a9a901bab3d17e5d3345a8c5d654bfa14b5a5d82fef0fde7f39
MD5 71ca5a452c3dd7f54fb4e7db9645fe75
BLAKE2b-256 2838f1b84a43b21e56104e7bcf47c8b51eea59affac22382a74a50daf4a1076a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page