# Azure - AI Speech

> Ejecuta reconocimiento automático de voz (ASR) de nivel de producción sobre flujos de audio con Microsoft Azure AI Speech.

Source: https://docs.sommatic.ai/es/nodes/integrations.microsoft.azure.speech/

- Slug: `integrations.microsoft.azure.speech`
- Familia: Integraciones
- Versión: 1.0.0
- Estado: Disponible
- Ejecución: async

Ejecuta reconocimiento automático de voz (ASR) de nivel de producción sobre flujos de audio con Microsoft Azure AI Speech.

Se autentica con tu propio recurso de Azure mediante `connection_id` (credencial api-key con los metadatos de `region`); Azure factura los costos de ejecución a tu suscripción.

**Operaciones:**
- **Reconocimiento continuo:** Procesa audio de cualquier duración mediante el endpoint de reconocimiento de larga duración: reuniones, llamadas, contenido multimedia extenso.
- **Diarización de hablantes:** Cuando `diarization.enabled` es true, usa ConversationTranscriber para etiquetar cada segmento con un identificador de hablante y devolver un arreglo `speakers` estructurado.
- **Sesgo con vocabulario personalizado:** Lista de frases que se inyecta en el reconocedor para mejorar la precisión con nombres, siglas, términos de producto y jerga.
- **Selección de configuración regional:** Más de 100 configuraciones regionales BCP-47 (`es-CO`, `en-US`, `pt-BR`, `fr-FR`, ...); la API subyacente ofrece detección automática cuando no se indica ninguna.
- **Marcas de tiempo por segmento:** Marcas de inicio y fin por segmento devueltas en `segments` para subtítulos, capítulos y anclaje de evidencias.

## Configuración

- `connection_id` (string, obligatorio): Credencial de conexión con region + api-key de tu recurso de Azure AI Speech.
- `language` (string, opcional, acepta expresiones): Configuración regional BCP-47 (p. ej., es-CO, en-US, pt-BR, fr-FR). Déjala vacía para la detección automática.
- `diarization` (object, opcional)
  - `enabled` (boolean, opcional): Activa la diarización de hablantes (ConversationTranscriber). Por defecto: `false`.
- `custom_vocabulary` (array<string>, opcional): Lista de frases para orientar el reconocedor hacia nombres, siglas o terminología del dominio.

Su configuración muestra los ajustes de ejecución compartidos, pero este nodo aún no aplica reintentos (`retryOnFail`, `maxTries`). Ningún nodo aplica `continueOnFail`.

## Puertos de salida

- `extracted` (por defecto): Transcribed
- `empty`: No Speech
- `error`: Error

## Contrato de entrada

- `content_base64` (string, opcional)
- `file_path` (string, opcional)

## Contrato de salida

- `text` (string, opcional)
- `chars` (number, opcional)
- `empty` (boolean, opcional)
- `method` (string, opcional)
- `metadata` (object, opcional)
- `segments` (array, opcional)
- `speakers` (array, opcional)

## En expresiones

Lo que un nodo posterior puede leer de la salida de este nodo con `$("Azure - AI Speech").item.json.<ruta>` (escribe la etiqueta de tu nodo en lugar de `Azure - AI Speech`). **Editor** marca las rutas que sugiere el editor de workflows en Previous Nodes (el contrato de salida); **Worker** marca las rutas que el worker devuelve de verdad por `extracted`, según la salida que muestra Puertos.

