# Speech analysis (https://docs.cochl.ai/docs/pro/speech-analysis)



**Speech analysis** turns the speech in an uploaded audio file into structured data—*what* was said and *who* said it. It has two capabilities working together:

* **Transcription**—speech to text, segmented by speaker turn.
* **Speaker profile**—populates `speaker_name` with a registered name when the voice matches a [Custom sound: Speaker profile](https://docs.cochl.ai/docs/pro/speech-analysis/custom-speaker-profile) you’ve registered. Voices that don’t match a profile get `Unknown 0`, `Unknown 1`, … instead, numbered to match the diarization label in `speaker` (`SPEAKER_00`, `SPEAKER_01`, …). Registering profiles needs speaker recognition to be enabled for your organization — see [When every speaker is Unknown](#when-speaker_name-is-missing).

Speech analysis is available on **Cochl.Sense Pro projects only**.

## 1. Transcription output [#1-transcription-output]

Transcription returns one segment per uninterrupted speaker turn. A 30-second clip with two speakers trading off might produce ten segments of varying length, not 30 one-second chunks. Inside the Integration API response it appears under the `speech_analysis` key:

```json
{
  "speech_analysis": {
    "status": "success",
    "results": [
      {
        "speaker": "SPEAKER_00",
        "speaker_name": "Unknown 0",
        "speaker_score": 0.08,
        "transcript": "I've never enjoyed challenging high-profile roles.",
        "start_time": "00:00.00",
        "end_time": "00:05.27",
        "start_time_sec": 0.0,
        "end_time_sec": 5.27
      },
      {
        "speaker": "SPEAKER_01",
        "speaker_name": "Christian_Bale",
        "speaker_score": 0.41,
        "transcript": "But the directing pulled me in.",
        "start_time": "00:05.34",
        "end_time": "00:07.91",
        "start_time_sec": 5.34,
        "end_time_sec": 7.91
      }
    ]
  }
}
```

| Field                            | Meaning                                                                                                                                                                                                                                                                                                                                                                                                |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `speaker`                        | Diarization label (`SPEAKER_00`, `SPEAKER_01`, …). Stable within a single file; not stable across files.                                                                                                                                                                                                                                                                                               |
| `speaker_name`                   | Registered profile name when this voice matches a [Custom sound: Speaker profile](https://docs.cochl.ai/docs/pro/speech-analysis/custom-speaker-profile). Otherwise `Unknown <n>`, where `<n>` is the number in the `speaker` label (`SPEAKER_01` → `Unknown 1`). Present when the `speaker_profile` option is on (the Python library turns it on together with speech analysis); otherwise the segment has `speaker` only. |
| `speaker_score`                  | Present together with `speaker_name`: the similarity between this voice and the closest registered profile, as a number rounded to three decimals (higher is more confident). `Unknown` segments carry a score too — the closest profile just didn’t score high enough — and it is `-1.0` when the organization has no registered profiles.                                                            |
| `transcript`                     | The recognized text for this turn.                                                                                                                                                                                                                                                                                                                                                                     |
| `start_time`, `end_time`         | Segment boundaries as a string — `MM:SS.SS`, or `HH:MM:SS.SS` for times from the 1-hour mark on. For display only.                                                                                                                                                                                                                                                                                     |
| `start_time_sec`, `end_time_sec` | Segment boundaries in seconds (float). Use these for math.                                                                                                                                                                                                                                                                                                                                             |

Segments carry no language field; the spoken language is reported once per file by [audio insights](https://docs.cochl.ai/docs/pro/audio-insights) (see [Supported languages](#2-supported-languages)). Each segment also has an `item_ids` object (identifiers used for result feedback), which you can ignore.

<div id="when-speaker_name-is-missing" style="{ scrollMarginTop: '6rem' }" />

<Callout type="info" title="When every speaker is Unknown">
  Turns that match no registered profile get `Unknown 0`, `Unknown 1`, … in `speaker_name`, with the closest profile’s score in `speaker_score` (`-1.0` when your organization has no profiles). Registering profiles needs speaker recognition to be enabled for your organization; contact [support@cochl.ai](mailto:support@cochl.ai) to have it turned on. `speaker_name` and `speaker_score` are left out when `speaker_profile` is off.
</Callout>

On the Dashboard’s **Speech analysis** page, those segments appear in the result’s **Speech analysis** tab as a scrollable log with per-speaker color coding. Clicking a segment seeks the audio player to that point.

<img src="/images/pro/speech-analysis/dashboard-transcription.png" alt="Speech analysis transcript view in the Dashboard" />

## 2. Supported languages [#2-supported-languages]

Transcription detects the spoken language automatically. The `speech_lang` option is no longer applied: if you send a language code other than `multi`, the request still runs and `metadata.warnings` contains `speech_lang was not applied: the speech model detects the language automatically.` The speech analysis segments themselves don’t carry a language field — the detected language is reported for the whole file in [audio insights](https://docs.cochl.ai/docs/pro/audio-insights) as `detected_language`, a lowercase language code (or `"N/A"` when there is no speech). Codes are [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes) where one exists. **More than 50 languages** are supported.

```json
"detected_language": "en"
```

### Code-switching [#code-switching]

When a single recording mixes more than one language — bilingual speakers, Korean speakers borrowing English terms, voiceovers that switch tracks — audio insights reports **every language it detects**, as codes joined by commas with no spaces:

```json
"detected_language": "ko,en"
```

You don’t need to opt in. Split the value on `,` to get a list; it is a single code, a comma-separated list of codes, or `"N/A"`.

## 3. Speaker profile [#3-speaker-profile]

A **Speaker profile** is a voice fingerprint you create by uploading or recording audio samples of one person. Once registered, Cochl.Sense matches that profile in any new upload and exposes the registered name in `speaker_name` (with a similarity in `speaker_score`), as long as speaker recognition is enabled for your organization ([details](#when-speaker_name-is-missing)).

Use speaker profiles when you need:

* Meeting and interview transcripts that name participants automatically.
* Searchable archives where you can jump to “everything spoken by Anna”.
* Per-speaker analytics—talk time, turn counts, etc.

To register a profile, see [Custom sound: Speaker profile](https://docs.cochl.ai/docs/pro/speech-analysis/custom-speaker-profile).

## 4. Run speech analysis [#4-run-speech-analysis]

### Via the Dashboard [#via-the-dashboard]

1. On the [Dashboard](https://dashboard.cochl.ai/), pick your Cochl.Sense Pro project at the top of the sidebar, then open **Speech analysis** under **Project**.
2. Drop your file (or record, or pick a sample) and click **Analyze**. This page runs speech analysis on its own; to run it together with the other services in one request, use the API or the Python library.
3. When the job completes, the result opens on the **Speech analysis** tab: the transcript with who spoke each line. You can search the transcript and filter by speaker. The run is also kept under **History** in the sidebar, so you can reopen it later in the same browser ([Dashboard → History](https://docs.cochl.ai/docs/pro/dashboard#3-history)).

### Via the Python library (recommended) [#via-the-python-library-recommended]

Use the `IntegratedApi` helper from the `cochl` library.

```python
from cochl.sense import IntegratedApi, IntegratedApiOptions

api = IntegratedApi('YOUR_API_PROJECT_KEY')

job = api.analyze_file(
    'your_file.wav',
    IntegratedApiOptions(
        sound_event_detection=False,  # the service flags default to True,
        speech_analysis=True,
        audio_insights=False,         # so turn off the ones you don't want
    ),
)

result = api.get_completed_result(job['job_id'])
for seg in result['speech_analysis']['results']:
    label = seg.get('speaker_name') or seg['speaker']
    print(f"[{seg['start_time_sec']:5.2f}–{seg['end_time_sec']:5.2f}] "
          f"{label}: {seg['transcript']}")
```

Running this on a 30-second interview clip with two speakers prints something like:

```text
[ 0.00– 4.32] Unknown 0: So, growing up, your father had a really strong influence on you.
[ 4.60– 8.91] Christian_Bale: Yeah, he taught me to never settle for the obvious choice.
[ 9.20–12.05] Unknown 0: And that carried into your acting?
[12.30–17.88] Christian_Bale: Absolutely. Every role becomes a question of what's underneath the surface.
```

And the corresponding `result` dict:

```json
{
  "speech_analysis": {
    "status": "success",
    "results": [
      {
        "speaker": "SPEAKER_00",
        "speaker_name": "Unknown 0",
        "speaker_score": 0.08,
        "transcript": "So, growing up, your father had a really strong influence on you.",
        "start_time": "00:00.00",
        "end_time": "00:04.32",
        "start_time_sec": 0.0,
        "end_time_sec": 4.32
      },
      {
        "speaker": "SPEAKER_01",
        "speaker_name": "Christian_Bale",
        "speaker_score": 0.41,
        "transcript": "Yeah, he taught me to never settle for the obvious choice.",
        "start_time": "00:04.60",
        "end_time": "00:08.91",
        "start_time_sec": 4.6,
        "end_time_sec": 8.91
      }
    ]
  }
}
```

The `SPEAKER_01` segment carries `speaker_name: "Christian_Bale"` because a profile with that name was registered ahead of time via [Custom sound: Speaker profile](https://docs.cochl.ai/docs/pro/speech-analysis/custom-speaker-profile). Unmatched turns get `Unknown <n>` in `speaker_name`, numbered to match their `speaker` label (`SPEAKER_00` → `Unknown 0`).

Set `sound_event_detection=True` in the same `IntegratedApiOptions` to also detect non-speech events, or `audio_insights=True` to add a summary. Sound event detection is billed at $0.012 per minute; speech analysis and audio insights are free for now — see [Getting Started → Valid service combinations](https://docs.cochl.ai/docs/pro/getting-started#4-valid-service-combinations) and [Usage & pricing](https://docs.cochl.ai/docs/pro/getting-started#5-usage--pricing).

<Card title="&#x22;cochlearai/cochl-sense-py&#x22;" description="&#x22;More runnable sample scripts.&#x22;" href="https://github.com/cochlearai/cochl-sense-py" />

#### Advanced: stream progress yourself [#advanced-stream-progress-yourself]

`get_completed_result` blocks until the job finishes. If you want to render a progress bar or display partial results as they arrive, subscribe to the SSE stream directly:

```python
from urllib.request import Request, urlopen

from cochl.sense import IntegratedApi, IntegratedApiOptions

def main():
    # 1. Authenticate with the project key.
    api = IntegratedApi('YOUR_API_PROJECT_KEY')

    # 2. Speech Analysis only. The service flags default to True, so set the
    #    others to False explicitly (or True to combine).
    options = IntegratedApiOptions(
        sound_event_detection=False,
        speech_analysis=True,
        audio_insights=False,
    )

    # 3. Upload the file — the server enqueues a job and returns its id.
    job: dict = api.analyze_file('YOUR_AUDIO_FILE_PATH', options)
    if 'job_id' not in job:
        print('ERROR: analyze_file did not return a job_id')
        return
    job_id: str = job['job_id']

    # 4. Subscribe to the SSE stream. Each line is either:
    #      event: metadata | progress | partial_result | completed | error
    #      data:  <JSON payload>
    #    The first event is always `metadata` (audio info and warnings).
    request: Request = api.create_event_stream_request(job_id)
    with urlopen(request) as response:
        for line in response:
            line = line.decode('utf-8').strip()
            if line.startswith('event: ') or line.startswith('data: '):
                print(line)

if __name__ == '__main__':
    main()
```

Use this pattern only when you need to react to progress events as they arrive. For “upload, wait, get the dict”, `get_completed_result(job_id)` is shorter and handles the SSE plumbing for you.

## 5. Export results [#5-export-results]

In the Dashboard result view, the **JSON** tab shows the full payload (every service that ran, in one object). The **Export** menu above the result has **Copy JSON**, &#x2A;*Result (JSON)** to save it as a file, &#x2A;*Sound Events (CSV)** (when sound events ran) to save them as a table, and **Get code** for the same request in cURL or Python.

<img src="/images/pro/speech-analysis/view-json-speech.png" alt="The JSON tab of an analysis result in the Dashboard" />

## 6. Best practices [#6-best-practices]

* For best transcription accuracy, use a sample rate of 16 kHz or higher and minimize background music.
* Speaker matching works best when the profile’s recording conditions (microphone, room) are similar to those of the upload.
* Unknown speakers get `Unknown <n>` in `speaker_name` and a diarization `speaker` label (`SPEAKER_00`, `SPEAKER_01`, …) that is stable within a single file. Neither persists across files — `SPEAKER_00` or `Unknown 0` in two different uploads is not necessarily the same person.

## See also [#see-also]

* [Custom sound: Speaker profile](https://docs.cochl.ai/docs/pro/speech-analysis/custom-speaker-profile)—register voices so they appear by name in `speaker_name` instead of as `Unknown <n>`
* [Sound event detection](https://docs.cochl.ai/docs/pro/sound-event-detection)—detect non-speech events in parallel
* [Audio insights](https://docs.cochl.ai/docs/pro/audio-insights)—high-level scene summary, which uses transcript context when speech is present
