This feature is on Alpha state.

We’re looking for feedbacks to improve this feature, share yours here.

The Content Moderation model scans your transcription and finds out if it contains words or expressions that potentially need to be moderated, while classifying their type and severity.

To use this feature, follow this example:

async function makeFetchRequest(url: string, options: any) {
  const response = await fetch(url, options);
  return response.json();
}

async function pollForResult(resultUrl: string, headers: any) {
  while (true) {
    console.log("Polling for results...");
    const pollResponse = await makeFetchRequest(resultUrl, { headers });

    if (pollResponse.status === "done") {
      console.log("- Moderation done: \n");
      const moderation = pollResponse.result.moderation;
      console.log(moderation);
      break;
    } else {
      console.log("Moderation status : ", pollResponse.status);
      await new Promise((resolve) => setTimeout(resolve, 1000));
    }
  }
}

async function startModeration() {
  const gladiaKey = "YOUR_GLADIA_API_TOKEN";
  const requestData = {
    audio_url:
      "YOUR_AUDIO_URL",
    moderation: true
  };
  const gladiaUrl = "https://api.gladia.io/v2/transcription/";
  const headers = {
    "x-gladia-key": gladiaKey,
    "Content-Type": "application/json",
  };

  console.log("- Sending initial request to Gladia API...");
  const initialResponse = await makeFetchRequest(gladiaUrl, {
    method: "POST",
    headers,
    body: JSON.stringify(requestData),
  });

  console.log("Initial response with Transcription ID :", initialResponse);

  if (initialResponse.result_url) {
    await pollForResult(initialResponse.result_url, headers);
  }
}

startTranscription();

With this code, your output will look like this if there is no need to moderate anything:

{
  "success": true,
  "is_empty": false,
  "results": [],
  "exec_time": 1.5126123428344727,
  "error": null
}

On the other hand, if profanities were detected, your result would look like this :

{
  "success": true,
  "is_empty": false,
  "results": [
  {
    "success": true,
    "is_empty": false,
    "results": [
    {
      "utterance_id": 0,
      "text": "****.",
      "type": "HATEFUL",
      "severity": "MEDIUM",
      "classifications": [
        "INSULT",
        "VULGARITY"
      ]
    },
    {
      "utterance_id": 3,
      "text": "****",
      "type": "HATEFUL",
      "severity": "MEDIUM",
      "classifications": [
          "INSULT"
      ]
    }
    ],
    "exec_time": 0.23801589012145996,
    "error": null
  }],
  "exec_time": 0.27121686935424805,
  "error": null
}