Skip to content

qq15725/modern-audio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Modern Audio

License Version Minzip

Feature

  • Adjustment decibel
  • Adjustment fade in
  • Adjustment fade out
  • Adjustment stereo
  • Enable noise reduction
  • Render bar chart from peaks data
  • Render bar chart from peaks time domain data
  • Export multiple audio as single wav file

Installation

pnpm

pnpm add modern-audio

npm

npm i modern-audio

Usage

Basic

import { createAudio } from 'modern-audio'

const audio = createAudio('./test/assets/audio.mp3')
await audio.load()

audio.set({
  db: 1,
  pan: 0.1,
  // fadeIn: 3,
  fadeIn: { at: 0, duration: 3 },
  fadeOut: 5,
  noiseReduction: true,
  playbackRate: 2,
  loop: true,
})

// onclick after call
audio.start()

// Pause
// audio.reset()

// Play
// audio.start(0, audio.context.currentTime)

Export multiple audio as single wav file

import { createAudio, createOfflineAudioContext, downloadOfflineAudio } from 'modern-audio'

// 10s duration
const context = createOfflineAudioContext(10)

const audio = createAudio('./test/assets/audio.mp3', context)
await audio.load()

audio.set('db', 1)
audio.set('pan', 0.1)
audio.set('fadeIn', 3)
audio.set('fadeOut', 5)
audio.set('noiseReduction', true)

const audio1 = createAudio('./test/assets/audio.mp3', context)
await audio1.load()

audio1.set('db', 0)
audio1.set('pan', 0)
audio1.set('fadeIn', 0)
audio1.set('fadeOut', 0)
audio1.set('noiseReduction', false)

// onclick after call
audio.start()
audio1.start()
downloadOfflineAudio(context)

Web custom component

import { ModernAudio } from 'modern-audio'

ModernAudio.install()

html

<audio
  is="modern-audio"
  src="./test/assets/audio.mp3"
  controls
  db="1"
  pan="0.1"
  fade-in="3"
  fade-out="5"
  noise-reduction
></audio>

CDN of usage

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>modern-audio</title>
  <script src="https://cdn.jsdelivr.net/npm/modern-audio/dist/modern-audio.js"></script>
  <script>
    window['modern-audio'].ModernAudio.install()
  </script>
</head>
<body>
  <audio
    is="modern-audio"
    src="./test/assets/audio.mp3"
    controls
    db="1"
    pan="0.1"
    fade-in="3"
    fade-out="5"
    noise-reduction
  ></audio>
</body>
</html>