"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AudioRequest = exports.AudioStreamingRequest = exports.AudioChunk = exports.AudioMetadata = exports.ContainerAudio = exports.RawAudio = exports.containerAudio_ContainerAudioTypeToJSON = exports.containerAudio_ContainerAudioTypeFromJSON = exports.ContainerAudio_ContainerAudioType = exports.rawAudio_AudioEncodingToJSON = exports.rawAudio_AudioEncodingFromJSON = exports.RawAudio_AudioEncoding = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const minimal_1 = __importDefault(require("protobufjs/minimal"));
exports.protobufPackage = 'yandex.cloud.speechsense.v1';
var RawAudio_AudioEncoding;
(function (RawAudio_AudioEncoding) {
    RawAudio_AudioEncoding[RawAudio_AudioEncoding["AUDIO_ENCODING_UNSPECIFIED"] = 0] = "AUDIO_ENCODING_UNSPECIFIED";
    /** AUDIO_ENCODING_LINEAR16_PCM - Audio bit depth 16-bit signed little-endian (Linear PCM). */
    RawAudio_AudioEncoding[RawAudio_AudioEncoding["AUDIO_ENCODING_LINEAR16_PCM"] = 1] = "AUDIO_ENCODING_LINEAR16_PCM";
    RawAudio_AudioEncoding[RawAudio_AudioEncoding["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
})(RawAudio_AudioEncoding = exports.RawAudio_AudioEncoding || (exports.RawAudio_AudioEncoding = {}));
function rawAudio_AudioEncodingFromJSON(object) {
    switch (object) {
        case 0:
        case 'AUDIO_ENCODING_UNSPECIFIED':
            return RawAudio_AudioEncoding.AUDIO_ENCODING_UNSPECIFIED;
        case 1:
        case 'AUDIO_ENCODING_LINEAR16_PCM':
            return RawAudio_AudioEncoding.AUDIO_ENCODING_LINEAR16_PCM;
        case -1:
        case 'UNRECOGNIZED':
        default:
            return RawAudio_AudioEncoding.UNRECOGNIZED;
    }
}
exports.rawAudio_AudioEncodingFromJSON = rawAudio_AudioEncodingFromJSON;
function rawAudio_AudioEncodingToJSON(object) {
    switch (object) {
        case RawAudio_AudioEncoding.AUDIO_ENCODING_UNSPECIFIED:
            return 'AUDIO_ENCODING_UNSPECIFIED';
        case RawAudio_AudioEncoding.AUDIO_ENCODING_LINEAR16_PCM:
            return 'AUDIO_ENCODING_LINEAR16_PCM';
        default:
            return 'UNKNOWN';
    }
}
exports.rawAudio_AudioEncodingToJSON = rawAudio_AudioEncodingToJSON;
var ContainerAudio_ContainerAudioType;
(function (ContainerAudio_ContainerAudioType) {
    ContainerAudio_ContainerAudioType[ContainerAudio_ContainerAudioType["CONTAINER_AUDIO_TYPE_UNSPECIFIED"] = 0] = "CONTAINER_AUDIO_TYPE_UNSPECIFIED";
    /** CONTAINER_AUDIO_TYPE_WAV - Audio bit depth 16-bit signed little-endian (Linear PCM). */
    ContainerAudio_ContainerAudioType[ContainerAudio_ContainerAudioType["CONTAINER_AUDIO_TYPE_WAV"] = 1] = "CONTAINER_AUDIO_TYPE_WAV";
    /** CONTAINER_AUDIO_TYPE_OGG_OPUS - Data is encoded using the OPUS audio codec and compressed using the OGG container format. */
    ContainerAudio_ContainerAudioType[ContainerAudio_ContainerAudioType["CONTAINER_AUDIO_TYPE_OGG_OPUS"] = 2] = "CONTAINER_AUDIO_TYPE_OGG_OPUS";
    /** CONTAINER_AUDIO_TYPE_MP3 - Data is encoded using MPEG-1/2 Layer III and compressed using the MP3 container format. */
    ContainerAudio_ContainerAudioType[ContainerAudio_ContainerAudioType["CONTAINER_AUDIO_TYPE_MP3"] = 3] = "CONTAINER_AUDIO_TYPE_MP3";
    ContainerAudio_ContainerAudioType[ContainerAudio_ContainerAudioType["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
})(ContainerAudio_ContainerAudioType = exports.ContainerAudio_ContainerAudioType || (exports.ContainerAudio_ContainerAudioType = {}));
function containerAudio_ContainerAudioTypeFromJSON(object) {
    switch (object) {
        case 0:
        case 'CONTAINER_AUDIO_TYPE_UNSPECIFIED':
            return ContainerAudio_ContainerAudioType.CONTAINER_AUDIO_TYPE_UNSPECIFIED;
        case 1:
        case 'CONTAINER_AUDIO_TYPE_WAV':
            return ContainerAudio_ContainerAudioType.CONTAINER_AUDIO_TYPE_WAV;
        case 2:
        case 'CONTAINER_AUDIO_TYPE_OGG_OPUS':
            return ContainerAudio_ContainerAudioType.CONTAINER_AUDIO_TYPE_OGG_OPUS;
        case 3:
        case 'CONTAINER_AUDIO_TYPE_MP3':
            return ContainerAudio_ContainerAudioType.CONTAINER_AUDIO_TYPE_MP3;
        case -1:
        case 'UNRECOGNIZED':
        default:
            return ContainerAudio_ContainerAudioType.UNRECOGNIZED;
    }
}
exports.containerAudio_ContainerAudioTypeFromJSON = containerAudio_ContainerAudioTypeFromJSON;
function containerAudio_ContainerAudioTypeToJSON(object) {
    switch (object) {
        case ContainerAudio_ContainerAudioType.CONTAINER_AUDIO_TYPE_UNSPECIFIED:
            return 'CONTAINER_AUDIO_TYPE_UNSPECIFIED';
        case ContainerAudio_ContainerAudioType.CONTAINER_AUDIO_TYPE_WAV:
            return 'CONTAINER_AUDIO_TYPE_WAV';
        case ContainerAudio_ContainerAudioType.CONTAINER_AUDIO_TYPE_OGG_OPUS:
            return 'CONTAINER_AUDIO_TYPE_OGG_OPUS';
        case ContainerAudio_ContainerAudioType.CONTAINER_AUDIO_TYPE_MP3:
            return 'CONTAINER_AUDIO_TYPE_MP3';
        default:
            return 'UNKNOWN';
    }
}
exports.containerAudio_ContainerAudioTypeToJSON = containerAudio_ContainerAudioTypeToJSON;
const baseRawAudio = { audioEncoding: 0, sampleRateHertz: 0, audioChannelCount: 0 };
exports.RawAudio = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.audioEncoding !== 0) {
            writer.uint32(8).int32(message.audioEncoding);
        }
        if (message.sampleRateHertz !== 0) {
            writer.uint32(16).int64(message.sampleRateHertz);
        }
        if (message.audioChannelCount !== 0) {
            writer.uint32(24).int64(message.audioChannelCount);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseRawAudio);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.audioEncoding = reader.int32();
                    break;
                case 2:
                    message.sampleRateHertz = longToNumber(reader.int64());
                    break;
                case 3:
                    message.audioChannelCount = longToNumber(reader.int64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseRawAudio);
        message.audioEncoding =
            object.audioEncoding !== undefined && object.audioEncoding !== null
                ? rawAudio_AudioEncodingFromJSON(object.audioEncoding)
                : 0;
        message.sampleRateHertz =
            object.sampleRateHertz !== undefined && object.sampleRateHertz !== null
                ? Number(object.sampleRateHertz)
                : 0;
        message.audioChannelCount =
            object.audioChannelCount !== undefined && object.audioChannelCount !== null
                ? Number(object.audioChannelCount)
                : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.audioEncoding !== undefined &&
            (obj.audioEncoding = rawAudio_AudioEncodingToJSON(message.audioEncoding));
        message.sampleRateHertz !== undefined &&
            (obj.sampleRateHertz = Math.round(message.sampleRateHertz));
        message.audioChannelCount !== undefined &&
            (obj.audioChannelCount = Math.round(message.audioChannelCount));
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseRawAudio);
        message.audioEncoding = (_a = object.audioEncoding) !== null && _a !== void 0 ? _a : 0;
        message.sampleRateHertz = (_b = object.sampleRateHertz) !== null && _b !== void 0 ? _b : 0;
        message.audioChannelCount = (_c = object.audioChannelCount) !== null && _c !== void 0 ? _c : 0;
        return message;
    },
};
const baseContainerAudio = { containerAudioType: 0 };
exports.ContainerAudio = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.containerAudioType !== 0) {
            writer.uint32(8).int32(message.containerAudioType);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseContainerAudio);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.containerAudioType = reader.int32();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseContainerAudio);
        message.containerAudioType =
            object.containerAudioType !== undefined && object.containerAudioType !== null
                ? containerAudio_ContainerAudioTypeFromJSON(object.containerAudioType)
                : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.containerAudioType !== undefined &&
            (obj.containerAudioType = containerAudio_ContainerAudioTypeToJSON(message.containerAudioType));
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseContainerAudio);
        message.containerAudioType = (_a = object.containerAudioType) !== null && _a !== void 0 ? _a : 0;
        return message;
    },
};
const baseAudioMetadata = {};
exports.AudioMetadata = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.rawAudio !== undefined) {
            exports.RawAudio.encode(message.rawAudio, writer.uint32(10).fork()).ldelim();
        }
        if (message.containerAudio !== undefined) {
            exports.ContainerAudio.encode(message.containerAudio, writer.uint32(18).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseAudioMetadata);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.rawAudio = exports.RawAudio.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.containerAudio = exports.ContainerAudio.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseAudioMetadata);
        message.rawAudio =
            object.rawAudio !== undefined && object.rawAudio !== null
                ? exports.RawAudio.fromJSON(object.rawAudio)
                : undefined;
        message.containerAudio =
            object.containerAudio !== undefined && object.containerAudio !== null
                ? exports.ContainerAudio.fromJSON(object.containerAudio)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.rawAudio !== undefined &&
            (obj.rawAudio = message.rawAudio ? exports.RawAudio.toJSON(message.rawAudio) : undefined);
        message.containerAudio !== undefined &&
            (obj.containerAudio = message.containerAudio
                ? exports.ContainerAudio.toJSON(message.containerAudio)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseAudioMetadata);
        message.rawAudio =
            object.rawAudio !== undefined && object.rawAudio !== null
                ? exports.RawAudio.fromPartial(object.rawAudio)
                : undefined;
        message.containerAudio =
            object.containerAudio !== undefined && object.containerAudio !== null
                ? exports.ContainerAudio.fromPartial(object.containerAudio)
                : undefined;
        return message;
    },
};
const baseAudioChunk = {};
exports.AudioChunk = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.data.length !== 0) {
            writer.uint32(10).bytes(message.data);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseAudioChunk);
        message.data = Buffer.alloc(0);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.data = reader.bytes();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseAudioChunk);
        message.data =
            object.data !== undefined && object.data !== null
                ? Buffer.from(bytesFromBase64(object.data))
                : Buffer.alloc(0);
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.data !== undefined &&
            (obj.data = base64FromBytes(message.data !== undefined ? message.data : Buffer.alloc(0)));
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseAudioChunk);
        message.data = (_a = object.data) !== null && _a !== void 0 ? _a : Buffer.alloc(0);
        return message;
    },
};
const baseAudioStreamingRequest = {};
exports.AudioStreamingRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.audioMetadata !== undefined) {
            exports.AudioMetadata.encode(message.audioMetadata, writer.uint32(10).fork()).ldelim();
        }
        if (message.chunk !== undefined) {
            exports.AudioChunk.encode(message.chunk, writer.uint32(18).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseAudioStreamingRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.audioMetadata = exports.AudioMetadata.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.chunk = exports.AudioChunk.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseAudioStreamingRequest);
        message.audioMetadata =
            object.audioMetadata !== undefined && object.audioMetadata !== null
                ? exports.AudioMetadata.fromJSON(object.audioMetadata)
                : undefined;
        message.chunk =
            object.chunk !== undefined && object.chunk !== null
                ? exports.AudioChunk.fromJSON(object.chunk)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.audioMetadata !== undefined &&
            (obj.audioMetadata = message.audioMetadata
                ? exports.AudioMetadata.toJSON(message.audioMetadata)
                : undefined);
        message.chunk !== undefined &&
            (obj.chunk = message.chunk ? exports.AudioChunk.toJSON(message.chunk) : undefined);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseAudioStreamingRequest);
        message.audioMetadata =
            object.audioMetadata !== undefined && object.audioMetadata !== null
                ? exports.AudioMetadata.fromPartial(object.audioMetadata)
                : undefined;
        message.chunk =
            object.chunk !== undefined && object.chunk !== null
                ? exports.AudioChunk.fromPartial(object.chunk)
                : undefined;
        return message;
    },
};
const baseAudioRequest = {};
exports.AudioRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.audioMetadata !== undefined) {
            exports.AudioMetadata.encode(message.audioMetadata, writer.uint32(10).fork()).ldelim();
        }
        if (message.audioData !== undefined) {
            exports.AudioChunk.encode(message.audioData, writer.uint32(18).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseAudioRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.audioMetadata = exports.AudioMetadata.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.audioData = exports.AudioChunk.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseAudioRequest);
        message.audioMetadata =
            object.audioMetadata !== undefined && object.audioMetadata !== null
                ? exports.AudioMetadata.fromJSON(object.audioMetadata)
                : undefined;
        message.audioData =
            object.audioData !== undefined && object.audioData !== null
                ? exports.AudioChunk.fromJSON(object.audioData)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.audioMetadata !== undefined &&
            (obj.audioMetadata = message.audioMetadata
                ? exports.AudioMetadata.toJSON(message.audioMetadata)
                : undefined);
        message.audioData !== undefined &&
            (obj.audioData = message.audioData ? exports.AudioChunk.toJSON(message.audioData) : undefined);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseAudioRequest);
        message.audioMetadata =
            object.audioMetadata !== undefined && object.audioMetadata !== null
                ? exports.AudioMetadata.fromPartial(object.audioMetadata)
                : undefined;
        message.audioData =
            object.audioData !== undefined && object.audioData !== null
                ? exports.AudioChunk.fromPartial(object.audioData)
                : undefined;
        return message;
    },
};
var globalThis = (() => {
    if (typeof globalThis !== 'undefined')
        return globalThis;
    if (typeof self !== 'undefined')
        return self;
    if (typeof window !== 'undefined')
        return window;
    if (typeof global !== 'undefined')
        return global;
    throw 'Unable to locate global object';
})();
const atob = globalThis.atob || ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary'));
function bytesFromBase64(b64) {
    const bin = atob(b64);
    const arr = new Uint8Array(bin.length);
    for (let i = 0; i < bin.length; ++i) {
        arr[i] = bin.charCodeAt(i);
    }
    return arr;
}
const btoa = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr) {
    const bin = [];
    for (const byte of arr) {
        bin.push(String.fromCharCode(byte));
    }
    return btoa(bin.join(''));
}
function longToNumber(long) {
    if (long.gt(Number.MAX_SAFE_INTEGER)) {
        throw new globalThis.Error('Value is larger than Number.MAX_SAFE_INTEGER');
    }
    return long.toNumber();
}
if (minimal_1.default.util.Long !== long_1.default) {
    minimal_1.default.util.Long = long_1.default;
    minimal_1.default.configure();
}
