> 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/17.latest/extending/providers/speech-to-text-capability.md).

# Speech-to-Text Capability

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/17.latest/extending/providers/creating-a-provider.md) - Provider setup
* [Chat Capability](/ai-in-umbraco/17.latest/extending/providers/chat-capability.md) - Chat capability implementation
* [Embedding Capability](/ai-in-umbraco/17.latest/extending/providers/embedding-capability.md) - Embedding capability implementation
* [Speech-to-Text API](/ai-in-umbraco/17.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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
