Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
audio-type
Advanced tools
The 'audio-type' npm package is used to detect the file type of a given audio buffer. It supports various audio formats and provides a simple interface to determine the type of audio data.
Detect Audio Type
This feature allows you to detect the type of an audio file by reading its buffer. The code sample demonstrates how to read an audio file into a buffer and then use the 'audio-type' package to determine its type.
const audioType = require('audio-type');
const fs = require('fs');
const buffer = fs.readFileSync('path/to/audio/file');
const type = audioType(buffer);
console.log(type); // e.g., 'mp3', 'wav', etc.
The 'file-type' package is a more general-purpose library that can detect the file type of various file formats, including audio, video, images, and more. It provides a broader range of file type detection compared to 'audio-type', which is specialized for audio files.
The 'music-metadata' package is used to parse audio files and extract metadata such as format, duration, and tags. While it provides more detailed information about audio files, including metadata, it also includes functionality to detect the file type, making it a more comprehensive tool compared to 'audio-type'.
Detect the audio type of a ArrayBuffer/Uint8Array
$ npm i audio-type
import readChunk from 'read-chunk'; // npm install read-chunk
import audioType from 'audio-type';
var buffer = readChunk.sync('meow.wav', 0, 12);
audioType(buffer);
//=> wav
import audioType from './audio-type.js'
var xhr = new XMLHttpRequest();
xhr.open('GET', 'meow.flac');
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
audioType(this.response);
//=> flac
};
xhr.send();
Returns: 'mp3'
, 'oga'
, 'flac'
, 'wav'
, 'm4a'
, 'opus'
, 'qoa'
Type: buffer
(Node.js), arrayBuffer
, uint8array
It only needs the first 12 bytes.
MIT • ॐ
FAQs
Detect the audio type of a Buffer/Uint8Array
We found that audio-type demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.