Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

audio-type-detect

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

audio-type-detect

detect audio file type from url

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
decreased by-43.75%
Maintainers
1
Weekly downloads
 
Created
Source

audio-type-detect

Detect an audio file type from remote url or ArrayBuffer.

According to the magic number of a file, we can detect the type of an audio file with or without a file suffix.

Install

npm install audio-type-detect --save

Usage

detect from url

import getAudioType from 'audio-type-detect'

// an aac audio file without file suffix
const url = 'https://0345-1400187352-1256635546.cos.ap-shanghai.myqcloud.com/rychou/e3801cfc517873a5a5471241e1da1869'

getAudioType(url).then(type => {
  console.log(type)
})

// ouput aac

detect from buffer

import { getAudioTypeFromBuffer } from 'audio-type-detect'
// an aac audio file without file suffix
const url = 'https://0345-1400187352-1256635546.cos.ap-shanghai.myqcloud.com/rychou/e3801cfc517873a5a5471241e1da1869'

const xhr = new XMLHttpRequest();
xhr.open('GET', 'url');
xhr.responseType = 'arraybuffer';
xhr.send();
xhr.onload = () => {
    console.log(getAudioTypeFromBuffer(xhr.response));
    // output aac
};

API

getAudioType(url) -> { Promise }

get audio file type from an url.

Parameters:

NameTypeDescription
urlStringThe audio file url.

Returns:

return a Promise object

  • getAudioType(url).then(type => {}) the type( String ) of file. if detect failure, it return false
  • getAudioType(url).catch(error => {})

getAudioTypeFromBuffer(buffer) -> { String }

get audio file type from an array buffer.

Parameters:

NameTypeDescription
urlStringThe audio file url.

Returns:

return the type( String ) of file. if detect failure, it return false

Supported file type

mp3, flac, aac, oga, wav, wma, amr

Keywords

FAQs

Package last updated on 30 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc