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)
Callback variant of SpeakLiveAsync(LiveSpeechRequest, Stream, CancellationToken).
public Task SpeakLiveAsync(LiveSpeechRequest request, Stream pcmInput, Func<SpeechStreamEvent, Task> onEvent, CancellationToken cancellationToken = default)
Parameters
requestLiveSpeechRequestThe live request.
pcmInputStreamThe PCM stream to upload; EOF marks end-of-speech.
onEventFunc<SpeechStreamEvent, Task>Callback invoked for each event; iteration stops if it throws.
cancellationTokenCancellationTokenCancellation 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
requestLiveSpeechRequestThe live request; all fields travel as query parameters.
pcmInputStreamThe PCM stream to upload; EOF marks end-of-speech.
cancellationTokenCancellationTokenCancellation 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
requestSpeechStreamRequestThe stream request;
stream_formatmust besse.onEventFunc<SpeechStreamEvent, Task>Callback invoked for each event; iteration stops if it throws.
cancellationTokenCancellationTokenCancellation 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
requestSpeechStreamRequestThe stream request;
stream_formatmust besse.cancellationTokenCancellationTokenCancellation 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
requestSpeechStreamRequestThe stream request;
stream_formatis forced toaudio.cancellationTokenCancellationTokenCancellation token.
Returns
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
requestSpeechRequestThe speech request (validated before sending).
cancellationTokenCancellationTokenCancellation 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
requestSpeechRequestThe speech request; ResponseFormat is forced to
json.cancellationTokenCancellationTokenCancellation token.
Returns
- Task<SpeechJsonResult>
The parsed JSON envelope.
Exceptions
- AudioCppException
The request failed.