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

# Transcribe an interview or podcast with speaker labels

> Send one interview or podcast URL and get a transcript where every line is tagged with who said it, then show the conversation by speaker or pull one person's lines. Node and Python.

An interview, podcast or panel is only useful once you know who said what. Doing that yourself means downloading the audio, working out where each voice starts and stops, and stitching the names back onto the text. Importly does it in one request: send the URL with `speakerLabels: true` and every transcript segment comes back with a `speaker` field, so you can render the conversation by speaker or pull out everything one guest said.

This script takes a link, transcribes it with speaker labels, prints the conversation, and then collects one speaker's lines. It works on any public interview or podcast URL (YouTube, a podcast MP3, an uploaded file) and needs no dependencies in Node, and `requests` in Python.

## The code

```js transcribe-interview.mjs theme={null}
const url = process.argv[2]
const API = 'https://api.importly.io'
const headers = {
  Authorization: `Bearer ${process.env.IMPORTLY_API_KEY}`,
  'Content-Type': 'application/json',
}

const fail = (message) => {
  console.error(message)
  process.exit(1)
}

// Start the transcription with speaker labels.
const start = await fetch(`${API}/transcribe`, {
  method: 'POST',
  headers,
  body: JSON.stringify({
    url,
    speakerLabels: true, // tag each segment with "A", "B", ...
    speakersExpected: 2, // an interview: host + guest. Leave out when you're unsure.
    maxCostDollars: 1.0, // cap the speech-to-text charge
  }),
})
const started = await start.json()
if (!started.success) fail(`${started.code}: ${started.error}`)

// Speaker labels always use speech-to-text, so collect the result by polling.
const { jobId } = started.data
let result
while (true) {
  const res = await fetch(`${API}/transcribe/status?id=${jobId}`, { headers })
  const { data } = await res.json()
  if (data.status === 'completed') {
    result = data.result
    break
  }
  if (data.status === 'failed') fail(`${data.code}: ${data.message}`)
  await new Promise((resolve) => setTimeout(resolve, 5000))
}

const segments = result.data.segments

// 1. The conversation, one line per turn.
for (const s of segments) {
  console.log(`${s.speaker}: ${s.text}`)
}

// 2. Everything one speaker said, as one block of text.
const speakerA = segments
  .filter((s) => s.speaker === 'A')
  .map((s) => s.text)
  .join(' ')
console.log(`\nSpeaker A only:\n${speakerA}`)
```

```python transcribe_interview.py theme={null}
import os
import sys
import time

import requests

url = sys.argv[1]
API = "https://api.importly.io"
headers = {"Authorization": f"Bearer {os.environ['IMPORTLY_API_KEY']}"}


def fail(message):
    raise SystemExit(message)


# Start the transcription with speaker labels.
started = requests.post(
    f"{API}/transcribe",
    headers=headers,
    json={
        "url": url,
        "speakerLabels": True,  # tag each segment with "A", "B", ...
        "speakersExpected": 2,  # an interview: host + guest. Leave out when you're unsure.
        "maxCostDollars": 1.0,  # cap the speech-to-text charge
    },
).json()
if not started["success"]:
    fail(f"{started['code']}: {started['error']}")

# Speaker labels always use speech-to-text, so collect the result by polling.
job_id = started["data"]["jobId"]
while True:
    data = requests.get(
        f"{API}/transcribe/status", headers=headers, params={"id": job_id}
    ).json()["data"]
    if data["status"] == "completed":
        result = data["result"]
        break
    if data["status"] == "failed":
        fail(f"{data['code']}: {data['message']}")
    time.sleep(5)

segments = result["data"]["segments"]

# 1. The conversation, one line per turn.
for s in segments:
    print(f"{s['speaker']}: {s['text']}")

# 2. Everything one speaker said, as one block of text.
speaker_a = " ".join(s["text"] for s in segments if s["speaker"] == "A")
print(f"\nSpeaker A only:\n{speaker_a}")
```

Run it on a short, public interview:

```bash theme={null}
# Node
node transcribe-interview.mjs "https://www.youtube.com/watch?v=VIDEO_ID"

# Python
python transcribe_interview.py "https://www.youtube.com/watch?v=VIDEO_ID"
```

## What comes back

Every segment carries a `speaker` (`"A"`, `"B"`, and so on), and a new segment starts whenever the speaker changes:

```json theme={null}
{
  "segments": [
    { "start": 0.64, "end": 4, "text": "How long did it take you to develop the Game Boy?", "speaker": "A" },
    { "start": 5.76, "end": 6.64, "text": "Game Boy?", "speaker": "B" },
    { "start": 9.44, "end": 10.8, "text": "Probably three or four years.", "speaker": "B" }
  ]
}
```

`A` is whoever speaks first. The labels are letters, not names, so map `A` and `B` to the host and guest in your app. Because each segment has one speaker, a quick reply that cuts in splits the sentence at that point, so a segment can be a short piece of a sentence.

## Notes that save you a round trip

Speaker labels always use speech-to-text. Captions don't say who is speaking, so the audio is transcribed at \$0.01 per started minute, even when the video has captions. `maxCostDollars` caps that, so a long interview over the cap fails with `MAX_COST_EXCEEDED` instead of running over it.

`speakersExpected` is a ceiling, not a target. Set it when you know the count (2 for a one-on-one). A number higher than the real count doesn't invent speakers, but a number lower than it merges people, so leave it out when you're unsure.

Non-English interviews work the same way. Leave `language` out and the spoken language is detected; pass a code such as `"es"` when you know it. Every [supported language](/docs/features/transcripts.md#supported-languages) has speaker labels.

Need the audio file as well? Add the same options to an import: send `transcriptSpeakerLabels: true` to [`POST /import`](/docs/endpoints/import) and you get the media file and the speaker-labelled transcript from one job. See [transcripts inside an import](/docs/features/transcripts.md#transcripts-inside-an-import).

> [card] [Full reference: who said what](/docs/features/transcripts.md#who-said-what)
>
> Every speaker-label option, the response shape and the pricing.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.