ts-audio-to-mp3
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

ts-audio-to-mp3

A TypeScript utility for converting audio to MP3 format in the browser.

Installation

npm install ts-audio-to-mp3

Usage

import { convertToMP3 } from 'ts-audio-to-mp3';

// Example with File input
const fileInput = document.querySelector('input[type="file"]');
fileInput.addEventListener('change', async (e) => {
  const file = e.target.files[0];
  try {
    const mp3Blob = await convertToMP3(file, {
      sampleRate: 44100, // optional, default: 44100
      bitRate: 128 // optional, default: 128
    });
    
    // Use the MP3 blob as needed
    const url = URL.createObjectURL(mp3Blob);
    const audio = new Audio(url);
    audio.play();
  } catch (error) {
    console.error('Error converting to MP3:', error);
  }
});

API

convertToMP3(audioData: Blob | File, options?: AudioToMP3Options): Promise

Converts an audio file or blob to MP3 format.

Parameters

  • audioData: The input audio data as a Blob or File
  • options: (Optional) Conversion options
    • sampleRate: Sample rate in Hz (default: 44100)
    • bitRate: Bit rate in kbps (default: 128)

Returns

Returns a Promise that resolves with a Blob containing the MP3 data.

License

MIT

Package Sidebar

Install

npm i ts-audio-to-mp3

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

9.81 kB

Total Files

6

Last publish

Collaborators

  • jjkyuldashov