Table of Contents

Class SpeechClient

Namespace
Mabs.AudioCpp
Assembly
AudioCpp.dll

Speech synthesis against POST /v1/audio/speech and /v1/audio/speech/live.

public sealed class SpeechClient
Inheritance
SpeechClient
Inherited Members

Methods

SpeakLiveAsync(LiveSpeechRequest, Stream, Func<SpeechStreamEvent, Task>, CancellationToken)

public Task SpeakLiveAsync(LiveSpeechRequest request, Stream pcmInput, Func<SpeechStreamEvent, Task> onEvent, CancellationToken cancellationToken = default)

Parameters

request LiveSpeechRequest

The live request.

pcmInput Stream

The PCM stream to upload; EOF marks end-of-speech.

onEvent Func<SpeechStreamEvent, Task>

Callback invoked for each event; iteration stops if it throws.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

Completes when the stream terminates or the callback stops consuming events.

Exceptions

AudioCppException

The response failed or an SSE error event arrives.

SpeakLiveAsync(LiveSpeechRequest, Stream, CancellationToken)

Live speech-to-speech: the request body is raw PCM pulled from pcmInput as it produces data (chunked transfer), and the response streams events on the same connection. Consuming events before pcmInput ends requires full-duplex HTTP; on platforms without it (browser/WASM) a PlatformNotSupportedException is thrown. The request ends — and the model treats it as end-of-speech — when pcmInput reaches EOF; closing the connection without that is a server error, by contract.

public IAsyncEnumerable<SpeechStreamEvent> SpeakLiveAsync(LiveSpeechRequest request, Stream pcmInput, CancellationToken cancellationToken = default)

Parameters

request LiveSpeechRequest

The live request; all fields travel as query parameters.

pcmInput Stream

The PCM stream to upload; EOF marks end-of-speech.

cancellationToken CancellationToken

Cancellation token observed while enumerating.

Returns

IAsyncEnumerable<SpeechStreamEvent>

The event sequence; iteration ends at [DONE] or connection close.

Exceptions

AudioCppException

The response failed or an SSE error event arrives.

StreamAsync(SpeechStreamRequest, Func<SpeechStreamEvent, Task>, CancellationToken)

Callback streaming variant.

public Task StreamAsync(SpeechStreamRequest request, Func<SpeechStreamEvent, Task> onEvent, CancellationToken cancellationToken = default)

Parameters

request SpeechStreamRequest

The stream request; stream_format must be sse.

onEvent Func<SpeechStreamEvent, Task>

Callback invoked for each event; iteration stops if it throws.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

Completes when the stream terminates or the callback stops consuming events.

Exceptions

AudioCppException

The response failed or an SSE error event arrives.

StreamAsync(SpeechStreamRequest, CancellationToken)

Stream speech as SSE events (requires a model configured with mode: "streaming"). Ends after speech.audio.done and [DONE]; throws AudioCppException on an SSE error event.

public IAsyncEnumerable<SpeechStreamEvent> StreamAsync(SpeechStreamRequest request, CancellationToken cancellationToken = default)

Parameters

request SpeechStreamRequest

The stream request; stream_format must be sse.

cancellationToken CancellationToken

Cancellation token observed while enumerating.

Returns

IAsyncEnumerable<SpeechStreamEvent>

The event sequence; iteration ends at [DONE] or connection close.

Exceptions

AudioCppException

The response failed or an SSE error event arrives.

StreamPcmAsync(SpeechStreamRequest, CancellationToken)

Raw PCM streaming: stream_format=audio + response_format=pcm returns chunked octet-stream bytes. The caller owns the returned stream; reading it yields PCM16 bytes as the server produces them.

public Task<Stream> StreamPcmAsync(SpeechStreamRequest request, CancellationToken cancellationToken = default)

Parameters

request SpeechStreamRequest

The stream request; stream_format is forced to audio.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<Stream>

The open response content stream.

Exceptions

AudioCppException

The response failed.

SynthesizeAsync(SpeechRequest, CancellationToken)

Synthesize speech. Returns the raw audio bytes (WAV by default) with the X-AudioCPP-* timing headers parsed into Timing.

public Task<SpeechResult> SynthesizeAsync(SpeechRequest request, CancellationToken cancellationToken = default)

Parameters

request SpeechRequest

The speech request (validated before sending).

cancellationToken CancellationToken

Cancellation token.

Returns

Task<SpeechResult>

The audio bytes, content type, and timing.

Exceptions

AudioCppException

The request failed.

SynthesizeJsonAsync(SpeechRequest, CancellationToken)

Synthesize with response_format=json and parse the JSON envelope (audio Base64 WAV, format, timing).

public Task<SpeechJsonResult> SynthesizeJsonAsync(SpeechRequest request, CancellationToken cancellationToken = default)

Parameters

request SpeechRequest

The speech request; ResponseFormat is forced to json.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<SpeechJsonResult>

The parsed JSON envelope.

Exceptions

AudioCppException

The request failed.