1.0.1 • Published 1 year ago

react-audio-spectrogram-player v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

react-audio-spectrogram-player

An audioplayer written in React that shows a spectrogram along with the audio. The playhead on the spectrogram is synchronized with the audioplayer. You can zoom in on the spectrogram and slow down the audio. It acts almost as a microscope for audio.

Note: At the moment, you still need to compute the spectrogram yourself and pass it to the component via the src prop.

If you use Python, there is also a jupyter widged based on this component. You can find it here.

Preview

See the demo.

preview

Installation

npm i react-audio-spectrogram-player

Usage

Basic Usage

import SpectrogramPlayer from "react-audio-spectrogram-player";

...

const App = () => {

    const src = ... // string: path to wav file

    const sxx = ... // number[][]: 2D array with spectrogram values

    return (
        <SpectrogramPlayer
            src={src}
            sxx={sxx}
        />
    )
}

Customization

return (
    <SpectrogramPlayer
        src={src}
        sxx={sxx}
        specHeight={200}
        navHeight={50}
        navigator
        settings
        colormap="viridis"
        transparent
        dark
    />
)
PropTypeDefaultDescription
srcstringrequiredPath to the wav audio file.
sxxnumber[][]required2D array with spectrogram values.
specHeightnumber200Height of the main spectrogram.
navigatorbooleanfalseAllow user to zoom in with the navigator UI.
navHeightnumber50Height of the navigator UI.
settingsbooleanfalseAllow user to change some playback behaviour.
colormapstring'viridis'The colormap to use.
transparentbooleanfalseUse rgba values for spectrogram image.
darkbooleanfalseUse dark mode theme.

Annotations

You can annotate intervals (such as words or phones) below the spectrogram.

  1. First place your annotation data in one or more (string | number)[][] objects.

    • Column 1: Start time in seconds
    • Column 2: End time in seconds
    • Column 3: Annotation as a string

    For example:

    const wordIntervals = [
        [0.54, 0.84, "this"],
        [0.84,  1.1, "little"],
        [ 1.1,  1.4, "work"],
        ...
    ]
    const phoneIntervals = [
        [0.54, 0.62, "ð"],
        [0.62, 0.67, "ɪ"],
        [0.67, 0.84, "s"],
        ...
    ]
  2. Now create a list of annotation objects that will be passed to the component:

    const annotations = [
        {
            data: wordIntervals,
            title: "Word intervals:",
            height: 30,
            strokeWidth: 1,
        },
        {
            data: phoneIntervals,
            title: "Phone intervals:",
            height: 30,
            strokeWidth: 1,
        }
    ]

    The title, height and strokewidth entries are optional.

  1. Pass the list to the component via the annotations prop:
```jsx
return (
    <SpectrogramPlayer
        src={src}
        sxx={sxx}
        specHeight={200}
        navHeight={50}
        annotations={annotations}
    />
)
```

Future Updates

  • Calculate spectrogram with javascript when no sxx prop is supplied.
  • Better touch screen compatibility.
1.0.1

1 year ago

1.0.0

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago