@respeecher/respeecher-js
Version:
[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Frespeecher%2Frespeecher-js) [ • 4.74 kB
JavaScript
/**
* This file was auto-generated by Fern from our API Definition.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import * as environments from "../../../../environments.mjs";
import * as core from "../../../../core/index.mjs";
import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.mjs";
import urlJoin from "url-join";
import * as serializers from "../../../../serialization/index.mjs";
import * as errors from "../../../../errors/index.mjs";
export class Voices {
constructor(_options = {}) {
this._options = _options;
}
/**
* List of available voices with IDs and metadata.
*
* @param {Voices.RequestOptions} requestOptions - Request-specific configuration.
*
* @example
* await client.voices.list()
*/
list(requestOptions) {
return core.HttpResponsePromise.fromPromise(this.__list(requestOptions));
}
__list(requestOptions) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c;
const _response = yield core.fetcher({
url: urlJoin((_a = (yield core.Supplier.get(this._options.baseUrl))) !== null && _a !== void 0 ? _a : ((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.RespeecherEnvironment.PublicEnRt).base, "/voices"),
method: "GET",
headers: mergeHeaders((_c = this._options) === null || _c === void 0 ? void 0 : _c.headers, mergeOnlyDefinedHeaders(Object.assign({}, (yield this._getCustomAuthorizationHeaders()))), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
});
if (_response.ok) {
return {
data: serializers.voices.list.Response.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
rawResponse: _response.rawResponse,
};
}
if (_response.error.reason === "status-code") {
throw new errors.RespeecherError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
switch (_response.error.reason) {
case "non-json":
throw new errors.RespeecherError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
rawResponse: _response.rawResponse,
});
case "timeout":
throw new errors.RespeecherTimeoutError("Timeout exceeded when calling GET /voices.");
case "unknown":
throw new errors.RespeecherError({
message: _response.error.errorMessage,
rawResponse: _response.rawResponse,
});
}
});
}
_getCustomAuthorizationHeaders() {
return __awaiter(this, void 0, void 0, function* () {
var _a;
const apiKeyValue = (_a = (yield core.Supplier.get(this._options.apiKey))) !== null && _a !== void 0 ? _a : process === null || process === void 0 ? void 0 : process.env["RESPEECHER_API_KEY"];
return { "X-API-Key": apiKeyValue };
});
}
}