Classify audio clips into predefined categories such as speech emotion, sound detection, and music genres.

Quickstart

Classify an Audio File

Send an audio file to a model for classification.

import Bytez from "bytez.js";

const client = new Bytez("YOUR_BYTEZ_KEY_HERE");
const model = client.model("aaraki/wav2vec2-base-finetuned-ks");

const inputAudioBase64 = await getBase64Audio(
  "https://huggingface.co/datasets/huggingfacejs/tasks/resolve/main/audio-classification/audio.wav"
);

const { error, output: labelObjects } = await model.run({
  b64AudioBufferWav: inputAudioBase64
});

if (error) {
  console.error("Error:", error);
} else {
  for (const labelObject of labelObjects) {
    console.log(labelObject);
    const { score, label } = labelObject;
    console.log({ score, label });
  }
}

async function getBase64Audio(url) {
  const response = await fetch(url);
  const arrayBuffer = await response.arrayBuffer();
  return Buffer.from(arrayBuffer).toString("base64");
}

Demo