- `$("Azure - AI Speech").item.json.text` (string) = `"Good morning, I am calling about order 123."`
- `$("Azure - AI Speech").item.json.chars` (number) = `43`
- `$("Azure - AI Speech").item.json.empty` (boolean) = `false`
- `$("Azure - AI Speech").item.json.method` (string) = `"azure-speech-diarized"`
- `$("Azure - AI Speech").item.json.metadata` (object) = `{…}`
- `$("Azure - AI Speech").item.json.segments` (array) = `[…] (1)`
- `$("Azure - AI Speech").item.json.speakers` (array) = `[…] (1)`
- `$("Azure - AI Speech").item.json.metadata.language` (string) = `"en-US"` (El editor no la sugiere)
- `$("Azure - AI Speech").item.json.metadata.region` (string) = `"eastus"` (El editor no la sugiere)
- `$("Azure - AI Speech").item.json.metadata.diarization_enabled` (boolean) = `true` (El editor no la sugiere)
- `$("Azure - AI Speech").item.json.metadata.segments_count` (number) = `1` (El editor no la sugiere)
- `$("Azure - AI Speech").item.json.metadata.speakers_count` (number) = `1` (El editor no la sugiere)


## Cómo funciona

Transcribe un archivo de audio con Azure AI Speech usando tu propio recurso, con separación de hablantes opcional, y devuelve el texto con segmentos temporizados. Sale por `empty` cuando no reconoce voz.

1. Resuelve la configuración del nodo. Lee `content_base64` o `file_path` primero de la configuración y luego del ítem de entrada; exige `connection_id` y uno de los dos.
2. Resuelve la credencial en el servidor: el secreto debe contener `apiKey` (o `api_key`) y `region` se lee de la configuración de la credencial o del secreto.
3. Ejecuta un proceso de Python. El contenido base64 se escribe en un `audio.wav` temporal; un `file_path` existente se usa directamente.
4. Reconoce de forma continua con `language` cuando está definido. Con `diarization.enabled` usa el transcriptor de conversaciones y marca cada segmento con `speaker`.
5. Construye `{ text, chars, empty, method, metadata, segments, speakers }` y elige `empty` si el texto está vacío; si no, `extracted`.

## En un workflow

### Nodo

```json
{
  "node_id": "node-transcribe-call",
  "label": "Transcribe call",
  "operator_slug": "integrations.microsoft.azure.speech",
  "operator_version": "1.0.0",
  "config": {
    "connection_id": "pi-credential-xxxx",
    "language": "en-US",
    "diarization": {
      "enabled": true
    }
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "text": "Good morning, I am calling about order 123.",
    "chars": 43,
    "empty": false,
    "method": "azure-speech-diarized",
    "metadata": {
      "language": "en-US",
      "region": "eastus",
      "diarization_enabled": true,
      "segments_count": 1,
      "speakers_count": 1
    },
    "segments": [
      {
        "start_ms": 420,
        "duration_ms": 2860,
        "speaker": "Guest-1",
        "text": "Good morning, I am calling about order 123."
      }
    ],
    "speakers": [
      {
        "id": "Guest-1",
        "segment_indexes": [
          0
        ]
      }
    ]
  },
  "port": "extracted"
}
```

## Puertos de salida (comportamiento en el código)

### `extracted`

Se reconoció voz.

```json
{
  "text": "Good morning, I am calling about order 123.",
  "chars": 43,
  "empty": false,
  "method": "azure-speech-diarized",
  "metadata": {
    "language": "en-US",
    "region": "eastus",
    "diarization_enabled": true,
    "segments_count": 1,
    "speakers_count": 1
  },
  "segments": [
    {
      "start_ms": 420,
      "duration_ms": 2860,
      "speaker": "Guest-1",
      "text": "Good morning, I am calling about order 123."
    }
  ],
  "speakers": [
    {
      "id": "Guest-1",
      "segment_indexes": [
        0
      ]
    }
  ]
}
```

### `empty`

El reconocimiento terminó sin texto. Una sesión cancelada (por ejemplo, una llave inválida o un formato de audio no compatible) también termina aquí, porque la cancelación detiene el reconocimiento sin generar error.

```json
{
  "text": "",
  "chars": 0,
  "empty": true,
  "method": "azure-speech",
  "metadata": {
    "language": "en-US",
    "region": "eastus",
    "diarization_enabled": false,
    "segments_count": 0,
    "speakers_count": 0
  },
  "segments": [],
  "speakers": []
}
```

