This feature is on Alpha state.

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

The Audio to LLM feature applies your own prompts to the audio transcription.

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("- Transcription done: \n");
      const audioToLlmResults = pollResponse.result.audio_to_llm;
      console.log(audioToLlmResults);
      break;
    } else {
      console.log("Transcription status : ", pollResponse.status);
      await new Promise((resolve) => setTimeout(resolve, 1000));
    }
  }
}

async function startTranscription() {
  const gladiaKey = "YOUR_GLADIA_API_TOKEN";
  const requestData = {
    audio_url: "YOUR_AUDIO_URL",
    audio_to_llm: true,
    audio_to_llm_config: {
      prompts: [
        "Extract the key points from the transcription as bullet points",
        "Generate a title from this transcription",
      ],
    },
  };
  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:

{
  "success": true,
  "is_empty": false,
  "results": [
    {
      "success": true,
      "is_empty": false,
      "results": {
        "prompt": "Extract the key points from the transcription as bullet points",
        "response": "The main entities key points from the transcription are:\n- ..."
      },
      "exec_time": 1.7726809978485107,
      "error": null
    },
    {
      "success": true,
      "is_empty": false,
      "results": {
        "prompt": "Generate a title from this transcription",
        "response": "The Great Title"
      },
      "exec_time": 1.7832809978258485,
      "error": null
    }
  ],
  "exec_time": 6.127103805541992,
  "error": null
}

You’ll find your custom prompts results of your audio under the results key.

Was this page helpful?