/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { llmSpeechDeleteTranscriptionHistory } from "../funcs/llmSpeechDeleteTranscriptionHistory.js"; import { llmSpeechDeleteTtsHistory } from "../funcs/llmSpeechDeleteTtsHistory.js"; import { llmSpeechGetTranscriptionHistory } from "../funcs/llmSpeechGetTranscriptionHistory.js"; import { llmSpeechGetTranscriptionHistoryContent } from "../funcs/llmSpeechGetTranscriptionHistoryContent.js"; import { llmSpeechGetTtsHistory } from "../funcs/llmSpeechGetTtsHistory.js"; import { GetTtsHistoryContentAcceptEnum, llmSpeechGetTtsHistoryContent, } from "../funcs/llmSpeechGetTtsHistoryContent.js"; import { llmSpeechListTranscriptionHistory } from "../funcs/llmSpeechListTranscriptionHistory.js"; import { llmSpeechListTtsHistory } from "../funcs/llmSpeechListTtsHistory.js"; import { llmSpeechLivekitToken } from "../funcs/llmSpeechLivekitToken.js"; import { llmSpeechSpeak } from "../funcs/llmSpeechSpeak.js"; import { llmSpeechSpeakStreaming, SpeakStreamingAcceptEnum, } from "../funcs/llmSpeechSpeakStreaming.js"; import { llmSpeechTranscribe } from "../funcs/llmSpeechTranscribe.js"; import { ClientSDK, RequestOptions } from "../lib/sdks.js"; import * as components from "../models/components/index.js"; import * as operations from "../models/operations/index.js"; import { unwrapAsync } from "../types/fp.js"; export { SpeakStreamingAcceptEnum } from "../funcs/llmSpeechSpeakStreaming.js"; export { GetTtsHistoryContentAcceptEnum } from "../funcs/llmSpeechGetTtsHistoryContent.js"; export class Speech extends ClientSDK { /** * Speech to text transcription * * @remarks * Convert audio to text using advanced speech recognition. * * **Complete File Upload (Standard)** * Use `Content-Type: multipart/form-data` to upload the complete audio file in one request. Maximum file size: 25MB. * * Example: * ```bash * curl -X POST "http://localhost:3000/api/v1/llm/speech/transcriptions?language=en" \ * -F "file=@audio.flac" * ``` * * **Chunked Upload (Streaming)** * Use `Transfer-Encoding: chunked` header to stream audio data in chunks as it's being recorded. No need to know total file size upfront. Server buffers chunks until complete before processing. Maximum total size: 25MB. * * Example: * ```bash * curl -X POST "http://localhost:3000/api/v1/llm/speech/transcriptions?language=en" \ * -H "Transfer-Encoding: chunked" \ * -H "Content-Type: multipart/form-data" \ * --data-binary @audio.flac * ``` * * **Supported Formats:** FLAC, MP3, MP4, MPEG, MPGA, M4A, OGG, WAV, WebM * * **Query Parameters:** * - `model` (optional): Transcription model identifier. Defaults to 'auto'. * - `language` (optional): ISO-639-1 or BCP-47 language code (e.g., "en", "en-US"). Auto-detects if not specified. * - `prompt` (optional): Legacy prompt parameter retained for backward compatibility. * - `temperature` (optional): Legacy temperature parameter retained for backward compatibility. * - `include_speaker_data` (optional): When `true`, include speaker diarization data and require WAV/PCM input. Otherwise transcription uses the standard compatibility path. * * **Response:** Returns transcribed text in JSON format. */ async transcribe( request: operations.TranscribeRequest, options?: RequestOptions, ): Promise { return unwrapAsync(llmSpeechTranscribe( this, request, options, )); } /** * Text to speech * * @remarks * Convert text to speech with automatic language detection. * * **Request Body:** * - `text`: Input text to convert to speech - required * - `language`: Language code (default: "auto") - "auto" for automatic detection, or ISO 639-1 codes: en, zh, hi, es, ar, bn, pt, ru, ja, pa, de, ko, fr, tr, it, th, pl, nl, id, vi, ur * - `model`: TTS model identifier (default: "auto") - "auto" selects the default provider; a registry-resolvable id dispatches to the matching provider * * **Response:** Returns audio file in WAV format with X-Language-Code header. When `store` is `true`, the generation is persisted before the response returns and the new history record id is included in the X-Tts-Id header. */ async speak( request: operations.TextToSpeechRequest, options?: RequestOptions, ): Promise { return unwrapAsync(llmSpeechSpeak( this, request, options, )); } /** * Streaming text to speech * * @remarks * Convert text to speech with real-time streaming audio delivery. * * **Key Features:** * - Low-latency audio streaming - playback can start immediately as chunks arrive * - Automatic language detection * - Multiple format support: MP3 or PCM/WAV * - High-quality audio: 24kHz sample rate, 16-bit mono * * **Request Body:** * - `text`: Input text to convert to speech - required * - `language`: Language code (default: "auto") - "auto" for automatic detection, or ISO 639-1 codes: en, zh, hi, es, ar, bn, pt, ru, ja, pa, de, ko, fr, tr, it, th, pl, nl, id, vi, ur * - `format`: Audio format (default: "mp3") - "mp3" for compressed MPEG audio (96 kbps) or "pcm" for uncompressed WAV * - `model`: TTS model identifier (default: "auto") - "auto" selects the default provider; a registry-resolvable id dispatches to the matching provider (note: not all providers support `format: "mp3"`) * * **Response:** * - Streams audio chunks in real-time * - Returns `X-Language-Code` header with detected/used language * - Content-Type: `audio/mpeg` (MP3) or `audio/wav` (PCM) * - When `store` is `true`, returns the `X-Tts-Id` header with the id the history record will be stored under; persistence is best-effort and completes shortly after the stream ends * * **Use Cases:** * - Real-time applications requiring immediate audio playback * - Interactive voice responses * - Low-latency text-to-speech scenarios */ async speakStreaming( request: operations.TextToSpeechStreamingRequest, options?: RequestOptions & { acceptHeaderOverride?: SpeakStreamingAcceptEnum; }, ): Promise { return unwrapAsync(llmSpeechSpeakStreaming( this, request, options, )); } /** * Generate LiveKit room token * * @remarks * Generates a LiveKit access token for joining a real-time voice room. The token includes encrypted credentials and model configuration for the voice agent. */ async livekitToken( request: operations.LivekitTokenRequest, options?: RequestOptions, ): Promise { return unwrapAsync(llmSpeechLivekitToken( this, request, options, )); } /** * List text-to-speech history * * @remarks * List stored text-to-speech generations for the authenticated user, newest first by default. */ async listTtsHistory( request: operations.ListTextToSpeechHistoryRequest, options?: RequestOptions, ): Promise { return unwrapAsync(llmSpeechListTtsHistory( this, request, options, )); } /** * Retrieve text-to-speech history item * * @remarks * Returns metadata for a stored text-to-speech generation. */ async getTtsHistory( request: operations.GetTextToSpeechHistoryRequest, options?: RequestOptions, ): Promise { return unwrapAsync(llmSpeechGetTtsHistory( this, request, options, )); } /** * Delete text-to-speech history item * * @remarks * Deletes a stored text-to-speech generation. The audio blob is content-addressed and may be shared, so it is left in storage. */ async deleteTtsHistory( request: operations.DeleteTextToSpeechHistoryRequest, options?: RequestOptions, ): Promise { return unwrapAsync(llmSpeechDeleteTtsHistory( this, request, options, )); } /** * Retrieve text-to-speech audio * * @remarks * Returns the stored audio for a text-to-speech generation as a binary response. */ async getTtsHistoryContent( request: operations.GetTextToSpeechHistoryContentRequest, options?: RequestOptions & { acceptHeaderOverride?: GetTtsHistoryContentAcceptEnum; }, ): Promise { return unwrapAsync(llmSpeechGetTtsHistoryContent( this, request, options, )); } /** * List speech-to-text history * * @remarks * List stored transcriptions for the authenticated user, newest first by default. */ async listTranscriptionHistory( request: operations.ListSpeechToTextHistoryRequest, options?: RequestOptions, ): Promise { return unwrapAsync(llmSpeechListTranscriptionHistory( this, request, options, )); } /** * Retrieve speech-to-text history item * * @remarks * Returns metadata for a stored transcription. */ async getTranscriptionHistory( request: operations.GetSpeechToTextHistoryRequest, options?: RequestOptions, ): Promise { return unwrapAsync(llmSpeechGetTranscriptionHistory( this, request, options, )); } /** * Delete speech-to-text history item * * @remarks * Deletes a stored transcription. The audio blob is content-addressed and may be shared, so it is left in storage. */ async deleteTranscriptionHistory( request: operations.DeleteSpeechToTextHistoryRequest, options?: RequestOptions, ): Promise { return unwrapAsync(llmSpeechDeleteTranscriptionHistory( this, request, options, )); } /** * Retrieve speech-to-text audio * * @remarks * Returns the stored input audio for a transcription as a binary response. */ async getTranscriptionHistoryContent( request: operations.GetSpeechToTextHistoryContentRequest, options?: RequestOptions, ): Promise> { return unwrapAsync(llmSpeechGetTranscriptionHistoryContent( this, request, options, )); } }