### `error`

Falló la validación, la resolución de la credencial o el proceso de Python.

```json
{
  "error": "connection must provide region + apiKey"
}
```

## Comportamiento en el código

- `language`: Si está vacío no se define idioma de reconocimiento y se aplica el predeterminado del Speech SDK; el worker no configura detección automática de idioma.
- `custom_vocabulary`: No se aplica en esta versión: la lista de frases se asocia a un reconocedor que se descarta antes de iniciar la transcripción.
- `execution`: Solo se lee `timeout_ms` (por defecto 900000). La configuración de reintentos no se aplica.

## Errores

| Mensaje | Puerto | Causa y solución |
| --- | --- | --- |
| `connection_id is required.` | `error` | No hay credencial configurada. |
| `Either content_base64 or file_path is required.` | `error` | El ítem de entrada no trae ninguno de los dos campos. |
| `connection must provide region + apiKey` | `error` | El secreto de la credencial no es un objeto con `apiKey`, o no hay `region` guardada. |
| `Python timed out after <ms>ms` | `error` | La transcripción tardó más que `execution.timeout_ms` (por defecto 900000). |

## Notas y límites

- El audio se lee como archivo WAV. Convierte otros formatos (MP3, OGG) a WAV antes de este nodo.
- `start_ms` y `duration_ms` están en milisegundos. `speakers` lista cada hablante con los índices de sus segmentos.
- La primera ejecución en un servidor instala las dependencias de Python, lo que puede tardar minutos. El consumo de Azure se factura a tu propio recurso.


