MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/ai_allyindian_com/node_modules/sarvamai/api/resources/speechToText/client/Client.js
"use strict";
/**
 * This file was auto-generated by Fern from our API Definition.
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
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());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SpeechToText = void 0;
const environments = __importStar(require("../../../../environments"));
const core = __importStar(require("../../../../core"));
const SarvamAI = __importStar(require("../../../index"));
const url_join_1 = __importDefault(require("url-join"));
const errors = __importStar(require("../../../../errors/index"));
class SpeechToText {
    constructor(_options = {}) {
        this._options = _options;
    }
    /**
     * ## Real-Time Speech to Text API
     *
     * This API transcribes speech to text in multiple Indian languages and English. Supports real-time transcription for interactive applications.
     *
     * ### Available Options:
     * - **Real-Time API** (Current Endpoint): For quick responses under 30 seconds with immediate results
     * - **Batch API**: For longer audio files, requires following a notebook script - [View Notebook](https://github.com/sarvamai/sarvam-ai-cookbook/tree/main/notebooks/stt/stt-batch-api)
     *   - Supports diarization (speaker identification)
     *
     * ### Note:
     * - Pricing differs for Real-Time and Batch APIs
     * - Diarization is only available in Batch API with separate pricing
     * - Please refer to [dashboard.sarvam.ai](https://dashboard.sarvam.ai) for detailed pricing information
     *
     * @param {File | fs.ReadStream | Blob} file
     * @param {SarvamAI.SpeechToTextTranscriptionRequest} request
     * @param {SpeechToText.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link SarvamAI.BadRequestError}
     * @throws {@link SarvamAI.ForbiddenError}
     * @throws {@link SarvamAI.UnprocessableEntityError}
     * @throws {@link SarvamAI.TooManyRequestsError}
     * @throws {@link SarvamAI.InternalServerError}
     * @throws {@link SarvamAI.ServiceUnavailableError}
     *
     * @example
     *     await client.speechToText.transcribe(fs.createReadStream("/path/to/your/file"), {})
     */
    transcribe(file, request, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b;
            const _request = yield core.newFormData();
            yield _request.appendFile("file", file);
            if (request.model != null) {
                _request.append("model", request.model);
            }
            if (request.language_code != null) {
                _request.append("language_code", request.language_code);
            }
            const _maybeEncodedRequest = yield _request.getRequest();
            const _response = yield core.fetcher({
                url: (0, url_join_1.default)((_b = (_a = (yield core.Supplier.get(this._options.baseUrl))) !== null && _a !== void 0 ? _a : (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.SarvamAIEnvironment.Production, "speech-to-text"),
                method: "POST",
                headers: Object.assign(Object.assign(Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "sarvamai", "X-Fern-SDK-Version": "0.1.5-a1", "User-Agent": "sarvamai/0.1.5-a1", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())), _maybeEncodedRequest.headers), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
                requestType: "file",
                duplex: _maybeEncodedRequest.duplex,
                body: _maybeEncodedRequest.body,
                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 _response.body;
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new SarvamAI.BadRequestError(_response.error.body);
                    case 403:
                        throw new SarvamAI.ForbiddenError(_response.error.body);
                    case 422:
                        throw new SarvamAI.UnprocessableEntityError(_response.error.body);
                    case 429:
                        throw new SarvamAI.TooManyRequestsError(_response.error.body);
                    case 500:
                        throw new SarvamAI.InternalServerError(_response.error.body);
                    case 503:
                        throw new SarvamAI.ServiceUnavailableError(_response.error.body);
                    default:
                        throw new errors.SarvamAIError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.SarvamAIError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                    });
                case "timeout":
                    throw new errors.SarvamAITimeoutError("Timeout exceeded when calling POST /speech-to-text.");
                case "unknown":
                    throw new errors.SarvamAIError({
                        message: _response.error.errorMessage,
                    });
            }
        });
    }
    /**
     * ## Real-Time Speech to Text Translation API
     *
     * This API automatically detects the input language, transcribes the speech, and translates the text to English.
     *
     * ### Available Options:
     * - **Real-Time API** (Current Endpoint): For quick responses under 30 seconds with immediate results
     * - **Batch API**: For longer audio files, requires following a notebook script - [View Notebook](https://github.com/sarvamai/sarvam-ai-cookbook/tree/main/notebooks/stt-translate/stt-translate-batch-api)
     *   - Supports diarization (speaker identification)
     *
     * ### Note:
     * - Pricing differs for Real-Time and Batch APIs
     * - Diarization is only available in Batch API with separate pricing
     * - Please refer to [dashboard.sarvam.ai](https://dashboard.sarvam.ai) for detailed pricing information
     *
     * @param {File | fs.ReadStream | Blob} file
     * @param {SarvamAI.SpeechToTextTranslationRequest} request
     * @param {SpeechToText.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link SarvamAI.BadRequestError}
     * @throws {@link SarvamAI.ForbiddenError}
     * @throws {@link SarvamAI.UnprocessableEntityError}
     * @throws {@link SarvamAI.TooManyRequestsError}
     * @throws {@link SarvamAI.InternalServerError}
     * @throws {@link SarvamAI.ServiceUnavailableError}
     *
     * @example
     *     await client.speechToText.translate(fs.createReadStream("/path/to/your/file"), {})
     */
    translate(file, request, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b;
            const _request = yield core.newFormData();
            yield _request.appendFile("file", file);
            if (request.prompt != null) {
                _request.append("prompt", request.prompt);
            }
            if (request.model != null) {
                _request.append("model", request.model);
            }
            const _maybeEncodedRequest = yield _request.getRequest();
            const _response = yield core.fetcher({
                url: (0, url_join_1.default)((_b = (_a = (yield core.Supplier.get(this._options.baseUrl))) !== null && _a !== void 0 ? _a : (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.SarvamAIEnvironment.Production, "speech-to-text-translate"),
                method: "POST",
                headers: Object.assign(Object.assign(Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "sarvamai", "X-Fern-SDK-Version": "0.1.5-a1", "User-Agent": "sarvamai/0.1.5-a1", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())), _maybeEncodedRequest.headers), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
                requestType: "file",
                duplex: _maybeEncodedRequest.duplex,
                body: _maybeEncodedRequest.body,
                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 _response.body;
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new SarvamAI.BadRequestError(_response.error.body);
                    case 403:
                        throw new SarvamAI.ForbiddenError(_response.error.body);
                    case 422:
                        throw new SarvamAI.UnprocessableEntityError(_response.error.body);
                    case 429:
                        throw new SarvamAI.TooManyRequestsError(_response.error.body);
                    case 500:
                        throw new SarvamAI.InternalServerError(_response.error.body);
                    case 503:
                        throw new SarvamAI.ServiceUnavailableError(_response.error.body);
                    default:
                        throw new errors.SarvamAIError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.SarvamAIError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                    });
                case "timeout":
                    throw new errors.SarvamAITimeoutError("Timeout exceeded when calling POST /speech-to-text-translate.");
                case "unknown":
                    throw new errors.SarvamAIError({
                        message: _response.error.errorMessage,
                    });
            }
        });
    }
    _getCustomAuthorizationHeaders() {
        return __awaiter(this, void 0, void 0, function* () {
            var _a;
            const apiSubscriptionKeyValue = (_a = (yield core.Supplier.get(this._options.apiSubscriptionKey))) !== null && _a !== void 0 ? _a : process === null || process === void 0 ? void 0 : process.env["SARVAM_API_KEY"];
            return { "api-subscription-key": apiSubscriptionKeyValue };
        });
    }
}
exports.SpeechToText = SpeechToText;