> For the complete documentation index, see [llms.txt](https://docs.umbraco.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.umbraco.com/ai-in-umbraco/19.latest/extending/providers/speech-to-text-capability.md).

# Speech-to-Text Capability

Implement the speech-to-text capability for your custom provider.

The speech-to-text capability enables audio transcription. Implement it by extending `AISpeechToTextCapabilityBase<TSettings>`.

## Base Class

{% code title="AISpeechToTextCapabilityBase<TSettings>" %}

```csharp
public abstract class AISpeechToTextCapabilityBase<TSettings>(IAIProvider provider)
    : AICapabilityBase<TSettings>(provider), IAICapability<TSettings>, IAISpeechToTextCapability
    where TSettings : class
{
    // Override this (or CreateClientAsync) to create an ISpeechToTextClient
    protected virtual ISpeechToTextClient CreateClient(TSettings settings, string? modelId) { /* ... */ }

    // Override this for an async variant
    protected virtual Task<ISpeechToTextClient> CreateClientAsync(
        TSettings settings, string? modelId, CancellationToken cancellationToken = default) { /* ... */ }

    // Implement this: Return available models
    protected abstract Task<IReadOnlyList<AIModelDescriptor>> GetModelsAsync(
        TSettings settings,
        CancellationToken cancellationToken = default);
}
```

{% endcode %}

{% hint style="info" %}
`ISpeechToTextClient` is marked as `[Experimental("MEAI001")]` in Microsoft.Extensions.AI. Add `#pragma warning disable MEAI001` to your implementation files.
{% endhint %}

## Basic Implementation

{% code title="MySpeechToTextCapability.cs" %}

```csharp
#pragma warning disable MEAI001

using Microsoft.Extensions.AI;
using Umbraco.AI.Core.Models;
using Umbraco.AI.Core.Providers;

public class MySpeechToTextCapability : AISpeechToTextCapabilityBase<MyProviderSettings>
{
    public MySpeechToTextCapability(IAIProvider provider) : base(provider) { }

    protected override ISpeechToTextClient CreateClient(MyProviderSettings settings, string? modelId)
    {
        return new MySpeechToTextClient(settings, modelId ?? "default-stt-model");
    }

    protected override Task<IReadOnlyList<AIModelDescriptor>> GetModelsAsync(
        MyProviderSettings settings,
        CancellationToken cancellationToken = default)
    {
        var models = new List<AIModelDescriptor>
        {
            new(new AIModelRef(Provider.Id, "stt-standard"), "Standard Transcription"),
            new(new AIModelRef(Provider.Id, "stt-enhanced"), "Enhanced Transcription")
        };
        return Task.FromResult<IReadOnlyList<AIModelDescriptor>>(models);
    }
}
```

{% endcode %}

## Register in Provider

Add the speech-to-text capability in your provider constructor:

{% code title="MyProvider.cs" %}

```csharp
[AIProvider("myprovider", "My AI Provider")]
public class MyProvider : AIProviderBase<MyProviderSettings>
{
    public MyProvider(IAIProviderInfrastructure infrastructure)
        : base(infrastructure)
    {
        WithCapability<MyChatCapability>();
        WithCapability<MyEmbeddingCapability>();
        WithCapability<MySpeechToTextCapability>();  // Add speech-to-text support
    }
}
```

{% endcode %}

## Using Existing `Microsoft.Extensions.AI` Clients

If your AI service has an existing `Microsoft.Extensions.AI` speech-to-text client, use it directly. For example, with OpenAI:

{% code title="Using OpenAI Client" %}

```csharp
#pragma warning disable MEAI001

using Microsoft.Extensions.AI;
using OpenAI;

public class MyOpenAICompatibleSTTCapability : AISpeechToTextCapabilityBase<MyProviderSettings>
{
    public MyOpenAICompatibleSTTCapability(IAIProvider provider) : base(provider) { }

    protected override ISpeechToTextClient CreateClient(MyProviderSettings settings, string? modelId)
    {
        var client = new OpenAIClient(new ApiKeyCredential(settings.ApiKey));
        return client.GetAudioClient(modelId ?? "whisper-1").AsISpeechToTextClient();
    }

    protected override Task<IReadOnlyList<AIModelDescriptor>> GetModelsAsync(
        MyProviderSettings settings,
        CancellationToken cancellationToken = default)
    {
        return Task.FromResult<IReadOnlyList<AIModelDescriptor>>(new List<AIModelDescriptor>
        {
            new(new AIModelRef(Provider.Id, "whisper-1"), "Whisper"),
            new(new AIModelRef(Provider.Id, "gpt-4o-transcribe"), "GPT-4o Transcribe"),
            new(new AIModelRef(Provider.Id, "gpt-4o-mini-transcribe"), "GPT-4o Mini Transcribe")
        });
    }
}
```

{% endcode %}

## Related

* [Creating a Provider](/ai-in-umbraco/19.latest/extending/providers/creating-a-provider.md) - Provider setup
* [Chat Capability](/ai-in-umbraco/19.latest/extending/providers/chat-capability.md) - Chat capability implementation
* [Embedding Capability](/ai-in-umbraco/19.latest/extending/providers/embedding-capability.md) - Embedding capability implementation
* [Speech-to-Text API](/ai-in-umbraco/19.latest/using-the-api/speech-to-text.md) - Using the Speech-to-Text API


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.umbraco.com/ai-in-umbraco/19.latest/extending/providers/speech-to-text-capability.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