## Contratos (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "integrations.microsoft.azure.speech",
  "name": "Azure - AI Speech",
  "category": "integrations",
  "group": [
    {
      "key": "microsoft",
      "name": "Microsoft",
      "icon_url": "/icons/integrations/microsoft/microsoft.svg"
    },
    {
      "key": "foundry",
      "name": "Microsoft Foundry",
      "icon_url": "/icons/integrations/microsoft/foundry.webp"
    }
  ],
  "icon_url": "/icons/integrations/microsoft/microsoft.svg",
  "version": "1.0.0",
  "description": "Execute production-grade Automatic Speech Recognition (ASR) on audio streams using Microsoft Azure AI Speech.\n\n  Authenticates with your own Azure resource via `connection_id` (api-key credential with `region` metadata); execution costs are billed by Azure to your subscription.\n\n  **Operations:**\n  - **Continuous recognition:** Streams audio of any length through the long-running recognition endpoint — meetings, calls, long-form media.\n  - **Speaker diarization:** When `diarization.enabled` is true, uses the ConversationTranscriber to tag each segment with a speaker identifier and return a structured `speakers` array.\n  - **Custom vocabulary bias:** Phrase list injected into the recognizer to improve accuracy on names, acronyms, product terms, and jargon.\n  - **Locale selection:** 100+ BCP-47 locales (`es-CO`, `en-US`, `pt-BR`, `fr-FR`, ...); auto-detection is available in the underlying API when no locale is supplied.\n  - **Segment timestamps:** Per-segment start/end timestamps returned in `segments` for subtitles, chaptering, and evidence anchoring.",
  "capabilities": [
    "speech",
    "asr",
    "transcription",
    "diarization",
    "azure",
    "cloud"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string",
        "title": "Azure AI Speech Credential",
        "description": "Connection credential with region + api-key for your Azure AI Speech resource.",
        "ui_widget": "connection_picker",
        "ui_options": {
          "credential_types": [
            "api-key",
            "object"
          ],
          "providers": [
            "azure"
          ]
        }
      },
      "language": {
        "type": "string",
        "title": "Recognition Language",
        "description": "BCP-47 locale (e.g., es-CO, en-US, pt-BR, fr-FR). Leave empty for auto-detection.",
        "format": "expression"
      },
      "diarization": {
        "type": "object",
        "title": "Diarization",
        "properties": {
          "enabled": {
            "type": "boolean",
            "default": false,
            "description": "Enable speaker diarization (ConversationTranscriber)."
          }
        }
      },
      "custom_vocabulary": {
        "type": "array",
        "title": "Custom Vocabulary",
        "items": {
          "type": "string"
        },
        "description": "Phrase list to bias the recognizer toward names, acronyms, or domain terminology."
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    },
    "required": [
      "connection_id"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "content_base64": {
        "type": "string"
      },
      "file_path": {
        "type": "string"
      }
    }
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "text": {
        "type": "string"
      },
      "chars": {
        "type": "number"
      },
      "empty": {
        "type": "boolean"
      },
      "method": {
        "type": "string"
      },
      "metadata": {
        "type": "object"
      },
      "segments": {
        "type": "array"
      },
      "speakers": {
        "type": "array"
      }
    }
  },
  "ports": [
    {
      "port_id": "extracted",
      "label": "Transcribed",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "empty",
      "label": "No Speech",
      "is_default": false,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "standard-io",
    "cloud-io"
  ],
  "tags": [
    "azure",
    "speech",
    "asr",
    "diarization"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://sommatic.ai",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "connection_id": {
      "type": "string",
      "title": "Azure AI Speech Credential",
      "description": "Connection credential with region + api-key for your Azure AI Speech resource.",
      "ui_widget": "connection_picker",
      "ui_options": {
        "credential_types": [
          "api-key",
          "object"
        ],
        "providers": [
          "azure"
        ]
      }
    },
    "language": {
      "type": "string",
      "title": "Recognition Language",
      "description": "BCP-47 locale (e.g., es-CO, en-US, pt-BR, fr-FR). Leave empty for auto-detection.",
      "format": "expression"
    },
    "diarization": {
      "type": "object",
      "title": "Diarization",
      "properties": {
        "enabled": {
          "type": "boolean",
          "default": false,
          "description": "Enable speaker diarization (ConversationTranscriber)."
        }
      }
    },
    "custom_vocabulary": {
      "type": "array",
      "title": "Custom Vocabulary",
      "items": {
        "type": "string"
      },
      "description": "Phrase list to bias the recognizer toward names, acronyms, or domain terminology."
    },
    "execution": {
      "type": "object",
      "title": "Execution Settings",
      "properties": {
        "alwaysOutputData": {
          "type": "boolean",
          "title": "Always Output Data",
          "description": "Always output data, even on error (if configured).",
          "default": false
        },
        "retryOnFail": {
          "type": "boolean",
          "title": "Retry On Fail",
          "description": "Retry the execution if it fails.",
          "default": false
        },
        "maxTries": {
          "type": "integer",
          "title": "Max Retries",
          "description": "Number of retries.",
          "default": 3,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "waitBetweenTries": {
          "type": "integer",
          "title": "Wait Between Retries (ms)",
          "default": 1000,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "continueOnFail": {
          "type": "boolean",
          "title": "Continue On Fail",
          "description": "Do not crash workflow on error.",
          "default": false
        },
        "timeout_ms": {
          "type": "integer",
          "title": "Timeout (ms)",
          "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
          "default": 300000
        }
      }
    }
  },
  "required": [
    "connection_id"
  ]
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "content_base64": {
      "type": "string"
    },
    "file_path": {
      "type": "string"
    }
  }
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "text": {
      "type": "string"
    },
    "chars": {
      "type": "number"
    },
    "empty": {
      "type": "boolean"
    },
    "method": {
      "type": "string"
    },
    "metadata": {
      "type": "object"
    },
    "segments": {
      "type": "array"
    },
    "speakers": {
      "type": "array"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "extracted",
    "label": "Transcribed",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "empty",
    "label": "No Speech",
    "is_default": false,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "is_default": false,
    "supports_condition": false
  }
]
```
