UNPKG

@aristech-org/tts-client

Version:

A Node.js client library for the Aristech Text-to-Speech API

84 lines (83 loc) 3.21 kB
import * as grpc from '@grpc/grpc-js'; import { DeepPartial, Voice } from './generated/TTSTypes.js'; import { PhonesetRequest, PhonesetResponse, SpeechRequest, SpeechResponse, TranscriptionRequest, TranscriptionResponse, VoiceListRequest } from './generated/TTSServices.js'; export * from './generated/TTSTypes.js'; export { PhonesetRequest, PhonesetResponse, SpeechRequest, SpeechResponse, SpeechServiceClient, TranscriptionRequest, TranscriptionResponse, VoiceListRequest } from './generated/TTSServices.js'; export type Stream = grpc.ClientReadableStream<SpeechResponse>; export interface ConnectionOptions { /** * The Aristech TTS-Server uri e.g. tts.example.com */ host?: string; /** * Whether to use SSL/TLS. Automatically enabled when rootCert is provided */ ssl?: boolean; /** * Allows providing a custom root certificate that might not exist * in the root certificate chain */ rootCert?: string; /** * Optionally instead of providing a root cert path via `rootCert` the root cert content can be provided directly */ rootCertContent?: string; /** * Further grpc client options */ grpcClientOptions?: grpc.ClientOptions; /** * Authentication options. * **Note:** Can only be used in combination with SSL/TLS. */ auth?: { token: string; secret: string; }; } export declare class TtsClient { private cOptions; constructor(options: ConnectionOptions); /** * Lists all available voices. */ listVoices(request?: DeepPartial<VoiceListRequest>): Promise<Array<Voice>>; /** * Creates a stream of audio data from the given text. * @param request The request object * @returns A tuple containing the stream and the voice used for the audio generation */ streamAudio(request: DeepPartial<SpeechRequest>): Promise<[Stream, Voice]>; /** * Creates an audio buffer from the given text. * @param request The request object * @returns The audio buffer */ synthesize(request: DeepPartial<SpeechRequest>): Promise<Buffer>; /** * This is an alias for the `synthesize` method. */ audioBuffer(request: DeepPartial<SpeechRequest>): Promise<Buffer>; /** * Retrieves the phoneset for the given voice. * @param request The request object * @returns The phoneset response */ getPhoneset(request: DeepPartial<PhonesetRequest>): Promise<PhonesetResponse>; /** * Retrieves the transcription for the given request. * @param request The request object * @returns The transcription response */ getTranscription(request: DeepPartial<TranscriptionRequest>): Promise<TranscriptionResponse>; private getClient; } /** * A helper function to create a WAV header for the given audio data. * @param dataLength The length of the audio data in bytes * @param sampleRate Sample rate in Hz * @param numChannels Number of channels * @param bitsPerSample Bits per sample * @returns The WAV header as a buffer */ export declare function createWaveHeader(dataLength: number, sampleRate: number, numChannels: number, bitsPerSample: number): Buffer;