### Install dependencies Source: https://github.com/speechify-ai/sdk-typescript/blob/main/CONTRIBUTING.md Install the project dependencies using pnpm. ```bash pnpm install ``` -------------------------------- ### Install Speechify SDK via npm Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Use this command to install the Speechify TypeScript library into your project. ```sh npm i -s @speechify/api ``` -------------------------------- ### client.voices.consentChallenges.create Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Starts the consent check for a voice clone, returning a phrase for the speaker to read and a unique challenge ID. ```APIDOC ## client.voices.consentChallenges.create ### Description Start the consent check for a voice clone. Returns a phrase for the speaker to read aloud and an id that identifies this challenge. ### Parameters - **request** (Speechify.voices.CreateConsentChallengeRequest) - Required - The request object containing details like full_name and Idempotency-Key. - **requestOptions** (ConsentChallengesClient.RequestOptions) - Optional - Configuration options for the request. ### Usage Example ```typescript await client.voices.consentChallenges.create({ "Idempotency-Key": "a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d", full_name: "Jane Doe" }); ``` ``` -------------------------------- ### Build the project Source: https://github.com/speechify-ai/sdk-typescript/blob/main/CONTRIBUTING.md Build the project using the configured build script. ```bash pnpm build ``` -------------------------------- ### Run the test suite Source: https://github.com/speechify-ai/sdk-typescript/blob/main/CONTRIBUTING.md Execute the full test suite for the project. ```bash pnpm test ``` -------------------------------- ### Upload files using SpeechifyClient Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Demonstrates how to initialize the client and upload files using fs.createReadStream for sample and consent recording parameters. ```typescript import { createReadStream } from "fs"; import * as fs from "fs"; import { SpeechifyClient } from "@speechify/api"; const client = new SpeechifyClient({ token: "YOUR_TOKEN", version: "2026-09-13" }); await client.voices.create({ sample: fs.createReadStream("/path/to/your/file"), consent_recording: fs.createReadStream("/path/to/your/file"), "Idempotency-Key": "a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d", name: "name", gender: "male", consent_challenge_id: "consent_challenge_id" }); ``` -------------------------------- ### client.fetch(path, init, options) Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md The fetch method allows making custom HTTP requests while leveraging the SDK's built-in features like authentication, retries, and logging. ```APIDOC ## client.fetch(path, init, options) ### Description Executes a custom HTTP request using the SDK's internal configuration, including authentication, retries, and logging. This is useful for accessing API endpoints not explicitly covered by the SDK methods. ### Parameters - **path** (string) - Required - The API endpoint path to request. - **init** (RequestInit) - Required - Standard fetch request initialization object (e.g., method, headers). - **options** (Object) - Optional - SDK-specific configuration: - **timeoutInSeconds** (number) - Request timeout duration. - **maxRetries** (number) - Number of retry attempts. - **headers** (Object) - Custom headers to include in the request. ### Request Example ```typescript const response = await client.fetch("/v1/custom/endpoint", { method: "GET", }, { timeoutInSeconds: 30, maxRetries: 3, headers: { "X-Custom-Header": "custom-value", }, }); ``` ``` -------------------------------- ### Download a voice sample with client.voices.downloadSample Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Downloads a sample for a personal cloned voice. ```typescript await client.voices.downloadSample({ voice_id: "voice_id" }); ``` -------------------------------- ### Instantiate and use the SpeechifyClient Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Initialize the client with an API token and version, then perform a text-to-speech request. ```typescript import { SpeechifyClient } from "@speechify/api"; const client = new SpeechifyClient({ token: "YOUR_TOKEN", version: "2026-09-13" }); await client.audio.speech({ audio_format: "mp3", input: "Hello! This is the Speechify text-to-speech API.", model: "simba-3.2", voice_id: "geffen_32" }); ``` -------------------------------- ### client.voices.downloadSample Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Download a sample audio file for a personal cloned voice. ```APIDOC ## client.voices.downloadSample({ ...params }) ### Description Download a personal (cloned) voice sample. ### Parameters - **request** (Speechify.DownloadSampleVoicesRequest) - Required - **requestOptions** (VoicesClient.RequestOptions) - Optional ### Usage ```typescript await client.voices.downloadSample({ voice_id: "voice_id" }); ``` ``` -------------------------------- ### Audit version strings with grep Source: https://github.com/speechify-ai/sdk-typescript/blob/main/AGENTS.md Use these grep commands to quickly verify the version strings across the project's configuration and source files before a release. ```bash grep -nE '"version"' package.json .release-please-manifest.json grep -n 'sdkVersion' .fern/metadata.json # stamped at publish — expected to disagree with the last release on main grep -n 'SDK_VERSION' src/version.ts grep -nE 'X-Fern-SDK-Version|User-Agent' src/BaseClient.ts ``` -------------------------------- ### client.voices.create() Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Creates a cloned voice for the workspace using an audio sample and a verified consent recording. ```APIDOC ## client.voices.create() ### Description Create a cloned voice for the workspace from a 10-30 second audio sample. Requires a consent challenge process where the speaker reads a phrase provided by the API. ### Parameters - **sample** (ReadStream) - Required - Audio sample of the voice to clone. - **consent_recording** (ReadStream) - Required - Audio recording of the speaker reading the consent phrase. - **consent_challenge_id** (string) - Required - The ID of the consent challenge. - **name** (string) - Required - Name for the new voice. - **gender** (string) - Optional - Gender of the voice. - **Idempotency-Key** (string) - Optional - Key to ensure request idempotency. ``` -------------------------------- ### client.models.list() Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Lists the text-to-speech models available for synthesis, including information on default models and supported routes. ```APIDOC ## client.models.list() ### Description List the text-to-speech models available for synthesis. The response includes the default model, supported routes, and compatible voices. Multi-speaker models are returned in a separate array for dialogue synthesis. ### Parameters - **requestOptions** (ModelsClient.RequestOptions) - Optional - Configuration options for the request. ``` -------------------------------- ### Download binary response in Browser using Blob Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Creates an object URL and triggers a download via an anchor element. ```ts const response = await client.audio.stream(...); const blob = await response.blob(); const url = URL.createObjectURL(blob); // trigger download const a = document.createElement('a'); a.href = url; a.download = 'filename'; a.click(); URL.revokeObjectURL(url); ``` -------------------------------- ### Configure file metadata for uploads Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Shows how to define metadata using Uploadable.WithMetadata, including optional filename, contentType, and contentLength. ```typescript const file: Uploadable.WithMetadata = { data: createReadStream("path/to/file"), filename: "my-file", // optional contentType: "audio/mpeg", // optional contentLength: 1949, // optional }; ``` -------------------------------- ### Stream audio with timestamps using client.audio.streamWithTimestamps Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Demonstrates how to stream audio, process Base64 chunks, handle speech marks, and manage stream completion or errors. Note that the SDK does not automatically decode Base64 audio or raise errors for events occurring after the stream has opened. ```typescript const response = await client.audio.streamWithTimestamps({ body: { input: "Streaming long-form audio with the Speechify API.", model: "simba-3.2", voice_id: "geffen_32" } }); const audioChunks: Buffer[] = []; for await (const item of response) { switch (item.type) { case "speech.chunk": // `audio` is Base64 and the SDK does not decode it for you. It is // absent on a marks-only chunk, which the last chunk often is. if (item.audio != null) { audioChunks.push(Buffer.from(item.audio, "base64")); } // Mark times are absolute ms from the start of the synthesis, so // they apply to the concatenated audio, not to this chunk. for (const mark of item.speech_marks ?? []) { console.log(mark.start_time, mark.value); } break; case "speech.error": // A failure after the stream has opened arrives as an event, NOT as // a thrown error: the 200 status is already committed. The SDK does // not raise it for you, so handle it explicitly — otherwise the loop // ends normally and you treat truncated audio as a success. throw new Error(`${item.error.code}: ${item.error.message}`); case "speech.done": // Terminal event. There is no `[DONE]` sentinel. console.log("billable characters:", item.billable_characters_count); console.log("audio duration (ms):", item.audio_duration_ms); break; default: // Ignore unrecognized event types so new ones cannot break you. break; } } const audio = Buffer.concat(audioChunks); ``` -------------------------------- ### client.voices.create Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Uploads a voice sample and associated consent recordings using the SpeechifyClient. ```APIDOC ## client.voices.create ### Description Uploads voice samples and consent recordings to the Speechify API. ### Parameters - **sample** (Stream/Buffer) - Required - The voice sample file. - **consent_recording** (Stream/Buffer) - Required - The consent recording file. - **Idempotency-Key** (string) - Optional - A unique key to ensure request idempotency. - **name** (string) - Optional - The name of the voice. - **gender** (string) - Optional - The gender of the voice. - **consent_challenge_id** (string) - Optional - The ID associated with the consent challenge. ``` -------------------------------- ### Save binary response to file in Deno using Bytes Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Writes the bytes directly to a file. ```ts const response = await client.audio.stream(...); const bytes = await response.bytes(); await Deno.writeFile('path/to/file', bytes); ``` -------------------------------- ### Implement Custom Logger with Pino Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Create a custom logger by implementing the logging.ILogger interface, shown here using the pino library. ```ts import pino from 'pino'; const pinoLogger = pino({...}); const logger: logging.ILogger = { debug: (msg, ...args) => pinoLogger.debug(args, msg), info: (msg, ...args) => pinoLogger.info(args, msg), warn: (msg, ...args) => pinoLogger.warn(args, msg), error: (msg, ...args) => pinoLogger.error(args, msg), }; ``` -------------------------------- ### Check code style Source: https://github.com/speechify-ai/sdk-typescript/blob/main/CONTRIBUTING.md Run linting and formatting checks to ensure code style compliance. ```bash pnpm run lint pnpm run format:check ``` -------------------------------- ### Create a consent challenge Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Initiates a consent check for a voice clone, returning a phrase and an ID. This should be called only when the speaker is ready to record, as challenges are single-use and time-limited. ```typescript await client.voices.consentChallenges.create({ "Idempotency-Key": "a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d", full_name: "Jane Doe" }); ``` -------------------------------- ### Import Subpackage Clients Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Import specific subpackage clients to enable tree-shaking and reduce bundle size. ```typescript import { AudioClient } from '@speechify/api/audio'; const client = new AudioClient({...}); ``` -------------------------------- ### Implement Custom Logger with Winston Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Create a custom logger by implementing the logging.ILogger interface, shown here using the winston library. ```ts import winston from 'winston'; const winstonLogger = winston.createLogger({...}); const logger: logging.ILogger = { debug: (msg, ...args) => winstonLogger.debug(msg, ...args), info: (msg, ...args) => winstonLogger.info(msg, ...args), warn: (msg, ...args) => winstonLogger.warn(msg, ...args), error: (msg, ...args) => winstonLogger.error(msg, ...args), }; ``` -------------------------------- ### Save binary response to file in Bun using Blob Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Uses Bun.write to handle the Blob. ```ts const response = await client.audio.stream(...); const blob = await response.blob(); await Bun.write('path/to/file', blob); ``` -------------------------------- ### Save binary response to file in Deno using Blob Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Converts Blob to ArrayBuffer and writes to a file. ```ts const response = await client.audio.stream(...); const blob = await response.blob(); const arrayBuffer = await blob.arrayBuffer(); await Deno.writeFile('path/to/file', new Uint8Array(arrayBuffer)); ``` -------------------------------- ### client.voices.list() Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Lists available voices, including the shared catalog and workspace-specific cloned voices, with support for pagination and filtering. ```APIDOC ## client.voices.list() ### Description Lists the voices available to the caller. Supports optional pagination using `limit` and `cursor`, and filtering by `type` and `locale`. ### Parameters - **request** (Speechify.ListVoicesRequest) - Optional - Filtering and pagination parameters. - **requestOptions** (VoicesClient.RequestOptions) - Optional - Configuration options for the request. ``` -------------------------------- ### Save binary response to file in Deno using ArrayBuffer Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Writes the ArrayBuffer to a file using Deno.writeFile. ```ts const response = await client.audio.stream(...); const arrayBuffer = await response.arrayBuffer(); await Deno.writeFile('path/to/file', new Uint8Array(arrayBuffer)); ``` -------------------------------- ### Import request and response types Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Access SDK request and response types via the Speechify namespace. ```typescript import { Speechify } from "@speechify/api"; const request: Speechify.GetSpeechRequest = { ... }; ``` -------------------------------- ### Run combined check and fix Source: https://github.com/speechify-ai/sdk-typescript/blob/main/CONTRIBUTING.md Execute the combined command to check and fix code style issues. ```bash pnpm run check:fix ``` -------------------------------- ### List available text-to-speech models Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Retrieves the full catalog of available text-to-speech models. Use the returned model IDs for synthesis requests. ```typescript await client.models.list(); ``` -------------------------------- ### Save binary response to file in Deno using ReadableStream Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Pipes the stream to a Deno file handle. ```ts const response = await client.audio.stream(...); const stream = response.stream(); const file = await Deno.open('path/to/file', { write: true, create: true }); await stream.pipeTo(file.writable); ``` -------------------------------- ### Upload files directly from a file path Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Demonstrates using Uploadable.FromPath to upload a file by specifying its local path. ```typescript const file : Uploadable.FromPath = { path: "path/to/file", filename: "my-file", // optional contentType: "audio/mpeg", // optional contentLength: 1949, // optional }; ``` -------------------------------- ### Save binary response to file in Bun using ArrayBuffer Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Uses Bun.write to handle the ArrayBuffer. ```ts const response = await client.audio.stream(...); const arrayBuffer = await response.arrayBuffer(); await Bun.write('path/to/file', arrayBuffer); ``` -------------------------------- ### Fix code style issues Source: https://github.com/speechify-ai/sdk-typescript/blob/main/CONTRIBUTING.md Automatically fix linting and formatting issues. ```bash pnpm run lint:fix pnpm run format:fix ``` -------------------------------- ### BinaryResponse.blob() Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Consumes the response body and returns it as a Blob. ```APIDOC ## BinaryResponse.blob() ### Description Consumes the response body and returns a promise that resolves to a Blob. ### Returns - **blob** (Blob) - The binary data as a Blob. ``` -------------------------------- ### Fetch a voice with client.voices.get Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Retrieves a single voice by its ID. Note that cloned voices from other workspaces will return a 404 error. ```typescript await client.voices.get({ voice_id: "voice_id" }); ``` -------------------------------- ### Save binary response to file in Bun using Bytes Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Uses Bun.write to handle the Uint8Array bytes. ```ts const response = await client.audio.stream(...); const bytes = await response.bytes(); await Bun.write('path/to/file', bytes); ``` -------------------------------- ### Configure SDK Logging Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Pass a logging object to the SpeechifyClient constructor to customize log levels, the logger implementation, and silence settings. ```typescript import { SpeechifyClient, logging } from "@speechify/api"; const client = new SpeechifyClient({ ... logging: { level: logging.LogLevel.Debug, // defaults to logging.LogLevel.Info logger: new logging.ConsoleLogger(), // defaults to ConsoleLogger silent: false, // defaults to true, set to false to enable logging } }); ``` -------------------------------- ### Download binary response as Bytes (UIntArray8) Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Converts the response to bytes and triggers a browser download. ```ts const response = await client.audio.stream(...); const bytes = await response.bytes(); const blob = new Blob([bytes]); const url = URL.createObjectURL(blob); // trigger download const a = document.createElement('a'); a.href = url; a.download = 'filename'; a.click(); URL.revokeObjectURL(url); ``` -------------------------------- ### Consume streaming audio with async iterators Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Uses a 'for await...of' loop to process audio chunks and events from the 'streamWithTimestamps' endpoint. Note that audio data is Base64 encoded and errors occurring after the stream opens must be handled explicitly within the loop. ```typescript import { SpeechifyClient } from "@speechify/api"; const client = new SpeechifyClient({ token: "YOUR_TOKEN", version: "2026-09-13" }); const response = await client.audio.streamWithTimestamps({ body: { input: "Streaming long-form audio with the Speechify API.", model: "simba-3.2", voice_id: "geffen_32" } }); const audioChunks: Buffer[] = []; for await (const item of response) { switch (item.type) { case "speech.chunk": // `audio` is Base64 and the SDK does not decode it for you. It is // absent on a marks-only chunk, which the last chunk often is. if (item.audio != null) { audioChunks.push(Buffer.from(item.audio, "base64")); } // Mark times are absolute ms from the start of the synthesis, so // they apply to the concatenated audio, not to this chunk. for (const mark of item.speech_marks ?? []) { console.log(mark.start_time, mark.value); } break; case "speech.error": // A failure after the stream has opened arrives as an event, NOT as // a thrown error: the 200 status is already committed. The SDK does // not raise it for you, so handle it explicitly — otherwise the loop // ends normally and you treat truncated audio as a success. throw new Error(`${item.error.code}: ${item.error.message}`); case "speech.done": // Terminal event. There is no `[DONE]` sentinel. console.log("billable characters:", item.billable_characters_count); console.log("audio duration (ms):", item.audio_duration_ms); break; default: // Ignore unrecognized event types so new ones cannot break you. break; } } const audio = Buffer.concat(audioChunks); ``` -------------------------------- ### client.audio.streamWithTimestamps Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Synthesize speech and stream it back together with word-level speech marks for synchronization. ```APIDOC ## client.audio.streamWithTimestamps ### Description Synthesize speech and stream it back together with word-level speech marks, for text highlighting, captions and audio-text synchronization. The response is a Server-Sent Events stream. ``` -------------------------------- ### Download binary response as ArrayBuffer Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Converts the response to an ArrayBuffer and triggers a browser download. ```ts const response = await client.audio.stream(...); const arrayBuffer = await response.arrayBuffer(); const blob = new Blob([arrayBuffer]); const url = URL.createObjectURL(blob); // trigger download const a = document.createElement('a'); a.href = url; a.download = 'filename'; a.click(); URL.revokeObjectURL(url); ``` -------------------------------- ### Save binary response to file in Bun using ReadableStream Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Uses Bun.write to handle the stream directly. ```ts const response = await client.audio.stream(...); const stream = response.stream(); await Bun.write('path/to/file', stream); ``` -------------------------------- ### Perform Custom HTTP Requests Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Use the client.fetch method to make custom API calls while maintaining SDK-level configurations like authentication and retries. ```typescript const response = await client.fetch("/v1/custom/endpoint", { method: "GET", }, { timeoutInSeconds: 30, maxRetries: 3, headers: { "X-Custom-Header": "custom-value", }, }); const data = await response.json(); ``` -------------------------------- ### BinaryResponse.stream() Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Returns a ReadableStream of the response body. This is the most efficient way to handle large binary data. ```APIDOC ## BinaryResponse.stream() ### Description Returns a ReadableStream representing the response body. Note that the response body can only be consumed once. ### Returns - **stream** (ReadableStream) - The stream of binary data. ``` -------------------------------- ### Download binary response as ReadableStream Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Reads a binary stream in chunks and triggers a browser download. ```ts const response = await client.audio.stream(...); const stream = response.stream(); const reader = stream.getReader(); const chunks = []; while (true) { const { done, value } = await reader.read(); if (done) break; chunks.push(value); } const blob = new Blob(chunks); const url = URL.createObjectURL(blob); // trigger download const a = document.createElement('a'); a.href = url; a.download = 'filename'; a.click(); URL.revokeObjectURL(url); ``` -------------------------------- ### client.audio.stream Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Synthesize speech and stream the audio back as it is generated for low-latency playback. ```APIDOC ## client.audio.stream ### Description Synthesize speech and stream the audio back as it is generated, for low-latency playback. The response is raw audio bytes. ### Parameters - **request** (Speechify.StreamAudioRequest) - Required - The request parameters for streaming audio. - **requestOptions** (AudioClient.RequestOptions) - Optional - Additional request configuration. ### Usage Example ```typescript await client.audio.stream({ body: { input: "input", voice_id: "voice_id" } }); ``` ``` -------------------------------- ### Create a cloned voice Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Creates a cloned voice using an audio sample and a verified consent recording. Requires a valid consent challenge ID. ```typescript await client.voices.create({ sample: fs.createReadStream("/path/to/your/file"), consent_recording: fs.createReadStream("/path/to/your/file"), "Idempotency-Key": "a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d", name: "name", gender: "male", consent_challenge_id: "consent_challenge_id" }); ``` -------------------------------- ### Configure Additional Request Headers Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Pass custom headers during client initialization or on individual request calls using the headers option. ```typescript import { SpeechifyClient } from "@speechify/api"; const client = new SpeechifyClient({ ... headers: { 'X-Custom-Header': 'custom value' } }); const response = await client.audio.speech(..., { headers: { 'X-Custom-Header': 'custom value' } }); ``` -------------------------------- ### Save binary response to file in Node.js using ReadableStream Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Uses pipeline to stream data efficiently to a file. ```ts import { createWriteStream } from 'fs'; import { Readable } from 'stream'; import { pipeline } from 'stream/promises'; const response = await client.audio.stream(...); const stream = response.stream(); const nodeStream = Readable.fromWeb(stream); const writeStream = createWriteStream('path/to/file'); await pipeline(nodeStream, writeStream); ``` -------------------------------- ### Save binary response to file in Node.js using ArrayBuffer Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Converts ArrayBuffer to a Buffer before writing to disk. ```ts import { writeFile } from 'fs/promises'; const response = await client.audio.stream(...); const arrayBuffer = await response.arrayBuffer(); await writeFile('path/to/file', Buffer.from(arrayBuffer)); ``` -------------------------------- ### BinaryResponse.bytes() Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Consumes the response body and returns it as a Uint8Array. ```APIDOC ## BinaryResponse.bytes() ### Description Consumes the response body and returns a promise that resolves to a Uint8Array. ### Returns - **bytes** (Uint8Array) - The binary data as a Uint8Array. ``` -------------------------------- ### Save binary response to file in Node.js using Blob Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Converts Blob to ArrayBuffer before writing to disk. ```ts import { writeFile } from 'fs/promises'; const response = await client.audio.stream(...); const blob = await response.blob(); const arrayBuffer = await blob.arrayBuffer(); await writeFile('output.bin', Buffer.from(arrayBuffer)); ``` -------------------------------- ### Stream audio with client.audio.stream Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Synthesizes and streams raw audio bytes for low-latency playback. The response is HTTP chunked. ```typescript await client.audio.stream({ body: { input: "input", voice_id: "voice_id" } }); ``` -------------------------------- ### BinaryResponse.arrayBuffer() Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Consumes the response body and returns it as an ArrayBuffer. ```APIDOC ## BinaryResponse.arrayBuffer() ### Description Consumes the response body and returns a promise that resolves to an ArrayBuffer. ### Returns - **arrayBuffer** (ArrayBuffer) - The binary data as an ArrayBuffer. ``` -------------------------------- ### Convert binary response to text using Blob Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Converts a Blob response into a text string. ```ts const response = await client.audio.stream(...); const blob = await response.blob(); const text = await blob.text(); ``` -------------------------------- ### Configure API environments Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Set the environment for API requests using the SpeechifyEnvironment enum. ```typescript import { SpeechifyClient, SpeechifyEnvironment } from "@speechify/api"; const client = new SpeechifyClient({ environment: SpeechifyEnvironment.Default, }); ``` -------------------------------- ### Save binary response to file in Node.js using Bytes Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Writes Uint8Array bytes directly to a file. ```ts import { writeFile } from 'fs/promises'; const response = await client.audio.stream(...); const bytes = await response.bytes(); await writeFile('path/to/file', bytes); ``` -------------------------------- ### client.audio.speech Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Generates audio from text. Supports advanced request options such as custom headers, query parameters, retries, timeouts, and abort signals. ```APIDOC ## client.audio.speech ### Description Generates audio content. This method supports advanced configuration options including custom headers, query parameters, retry logic, timeouts, and request cancellation. ### Request Options - **headers** (object) - Optional - Custom headers to include in the request. - **queryParams** (object) - Optional - Additional query string parameters. - **maxRetries** (number) - Optional - Override the default retry limit. - **timeoutInSeconds** (number) - Optional - Override the default 60s timeout. - **abortSignal** (AbortSignal) - Optional - Signal to abort the request. ### Request Example ```typescript const response = await client.audio.speech(..., { headers: { 'X-Custom-Header': 'value' }, queryParams: { 'customKey': 'value' }, maxRetries: 0, timeoutInSeconds: 30 }); ``` ``` -------------------------------- ### client.voices.get Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Fetch a single voice by ID, including shared catalogue voices or workspace-specific cloned voices. ```APIDOC ## client.voices.get({ ...params }) ### Description Fetch a single voice by id - a shared catalogue voice or one of the workspace's cloned voices. A cloned voice that belongs to another workspace returns 404, identical to an unknown id, so voice inventory is never enumerable across tenants. ### Parameters - **request** (Speechify.GetVoicesRequest) - Required - **requestOptions** (VoicesClient.RequestOptions) - Optional ### Usage ```typescript await client.voices.get({ voice_id: "voice_id" }); ``` ``` -------------------------------- ### client.audio.speech Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Synthesize speech audio from text or SSML. Returns the complete audio file plus billing and speech-mark metadata in a single JSON response. ```APIDOC ## client.audio.speech ### Description Synthesize speech audio from text or SSML. Returns the complete audio file plus billing and speech-mark metadata in a single JSON response. ### Parameters - **request** (Speechify.GetSpeechRequest) - Required - The request parameters for speech synthesis. - **requestOptions** (AudioClient.RequestOptions) - Optional - Additional request configuration. ### Usage Example ```typescript await client.audio.speech({ audio_format: "mp3", input: "Hello! This is the Speechify text-to-speech API.", model: "simba-3.2", voice_id: "geffen_32" }); ``` ``` -------------------------------- ### List and paginate voices Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Lists available voices with optional filtering by locale and model. Supports both async iteration and manual page-by-page navigation. ```typescript const pageableResponse = await client.voices.list({ locale: "en", model: "simba-3.2" }); for await (const item of pageableResponse) { console.log(item); } // Or you can manually iterate page-by-page let page = await client.voices.list({ locale: "en", model: "simba-3.2" }); while (page.hasNextPage()) { page = page.getNextPage(); } // You can also access the underlying response const response = page.response; ``` -------------------------------- ### Consume BinaryResponse data Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Demonstrates how to access the stream and check if the response body has been used. Note that only one consumption method can be used per response. ```typescript const response = await client.audio.stream(...); const stream: ReadableStream = response.stream(); // const arrayBuffer: ArrayBuffer = await response.arrayBuffer(); // const blob: Blob = response.blob(); // const bytes: Uint8Array = response.bytes(); // You can only use the response body once, so you must choose one of the above methods. // If you want to check if the response body has been used, you can use the following property. const bodyUsed = response.bodyUsed; ``` -------------------------------- ### client.audio.streamWithTimestamps Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Streams audio content with timestamps. The method returns an async iterable that yields chunks of audio data and speech marks. ```APIDOC ## client.audio.streamWithTimestamps ### Description Streams long-form audio from the Speechify API. The response is an async iterable that provides audio chunks and speech marks, requiring manual handling of events like speech.chunk, speech.error, and speech.done. ### Parameters - **request** (Speechify.StreamWithTimestampsAudioRequest) - Required - The request object containing input text, model, and voice_id. - **requestOptions** (AudioClient.RequestOptions) - Optional - Configuration options for the request. ### Request Example ```typescript const response = await client.audio.streamWithTimestamps({ body: { input: "Streaming long-form audio with the Speechify API.", model: "simba-3.2", voice_id: "geffen_32" } }); ``` ``` -------------------------------- ### Convert binary response to text using Bytes (UIntArray8) Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Converts a byte array response into a text string using TextDecoder. ```ts const response = await client.audio.stream(...); const bytes = await response.bytes(); const text = new TextDecoder().decode(bytes); ``` -------------------------------- ### client.voices.list Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Retrieves a list of voices. This method supports pagination via an async iterator or manual page navigation. ```APIDOC ## client.voices.list ### Description Retrieves a list of available voices. The response is paginated and can be iterated over using an async loop or manual page-by-page navigation. ### Parameters - **locale** (string) - Optional - The locale filter for voices. - **model** (string) - Optional - The model filter for voices. ### Request Example ```typescript const pageableResponse = await client.voices.list({ locale: "en", model: "simba-3.2" }); ``` ``` -------------------------------- ### client.voices.delete Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Delete a cloned voice from the workspace. Requires appropriate permissions. ```APIDOC ## client.voices.delete({ ...params }) ### Description Delete one of the workspace's cloned voices. Requires the `content.manage` permission (owner, admin, or member); a service-account key is authorized by its scopes instead. ### Parameters - **request** (Speechify.DeleteVoicesRequest) - Required - **requestOptions** (VoicesClient.RequestOptions) - Optional ### Usage ```typescript await client.voices.delete({ voice_id: "voice_id" }); ``` ``` -------------------------------- ### Add Query String Parameters Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Include extra query string parameters in a request using the queryParams option. ```typescript const response = await client.audio.speech(..., { queryParams: { 'customQueryParamKey': 'custom query param value' } }); ``` -------------------------------- ### Handle API exceptions Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Catch and inspect SpeechifyError instances when the API returns non-success status codes. ```typescript import { SpeechifyError } from "@speechify/api"; try { await client.audio.speech(...); } catch (err) { if (err instanceof SpeechifyError) { console.log(err.statusCode); console.log(err.message); console.log(err.body); console.log(err.rawResponse); } } ``` -------------------------------- ### Synthesize speech with client.audio.speech Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Synthesizes speech audio from text or SSML, returning a complete audio file with metadata in a single JSON response. Use this for standard synthesis tasks. ```typescript await client.audio.speech({ audio_format: "mp3", input: "Hello! This is the Speechify text-to-speech API.", model: "simba-3.2", voice_id: "geffen_32" }); ``` -------------------------------- ### Configure Request Timeout Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Override the default 60-second timeout by specifying the timeoutInSeconds option. ```typescript const response = await client.audio.speech(..., { timeoutInSeconds: 30 // override timeout to 30s }); ``` -------------------------------- ### Access Raw Response Data Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Use the withRawResponse method to retrieve both the data and the raw response object, including headers. ```typescript const { data, rawResponse } = await client.audio.speech(...).withRawResponse(); console.log(data); console.log(rawResponse.headers['X-My-Header']); ``` -------------------------------- ### Convert binary response to text using ArrayBuffer Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Converts an ArrayBuffer response into a text string using TextDecoder. ```ts const response = await client.audio.stream(...); const arrayBuffer = await response.arrayBuffer(); const text = new TextDecoder().decode(arrayBuffer); ``` -------------------------------- ### Convert binary response to text using ReadableStream Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Converts a ReadableStream response into a text string. ```ts const response = await client.audio.stream(...); const stream = response.stream(); const text = await new Response(stream).text(); ``` -------------------------------- ### Iterate Over Paginated List Endpoints Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Use the provided iterator to loop over paginated items, or manually iterate page-by-page using hasNextPage and getNextPage methods. ```typescript import { SpeechifyClient } from "@speechify/api"; const client = new SpeechifyClient({ token: "YOUR_TOKEN", version: "2026-09-13" }); const pageableResponse = await client.voices.list({ locale: "en", model: "simba-3.2" }); for await (const item of pageableResponse) { console.log(item); } // Or you can manually iterate page-by-page let page = await client.voices.list({ locale: "en", model: "simba-3.2" }); while (page.hasNextPage()) { page = page.getNextPage(); } // You can also access the underlying response const response = page.response; ``` -------------------------------- ### Delete a voice with client.voices.delete Source: https://github.com/speechify-ai/sdk-typescript/blob/main/reference.md Deletes a cloned voice from the workspace. Requires the content.manage permission or appropriate service-account scopes. ```typescript await client.voices.delete({ voice_id: "voice_id" }); ``` -------------------------------- ### Abort Requests Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Cancel an ongoing request by passing an AbortController signal and calling the abort method. ```typescript const controller = new AbortController(); const response = await client.audio.speech(..., { abortSignal: controller.signal }); controller.abort(); // aborts the request ``` -------------------------------- ### Override Retry Limit Source: https://github.com/speechify-ai/sdk-typescript/blob/main/README.md Configure the maximum number of retries for a specific request using the maxRetries option. ```typescript const response = await client.audio.speech(..., { maxRetries: 0 // override maxRetries at the request level }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.