# OpenAISpeechBuilderExtensions

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.openaispeechbuilderextensions/
> Summary: OpenAISpeechBuilderExtensions: Adds OpenAI speech to the Tracon chain.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.OpenAI.dll</code></div>

Adds OpenAI speech to the Tracon chain.

```csharp
public static class OpenAISpeechBuilderExtensions
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="/api/tracon.openaispeechbuilderextensions/">OpenAISpeechBuilderExtensions</a></dd><dt>Inherited Members</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a></dd></dl>

## Methods

### <a id="Tracon_OpenAISpeechBuilderExtensions_UseOpenAISpeech_Tracon_ITraconBuilder_System_Action_Tracon_OpenAISpeechOptions__"></a> UseOpenAISpeech\(ITraconBuilder, Action<OpenAISpeechOptions\>\)

Registers OpenAI text-to-speech and speech-to-text as named Tracon speech providers.

```csharp
public static ITraconBuilder UseOpenAISpeech(this ITraconBuilder builder, Action<OpenAISpeechOptions> configure)
```

#### Parameters

`builder` [ITraconBuilder](/api/tracon.itraconbuilder/)

The Tracon chain.

`configure` [Action](https://learn.microsoft.com/dotnet/api/system.action\-1)<[OpenAISpeechOptions](/api/tracon.openaispeechoptions/)\>

The speech settings. At least one model is required.

#### Returns

 [ITraconBuilder](/api/tracon.itraconbuilder/)

The continuation of the chain.

#### Remarks

Call [OpenAIProviderExtensions.UseOpenAI](/api/tracon.openaiproviderextensions/)
first. This call shares the authenticated OpenAI client that `UseOpenAI`
registers and does not add a package or a second connection pool.

The providers are named speech providers: every call passes the tenant's egress policy
against the provider name `openai`, the name the chat provider uses, so one rule
covers chat, images and speech. A tenant that has its own OpenAI key is refused for
speech: the client was built with the setup key and cannot use another.

Billing is an estimate. The speech endpoint reports no billed characters, so Tracon records
the length of the text and labels it as estimated. A transcription has no duration, so it
has no cost: the client reads no duration from the answer.

```csharp
builder.AddTracon()
       .UseOpenAI(builder.Configuration["OpenAI:ApiKey"]!)
       .UseOpenAISpeech(options =>
       {
           options.SynthesisModel = "gpt-4o-mini-tts";
           options.TranscriptionModel = "gpt-4o-mini-transcribe";
       });
```

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

`builder` or `configure` is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

 [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)

`configure` sets neither model, or sets a name that is not a valid speech provider name,
or a character limit that is not greater than zero.
