> ## Documentation Index
> Fetch the complete documentation index at: https://ai.aidalinfo.fr/llms.txt
> Use this file to discover all available pages before exploring further.

# Transcription audio

> Transcription audio agnostique du modèle avec createTranscriptionModel, transcribe et createTranscriptionTool.

`@ai_kit/core` inclut un support de transcription audio agnostique du modèle, compatible avec n'importe quel endpoint OpenAI-compatible (Scaleway Whisper large v3, OpenAI whisper-1, etc.).

## Quatre primitives publiques

| Export                                      | Rôle                                                                                                       |
| ------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `createTranscriptionModel(config)`          | Crée un provider `TranscriptionModelV3`                                                                    |
| `createTranscriptionStreamingModel(config)` | Crée un modèle de streaming **natif** (sans AI SDK) qui émet le texte au fur et à mesure via SSE           |
| `transcribe(options)`                       | Fonction standalone : charge l'audio (chemin / URL / buffer), appelle le modèle, retourne la transcription |
| `createTranscriptionTool(model, options?)`  | Retourne un `tool()` AI SDK à attacher directement à un `Agent`                                            |

## `createTranscriptionModel`

```ts theme={null}
import { createTranscriptionModel } from "@ai_kit/core";

const whisperModel = createTranscriptionModel({
  modelId: "whisper-large-v3",
  apiKey: process.env.SCALEWAY_API_KEY!,
  baseURL: "https://api.scaleway.ai/v1",
  providerName: "scaleway", // optionnel, utilisé dans les logs
});
```

Compatible avec tout endpoint `/audio/transcriptions` OpenAI-compatible (`response_format=verbose_json`).

## `transcribe`

```ts theme={null}
import { transcribe } from "@ai_kit/core";

// Depuis un chemin de fichier
const result = await transcribe({
  model: whisperModel,
  audio: "/chemin/vers/audio.wav",
  inputType: "path",         // "path" | "url" | "buffer" — auto-détecté si omis
  language: "fr",            // code langue ISO-639-1, optionnel
});

console.log(result.text);
// result.segments → [{ text, startSecond, endSecond }]
// result.language, result.durationInSeconds
```

`audio` accepte un chemin de fichier, une URL `http(s)`, ou un `Buffer` / `Uint8Array`. L'`inputType` est auto-détecté si omis.

### Valeur retournée

```ts theme={null}
interface TranscribeResult {
  text: string;
  segments: Array<{ text: string; startSecond: number; endSecond: number }>;
  language: string | undefined;
  durationInSeconds: number | undefined;
}
```

## `createTranscriptionStreamingModel` — streaming (natif)

Pour les enregistrements longs, vous pouvez streamer la transcription au fur et à mesure de sa production plutôt que d'attendre le fichier entier. Cette primitive dialogue **directement** avec l'endpoint OpenAI-compatible `/audio/transcriptions` avec `stream=true` et parse les server-sent events nativement — elle **n'utilise pas** `experimental_transcribe` de l'AI SDK.

```ts theme={null}
import { createTranscriptionStreamingModel } from "@ai_kit/core";

const streamingModel = createTranscriptionStreamingModel({
  modelId: "whisper-large-v3",
  apiKey: process.env.SCALEWAY_API_KEY!,
  baseURL: "https://api.scaleway.ai/v1",
  providerName: "scaleway",
});

let full = "";
for await (const chunk of streamingModel.stream({
  audio: "/chemin/vers/audio.wav", // chemin / URL / Buffer / Uint8Array (auto-détecté)
  language: "fr",                  // code langue ISO-639-1, optionnel
})) {
  if (chunk.type === "delta") {
    full += chunk.textDelta;
    process.stdout.write(chunk.textDelta); // affichage à la volée
  } else {
    // événement final
    console.log("\nTerminé :", chunk.text, chunk.durationInSeconds);
  }
}
```

La sortie commence à streamer dès que le provider a traité le premier segment de 30 secondes — au bout de quelques secondes, et non après le fichier entier.

### Forme des chunks

```ts theme={null}
type TranscriptionStreamChunk =
  | { type: "delta"; textDelta: string }
  | { type: "done"; text: string; durationInSeconds?: number };
```

Les événements `delta` portent le texte incrémental ; l'unique événement `done` de fermeture porte le texte complet accumulé (égal à la concaténation de tous les deltas). Passez un `AbortSignal` via `abortSignal` pour annuler en cours de stream.

<Note>
  Le streaming utilise le format JSON par défaut — `verbose_json` (et donc les timestamps par segment) n'est pas disponible en streaming. Utilisez `transcribe` / `createTranscriptionModel` si vous avez besoin des `segments`.
</Note>

## `createTranscriptionTool` — attacher à un Agent

```ts theme={null}
import { createTranscriptionModel, createTranscriptionTool, Agent } from "@ai_kit/core";
import { scaleway } from "@ai_kit/core";

const whisperModel = createTranscriptionModel({
  modelId: "whisper-large-v3",
  apiKey: process.env.SCALEWAY_API_KEY!,
  baseURL: "https://api.scaleway.ai/v1",
});

const agent = new Agent({
  name: "assistant-medical",
  model: scaleway("gpt-oss-120b"),
  tools: {
    transcribeAudio: createTranscriptionTool(whisperModel, {
      description: "Transcrit un enregistrement audio médical en texte",
    }),
  },
});

const result = await agent.generate({
  prompt: "Transcris ce fichier : /enregistrements/consultation.mp3",
});
```

Le schéma du tool exposé au LLM : `audio` (chemin / URL / base64), `inputType`, `language`.

## Formats audio supportés

`flac`, `mp3`, `mp4`, `mpeg`, `mpga`, `m4a`, `ogg`, `wav`, `webm` (identique à OpenAI Whisper).
