@humeai/audio-decisions 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +411 -2
- package/dist/cjs/BaseClient.d.ts +54 -0
- package/dist/cjs/BaseClient.js +77 -0
- package/dist/cjs/Client.d.ts +29 -0
- package/dist/cjs/Client.js +88 -0
- package/dist/cjs/api/errors/BadRequestError.d.ts +7 -0
- package/dist/cjs/api/errors/BadRequestError.js +54 -0
- package/dist/cjs/api/errors/ContentTooLargeError.d.ts +7 -0
- package/dist/cjs/api/errors/ContentTooLargeError.js +54 -0
- package/dist/cjs/api/errors/ForbiddenError.d.ts +7 -0
- package/dist/cjs/api/errors/ForbiddenError.js +54 -0
- package/dist/cjs/api/errors/InternalServerError.d.ts +7 -0
- package/dist/cjs/api/errors/InternalServerError.js +54 -0
- package/dist/cjs/api/errors/NotFoundError.d.ts +7 -0
- package/dist/cjs/api/errors/NotFoundError.js +54 -0
- package/dist/cjs/api/errors/PaymentRequiredError.d.ts +7 -0
- package/dist/cjs/api/errors/PaymentRequiredError.js +54 -0
- package/dist/cjs/api/errors/ServiceUnavailableError.d.ts +7 -0
- package/dist/cjs/api/errors/ServiceUnavailableError.js +54 -0
- package/dist/cjs/api/errors/TooManyRequestsError.d.ts +7 -0
- package/dist/cjs/api/errors/TooManyRequestsError.js +54 -0
- package/dist/cjs/api/errors/UnauthorizedError.d.ts +7 -0
- package/dist/cjs/api/errors/UnauthorizedError.js +54 -0
- package/dist/cjs/api/errors/UnsupportedMediaTypeError.d.ts +7 -0
- package/dist/cjs/api/errors/UnsupportedMediaTypeError.js +54 -0
- package/dist/cjs/api/errors/index.d.ts +10 -0
- package/dist/cjs/api/errors/index.js +26 -0
- package/dist/cjs/api/index.d.ts +3 -0
- package/dist/cjs/api/index.js +19 -0
- package/dist/cjs/api/resources/decisions/client/Client.d.ts +284 -0
- package/dist/cjs/api/resources/decisions/client/Client.js +564 -0
- package/dist/cjs/api/resources/decisions/client/index.d.ts +1 -0
- package/dist/cjs/api/resources/decisions/client/index.js +17 -0
- package/dist/cjs/api/resources/decisions/client/requests/DecisionsUpload.d.ts +118 -0
- package/dist/cjs/api/resources/decisions/client/requests/DecisionsUpload.js +3 -0
- package/dist/cjs/api/resources/decisions/client/requests/InputTokensRequest.d.ts +44 -0
- package/dist/cjs/api/resources/decisions/client/requests/InputTokensRequest.js +3 -0
- package/dist/cjs/api/resources/decisions/client/requests/index.d.ts +2 -0
- package/dist/cjs/api/resources/decisions/client/requests/index.js +2 -0
- package/dist/cjs/api/resources/decisions/exports.d.ts +2 -0
- package/dist/cjs/api/resources/decisions/exports.js +21 -0
- package/dist/cjs/api/resources/decisions/index.d.ts +1 -0
- package/dist/cjs/api/resources/decisions/index.js +17 -0
- package/dist/cjs/api/resources/index.d.ts +4 -0
- package/dist/cjs/api/resources/index.js +43 -0
- package/dist/cjs/api/resources/runs/client/Client.d.ts +60 -0
- package/dist/cjs/api/resources/runs/client/Client.js +306 -0
- package/dist/cjs/api/resources/runs/client/index.d.ts +1 -0
- package/dist/cjs/api/resources/runs/client/index.js +17 -0
- package/dist/cjs/api/resources/runs/client/requests/GetRunsRequest.d.ts +10 -0
- package/dist/cjs/api/resources/runs/client/requests/GetRunsRequest.js +3 -0
- package/dist/cjs/api/resources/runs/client/requests/ListRunsRequest.d.ts +19 -0
- package/dist/cjs/api/resources/runs/client/requests/ListRunsRequest.js +3 -0
- package/dist/cjs/api/resources/runs/client/requests/index.d.ts +2 -0
- package/dist/cjs/api/resources/runs/client/requests/index.js +2 -0
- package/dist/cjs/api/resources/runs/exports.d.ts +2 -0
- package/dist/cjs/api/resources/runs/exports.js +21 -0
- package/dist/cjs/api/resources/runs/index.d.ts +1 -0
- package/dist/cjs/api/resources/runs/index.js +17 -0
- package/dist/cjs/api/types/Answer.d.ts +19 -0
- package/dist/cjs/api/types/Answer.js +3 -0
- package/dist/cjs/api/types/Answers.d.ts +7 -0
- package/dist/cjs/api/types/Answers.js +3 -0
- package/dist/cjs/api/types/ChoiceAnswer.d.ts +11 -0
- package/dist/cjs/api/types/ChoiceAnswer.js +3 -0
- package/dist/cjs/api/types/ChoiceQuestion.d.ts +10 -0
- package/dist/cjs/api/types/ChoiceQuestion.js +3 -0
- package/dist/cjs/api/types/Criterion.d.ts +9 -0
- package/dist/cjs/api/types/Criterion.js +3 -0
- package/dist/cjs/api/types/DecisionsRequest.d.ts +9 -0
- package/dist/cjs/api/types/DecisionsRequest.js +3 -0
- package/dist/cjs/api/types/DecisionsResponse.d.ts +10 -0
- package/dist/cjs/api/types/DecisionsResponse.js +3 -0
- package/dist/cjs/api/types/ErrorCode.d.ts +58 -0
- package/dist/cjs/api/types/ErrorCode.js +61 -0
- package/dist/cjs/api/types/ErrorType.d.ts +5 -0
- package/dist/cjs/api/types/ErrorType.js +8 -0
- package/dist/cjs/api/types/Error_.d.ts +15 -0
- package/dist/cjs/api/types/Error_.js +3 -0
- package/dist/cjs/api/types/GatewayError.d.ts +9 -0
- package/dist/cjs/api/types/GatewayError.js +3 -0
- package/dist/cjs/api/types/InputTokensResponse.d.ts +7 -0
- package/dist/cjs/api/types/InputTokensResponse.js +3 -0
- package/dist/cjs/api/types/Moment.d.ts +11 -0
- package/dist/cjs/api/types/Moment.js +3 -0
- package/dist/cjs/api/types/MomentAnswer.d.ts +8 -0
- package/dist/cjs/api/types/MomentAnswer.js +3 -0
- package/dist/cjs/api/types/MomentQuestion.d.ts +7 -0
- package/dist/cjs/api/types/MomentQuestion.js +3 -0
- package/dist/cjs/api/types/NoulAnswer.d.ts +7 -0
- package/dist/cjs/api/types/NoulAnswer.js +3 -0
- package/dist/cjs/api/types/NoulCriteria.d.ts +9 -0
- package/dist/cjs/api/types/NoulCriteria.js +3 -0
- package/dist/cjs/api/types/NoulQuestion.d.ts +9 -0
- package/dist/cjs/api/types/NoulQuestion.js +3 -0
- package/dist/cjs/api/types/Question.d.ts +19 -0
- package/dist/cjs/api/types/Question.js +3 -0
- package/dist/cjs/api/types/Questions.d.ts +7 -0
- package/dist/cjs/api/types/Questions.js +3 -0
- package/dist/cjs/api/types/Received.d.ts +7 -0
- package/dist/cjs/api/types/Received.js +3 -0
- package/dist/cjs/api/types/Run.d.ts +18 -0
- package/dist/cjs/api/types/Run.js +3 -0
- package/dist/cjs/api/types/RunReceived.d.ts +9 -0
- package/dist/cjs/api/types/RunReceived.js +3 -0
- package/dist/cjs/api/types/RunStatus.d.ts +6 -0
- package/dist/cjs/api/types/RunStatus.js +9 -0
- package/dist/cjs/api/types/RunSummary.d.ts +16 -0
- package/dist/cjs/api/types/RunSummary.js +3 -0
- package/dist/cjs/api/types/RunsPage.d.ts +10 -0
- package/dist/cjs/api/types/RunsPage.js +3 -0
- package/dist/cjs/api/types/ScoreAnswer.d.ts +13 -0
- package/dist/cjs/api/types/ScoreAnswer.js +3 -0
- package/dist/cjs/api/types/ScoreQuestion.d.ts +9 -0
- package/dist/cjs/api/types/ScoreQuestion.js +3 -0
- package/dist/cjs/api/types/index.d.ts +28 -0
- package/dist/cjs/api/types/index.js +44 -0
- package/dist/cjs/audio-helpers/bytes.d.ts +6 -0
- package/dist/cjs/audio-helpers/bytes.js +38 -0
- package/dist/cjs/audio-helpers/checks.d.ts +2 -0
- package/dist/cjs/audio-helpers/checks.js +25 -0
- package/dist/cjs/audio-helpers/chunks.d.ts +160 -0
- package/dist/cjs/audio-helpers/chunks.js +350 -0
- package/dist/cjs/audio-helpers/downmix.d.ts +17 -0
- package/dist/cjs/audio-helpers/downmix.js +291 -0
- package/dist/cjs/audio-helpers/errors.d.ts +4 -0
- package/dist/cjs/audio-helpers/errors.js +12 -0
- package/dist/cjs/audio-helpers/files.d.ts +27 -0
- package/dist/cjs/audio-helpers/files.js +178 -0
- package/dist/cjs/audio-helpers/index.d.ts +4 -0
- package/dist/cjs/audio-helpers/index.js +11 -0
- package/dist/cjs/audio-helpers/integers.d.ts +3 -0
- package/dist/cjs/audio-helpers/integers.js +26 -0
- package/dist/cjs/audio-helpers/mp3.d.ts +24 -0
- package/dist/cjs/audio-helpers/mp3.js +245 -0
- package/dist/cjs/audio-helpers/results.d.ts +74 -0
- package/dist/cjs/audio-helpers/results.js +187 -0
- package/dist/cjs/audio-helpers/wav.d.ts +21 -0
- package/dist/cjs/audio-helpers/wav.js +167 -0
- package/dist/cjs/auth/HeaderAuthProvider.d.ts +20 -0
- package/dist/cjs/auth/HeaderAuthProvider.js +83 -0
- package/dist/cjs/auth/index.d.ts +1 -0
- package/dist/cjs/auth/index.js +5 -0
- package/dist/cjs/core/auth/AuthProvider.d.ts +8 -0
- package/dist/cjs/core/auth/AuthProvider.js +9 -0
- package/dist/cjs/core/auth/AuthRequest.d.ts +9 -0
- package/dist/cjs/core/auth/AuthRequest.js +2 -0
- package/dist/cjs/core/auth/BasicAuth.d.ts +8 -0
- package/dist/cjs/core/auth/BasicAuth.js +33 -0
- package/dist/cjs/core/auth/BearerToken.d.ts +7 -0
- package/dist/cjs/core/auth/BearerToken.js +16 -0
- package/dist/cjs/core/auth/NoOpAuthProvider.d.ts +5 -0
- package/dist/cjs/core/auth/NoOpAuthProvider.js +9 -0
- package/dist/cjs/core/auth/index.d.ts +5 -0
- package/dist/cjs/core/auth/index.js +11 -0
- package/dist/cjs/core/base64.d.ts +2 -0
- package/dist/cjs/core/base64.js +26 -0
- package/dist/cjs/core/exports.d.ts +2 -0
- package/dist/cjs/core/exports.js +18 -0
- package/dist/cjs/core/fetcher/APIResponse.d.ts +20 -0
- package/dist/cjs/core/fetcher/APIResponse.js +2 -0
- package/dist/cjs/core/fetcher/BinaryResponse.d.ts +19 -0
- package/dist/cjs/core/fetcher/BinaryResponse.js +17 -0
- package/dist/cjs/core/fetcher/EndpointMetadata.d.ts +13 -0
- package/dist/cjs/core/fetcher/EndpointMetadata.js +2 -0
- package/dist/cjs/core/fetcher/EndpointSupplier.d.ts +12 -0
- package/dist/cjs/core/fetcher/EndpointSupplier.js +22 -0
- package/dist/cjs/core/fetcher/Fetcher.d.ts +56 -0
- package/dist/cjs/core/fetcher/Fetcher.js +275 -0
- package/dist/cjs/core/fetcher/Headers.d.ts +2 -0
- package/dist/cjs/core/fetcher/Headers.js +84 -0
- package/dist/cjs/core/fetcher/HttpResponsePromise.d.ts +58 -0
- package/dist/cjs/core/fetcher/HttpResponsePromise.js +103 -0
- package/dist/cjs/core/fetcher/RawResponse.d.ts +29 -0
- package/dist/cjs/core/fetcher/RawResponse.js +44 -0
- package/dist/cjs/core/fetcher/Supplier.d.ts +4 -0
- package/dist/cjs/core/fetcher/Supplier.js +22 -0
- package/dist/cjs/core/fetcher/createRequestUrl.d.ts +1 -0
- package/dist/cjs/core/fetcher/createRequestUrl.js +8 -0
- package/dist/cjs/core/fetcher/getErrorResponseBody.d.ts +1 -0
- package/dist/cjs/core/fetcher/getErrorResponseBody.js +58 -0
- package/dist/cjs/core/fetcher/getFetchFn.d.ts +1 -0
- package/dist/cjs/core/fetcher/getFetchFn.js +17 -0
- package/dist/cjs/core/fetcher/getHeader.d.ts +1 -0
- package/dist/cjs/core/fetcher/getHeader.js +11 -0
- package/dist/cjs/core/fetcher/getRequestBody.d.ts +7 -0
- package/dist/cjs/core/fetcher/getRequestBody.js +27 -0
- package/dist/cjs/core/fetcher/getResponseBody.d.ts +17 -0
- package/dist/cjs/core/fetcher/getResponseBody.js +85 -0
- package/dist/cjs/core/fetcher/index.d.ts +13 -0
- package/dist/cjs/core/fetcher/index.js +19 -0
- package/dist/cjs/core/fetcher/makePassthroughRequest.d.ts +49 -0
- package/dist/cjs/core/fetcher/makePassthroughRequest.js +173 -0
- package/dist/cjs/core/fetcher/makeRequest.d.ts +11 -0
- package/dist/cjs/core/fetcher/makeRequest.js +94 -0
- package/dist/cjs/core/fetcher/redactUrl.d.ts +2 -0
- package/dist/cjs/core/fetcher/redactUrl.js +88 -0
- package/dist/cjs/core/fetcher/requestWithRetries.d.ts +1 -0
- package/dist/cjs/core/fetcher/requestWithRetries.js +91 -0
- package/dist/cjs/core/fetcher/signals.d.ts +6 -0
- package/dist/cjs/core/fetcher/signals.js +33 -0
- package/dist/cjs/core/file/exports.d.ts +1 -0
- package/dist/cjs/core/file/exports.js +2 -0
- package/dist/cjs/core/file/file.d.ts +10 -0
- package/dist/cjs/core/file/file.js +225 -0
- package/dist/cjs/core/file/index.d.ts +2 -0
- package/dist/cjs/core/file/index.js +18 -0
- package/dist/cjs/core/file/types.d.ts +66 -0
- package/dist/cjs/core/file/types.js +2 -0
- package/dist/cjs/core/form-data-utils/FormDataWrapper.d.ts +15 -0
- package/dist/cjs/core/form-data-utils/FormDataWrapper.js +192 -0
- package/dist/cjs/core/form-data-utils/encodeAsFormParameter.d.ts +1 -0
- package/dist/cjs/core/form-data-utils/encodeAsFormParameter.js +12 -0
- package/dist/cjs/core/form-data-utils/index.d.ts +2 -0
- package/dist/cjs/core/form-data-utils/index.js +20 -0
- package/dist/cjs/core/headers.d.ts +2 -0
- package/dist/cjs/core/headers.js +31 -0
- package/dist/cjs/core/index.d.ts +9 -0
- package/dist/cjs/core/index.js +48 -0
- package/dist/cjs/core/json.d.ts +15 -0
- package/dist/cjs/core/json.js +24 -0
- package/dist/cjs/core/logging/exports.d.ts +18 -0
- package/dist/cjs/core/logging/exports.js +45 -0
- package/dist/cjs/core/logging/index.d.ts +1 -0
- package/dist/cjs/core/logging/index.js +17 -0
- package/dist/cjs/core/logging/logger.d.ts +126 -0
- package/dist/cjs/core/logging/logger.js +144 -0
- package/dist/cjs/core/requestBody.d.ts +12 -0
- package/dist/cjs/core/requestBody.js +26 -0
- package/dist/cjs/core/runtime/index.d.ts +1 -0
- package/dist/cjs/core/runtime/index.js +6 -0
- package/dist/cjs/core/runtime/runtime.d.ts +28 -0
- package/dist/cjs/core/runtime/runtime.js +176 -0
- package/dist/cjs/core/schemas/Schema.d.ts +88 -0
- package/dist/cjs/core/schemas/Schema.js +25 -0
- package/dist/cjs/core/schemas/builders/bigint/bigint.d.ts +2 -0
- package/dist/cjs/core/schemas/builders/bigint/bigint.js +53 -0
- package/dist/cjs/core/schemas/builders/bigint/index.d.ts +1 -0
- package/dist/cjs/core/schemas/builders/bigint/index.js +5 -0
- package/dist/cjs/core/schemas/builders/date/date.d.ts +2 -0
- package/dist/cjs/core/schemas/builders/date/date.js +62 -0
- package/dist/cjs/core/schemas/builders/date/index.d.ts +1 -0
- package/dist/cjs/core/schemas/builders/date/index.js +5 -0
- package/dist/cjs/core/schemas/builders/enum/enum.d.ts +3 -0
- package/dist/cjs/core/schemas/builders/enum/enum.js +45 -0
- package/dist/cjs/core/schemas/builders/enum/index.d.ts +1 -0
- package/dist/cjs/core/schemas/builders/enum/index.js +6 -0
- package/dist/cjs/core/schemas/builders/index.d.ts +14 -0
- package/dist/cjs/core/schemas/builders/index.js +30 -0
- package/dist/cjs/core/schemas/builders/lazy/index.d.ts +3 -0
- package/dist/cjs/core/schemas/builders/lazy/index.js +7 -0
- package/dist/cjs/core/schemas/builders/lazy/lazy.d.ts +5 -0
- package/dist/cjs/core/schemas/builders/lazy/lazy.js +24 -0
- package/dist/cjs/core/schemas/builders/lazy/lazyObject.d.ts +3 -0
- package/dist/cjs/core/schemas/builders/lazy/lazyObject.js +11 -0
- package/dist/cjs/core/schemas/builders/list/index.d.ts +1 -0
- package/dist/cjs/core/schemas/builders/list/index.js +5 -0
- package/dist/cjs/core/schemas/builders/list/list.d.ts +2 -0
- package/dist/cjs/core/schemas/builders/list/list.js +49 -0
- package/dist/cjs/core/schemas/builders/literals/booleanLiteral.d.ts +2 -0
- package/dist/cjs/core/schemas/builders/literals/booleanLiteral.js +28 -0
- package/dist/cjs/core/schemas/builders/literals/index.d.ts +2 -0
- package/dist/cjs/core/schemas/builders/literals/index.js +7 -0
- package/dist/cjs/core/schemas/builders/literals/stringLiteral.d.ts +2 -0
- package/dist/cjs/core/schemas/builders/literals/stringLiteral.js +28 -0
- package/dist/cjs/core/schemas/builders/object/index.d.ts +6 -0
- package/dist/cjs/core/schemas/builders/object/index.js +11 -0
- package/dist/cjs/core/schemas/builders/object/object.d.ts +3 -0
- package/dist/cjs/core/schemas/builders/object/object.js +354 -0
- package/dist/cjs/core/schemas/builders/object/objectWithoutOptionalProperties.d.ts +6 -0
- package/dist/cjs/core/schemas/builders/object/objectWithoutOptionalProperties.js +7 -0
- package/dist/cjs/core/schemas/builders/object/property.d.ts +8 -0
- package/dist/cjs/core/schemas/builders/object/property.js +15 -0
- package/dist/cjs/core/schemas/builders/object/types.d.ts +31 -0
- package/dist/cjs/core/schemas/builders/object/types.js +2 -0
- package/dist/cjs/core/schemas/builders/object-like/getObjectLikeUtils.d.ts +9 -0
- package/dist/cjs/core/schemas/builders/object-like/getObjectLikeUtils.js +60 -0
- package/dist/cjs/core/schemas/builders/object-like/index.d.ts +2 -0
- package/dist/cjs/core/schemas/builders/object-like/index.js +6 -0
- package/dist/cjs/core/schemas/builders/object-like/types.d.ts +7 -0
- package/dist/cjs/core/schemas/builders/object-like/types.js +2 -0
- package/dist/cjs/core/schemas/builders/primitives/any.d.ts +2 -0
- package/dist/cjs/core/schemas/builders/primitives/any.js +9 -0
- package/dist/cjs/core/schemas/builders/primitives/boolean.d.ts +2 -0
- package/dist/cjs/core/schemas/builders/primitives/boolean.js +25 -0
- package/dist/cjs/core/schemas/builders/primitives/index.d.ts +6 -0
- package/dist/cjs/core/schemas/builders/primitives/index.js +15 -0
- package/dist/cjs/core/schemas/builders/primitives/never.d.ts +2 -0
- package/dist/cjs/core/schemas/builders/primitives/never.js +14 -0
- package/dist/cjs/core/schemas/builders/primitives/number.d.ts +2 -0
- package/dist/cjs/core/schemas/builders/primitives/number.js +25 -0
- package/dist/cjs/core/schemas/builders/primitives/string.d.ts +2 -0
- package/dist/cjs/core/schemas/builders/primitives/string.js +25 -0
- package/dist/cjs/core/schemas/builders/primitives/unknown.d.ts +2 -0
- package/dist/cjs/core/schemas/builders/primitives/unknown.js +6 -0
- package/dist/cjs/core/schemas/builders/record/index.d.ts +2 -0
- package/dist/cjs/core/schemas/builders/record/index.js +6 -0
- package/dist/cjs/core/schemas/builders/record/record.d.ts +4 -0
- package/dist/cjs/core/schemas/builders/record/record.js +131 -0
- package/dist/cjs/core/schemas/builders/record/types.d.ts +6 -0
- package/dist/cjs/core/schemas/builders/record/types.js +2 -0
- package/dist/cjs/core/schemas/builders/schema-utils/JsonError.d.ts +5 -0
- package/dist/cjs/core/schemas/builders/schema-utils/JsonError.js +13 -0
- package/dist/cjs/core/schemas/builders/schema-utils/ParseError.d.ts +5 -0
- package/dist/cjs/core/schemas/builders/schema-utils/ParseError.js +13 -0
- package/dist/cjs/core/schemas/builders/schema-utils/getSchemaUtils.d.ts +21 -0
- package/dist/cjs/core/schemas/builders/schema-utils/getSchemaUtils.js +145 -0
- package/dist/cjs/core/schemas/builders/schema-utils/index.d.ts +4 -0
- package/dist/cjs/core/schemas/builders/schema-utils/index.js +11 -0
- package/dist/cjs/core/schemas/builders/schema-utils/stringifyValidationErrors.d.ts +2 -0
- package/dist/cjs/core/schemas/builders/schema-utils/stringifyValidationErrors.js +9 -0
- package/dist/cjs/core/schemas/builders/set/index.d.ts +1 -0
- package/dist/cjs/core/schemas/builders/set/index.js +5 -0
- package/dist/cjs/core/schemas/builders/set/set.d.ts +2 -0
- package/dist/cjs/core/schemas/builders/set/set.js +43 -0
- package/dist/cjs/core/schemas/builders/undiscriminated-union/index.d.ts +2 -0
- package/dist/cjs/core/schemas/builders/undiscriminated-union/index.js +5 -0
- package/dist/cjs/core/schemas/builders/undiscriminated-union/types.d.ts +4 -0
- package/dist/cjs/core/schemas/builders/undiscriminated-union/types.js +2 -0
- package/dist/cjs/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.d.ts +3 -0
- package/dist/cjs/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.js +39 -0
- package/dist/cjs/core/schemas/builders/union/discriminant.d.ts +5 -0
- package/dist/cjs/core/schemas/builders/union/discriminant.js +9 -0
- package/dist/cjs/core/schemas/builders/union/index.d.ts +4 -0
- package/dist/cjs/core/schemas/builders/union/index.js +7 -0
- package/dist/cjs/core/schemas/builders/union/types.d.ts +13 -0
- package/dist/cjs/core/schemas/builders/union/types.js +2 -0
- package/dist/cjs/core/schemas/builders/union/union.d.ts +4 -0
- package/dist/cjs/core/schemas/builders/union/union.js +126 -0
- package/dist/cjs/core/schemas/index.d.ts +2 -0
- package/dist/cjs/core/schemas/index.js +17 -0
- package/dist/cjs/core/schemas/utils/MaybePromise.d.ts +1 -0
- package/dist/cjs/core/schemas/utils/MaybePromise.js +2 -0
- package/dist/cjs/core/schemas/utils/addQuestionMarksToNullableProperties.d.ts +7 -0
- package/dist/cjs/core/schemas/utils/addQuestionMarksToNullableProperties.js +2 -0
- package/dist/cjs/core/schemas/utils/createIdentitySchemaCreator.d.ts +2 -0
- package/dist/cjs/core/schemas/utils/createIdentitySchemaCreator.js +15 -0
- package/dist/cjs/core/schemas/utils/entries.d.ts +1 -0
- package/dist/cjs/core/schemas/utils/entries.js +6 -0
- package/dist/cjs/core/schemas/utils/filterObject.d.ts +1 -0
- package/dist/cjs/core/schemas/utils/filterObject.js +13 -0
- package/dist/cjs/core/schemas/utils/getErrorMessageForIncorrectType.d.ts +1 -0
- package/dist/cjs/core/schemas/utils/getErrorMessageForIncorrectType.js +27 -0
- package/dist/cjs/core/schemas/utils/isPlainObject.d.ts +1 -0
- package/dist/cjs/core/schemas/utils/isPlainObject.js +15 -0
- package/dist/cjs/core/schemas/utils/keys.d.ts +1 -0
- package/dist/cjs/core/schemas/utils/keys.js +6 -0
- package/dist/cjs/core/schemas/utils/maybeSkipValidation.d.ts +2 -0
- package/dist/cjs/core/schemas/utils/maybeSkipValidation.js +27 -0
- package/dist/cjs/core/schemas/utils/partition.d.ts +1 -0
- package/dist/cjs/core/schemas/utils/partition.js +15 -0
- package/dist/cjs/core/url/QueryStringBuilder.d.ts +47 -0
- package/dist/cjs/core/url/QueryStringBuilder.js +83 -0
- package/dist/cjs/core/url/encodePathParam.d.ts +3 -0
- package/dist/cjs/core/url/encodePathParam.js +27 -0
- package/dist/cjs/core/url/index.d.ts +4 -0
- package/dist/cjs/core/url/index.js +11 -0
- package/dist/cjs/core/url/join.d.ts +1 -0
- package/dist/cjs/core/url/join.js +68 -0
- package/dist/cjs/core/url/qs.d.ts +7 -0
- package/dist/cjs/core/url/qs.js +76 -0
- package/dist/cjs/environments.d.ts +4 -0
- package/dist/cjs/environments.js +7 -0
- package/dist/cjs/errors/DecisionsError.d.ts +15 -0
- package/dist/cjs/errors/DecisionsError.js +53 -0
- package/dist/cjs/errors/DecisionsTimeoutError.d.ts +6 -0
- package/dist/cjs/errors/DecisionsTimeoutError.js +52 -0
- package/dist/cjs/errors/handleNonStatusCodeError.d.ts +2 -0
- package/dist/cjs/errors/handleNonStatusCodeError.js +68 -0
- package/dist/cjs/errors/index.d.ts +2 -0
- package/dist/cjs/errors/index.js +7 -0
- package/dist/cjs/exports.d.ts +1 -0
- package/dist/cjs/exports.js +17 -0
- package/dist/cjs/index.d.ts +7 -0
- package/dist/cjs/index.js +49 -0
- package/dist/cjs/serialization/index.d.ts +2 -0
- package/dist/cjs/serialization/index.js +18 -0
- package/dist/cjs/serialization/resources/decisions/client/index.d.ts +1 -0
- package/dist/cjs/serialization/resources/decisions/client/index.js +17 -0
- package/dist/cjs/serialization/resources/decisions/client/requests/InputTokensRequest.d.ts +12 -0
- package/dist/cjs/serialization/resources/decisions/client/requests/InputTokensRequest.js +44 -0
- package/dist/cjs/serialization/resources/decisions/client/requests/index.d.ts +1 -0
- package/dist/cjs/serialization/resources/decisions/client/requests/index.js +5 -0
- package/dist/cjs/serialization/resources/decisions/index.d.ts +1 -0
- package/dist/cjs/serialization/resources/decisions/index.js +17 -0
- package/dist/cjs/serialization/resources/index.d.ts +2 -0
- package/dist/cjs/serialization/resources/index.js +41 -0
- package/dist/cjs/serialization/types/Answer.d.ts +23 -0
- package/dist/cjs/serialization/types/Answer.js +53 -0
- package/dist/cjs/serialization/types/Answers.d.ts +10 -0
- package/dist/cjs/serialization/types/Answers.js +40 -0
- package/dist/cjs/serialization/types/ChoiceAnswer.d.ts +11 -0
- package/dist/cjs/serialization/types/ChoiceAnswer.js +43 -0
- package/dist/cjs/serialization/types/ChoiceQuestion.d.ts +11 -0
- package/dist/cjs/serialization/types/ChoiceQuestion.js +43 -0
- package/dist/cjs/serialization/types/Criterion.d.ts +10 -0
- package/dist/cjs/serialization/types/Criterion.js +42 -0
- package/dist/cjs/serialization/types/DecisionsRequest.d.ts +11 -0
- package/dist/cjs/serialization/types/DecisionsRequest.js +43 -0
- package/dist/cjs/serialization/types/DecisionsResponse.d.ts +13 -0
- package/dist/cjs/serialization/types/DecisionsResponse.js +45 -0
- package/dist/cjs/serialization/types/ErrorCode.d.ts +7 -0
- package/dist/cjs/serialization/types/ErrorCode.js +54 -0
- package/dist/cjs/serialization/types/ErrorType.d.ts +7 -0
- package/dist/cjs/serialization/types/ErrorType.js +39 -0
- package/dist/cjs/serialization/types/Error_.d.ts +15 -0
- package/dist/cjs/serialization/types/Error_.js +47 -0
- package/dist/cjs/serialization/types/GatewayError.d.ts +10 -0
- package/dist/cjs/serialization/types/GatewayError.js +42 -0
- package/dist/cjs/serialization/types/InputTokensResponse.d.ts +9 -0
- package/dist/cjs/serialization/types/InputTokensResponse.js +41 -0
- package/dist/cjs/serialization/types/Moment.d.ts +11 -0
- package/dist/cjs/serialization/types/Moment.js +43 -0
- package/dist/cjs/serialization/types/MomentAnswer.d.ts +10 -0
- package/dist/cjs/serialization/types/MomentAnswer.js +42 -0
- package/dist/cjs/serialization/types/MomentQuestion.d.ts +9 -0
- package/dist/cjs/serialization/types/MomentQuestion.js +41 -0
- package/dist/cjs/serialization/types/NoulAnswer.d.ts +9 -0
- package/dist/cjs/serialization/types/NoulAnswer.js +41 -0
- package/dist/cjs/serialization/types/NoulCriteria.d.ts +10 -0
- package/dist/cjs/serialization/types/NoulCriteria.js +42 -0
- package/dist/cjs/serialization/types/NoulQuestion.d.ts +11 -0
- package/dist/cjs/serialization/types/NoulQuestion.js +43 -0
- package/dist/cjs/serialization/types/Question.d.ts +23 -0
- package/dist/cjs/serialization/types/Question.js +53 -0
- package/dist/cjs/serialization/types/Questions.d.ts +10 -0
- package/dist/cjs/serialization/types/Questions.js +40 -0
- package/dist/cjs/serialization/types/Received.d.ts +9 -0
- package/dist/cjs/serialization/types/Received.js +41 -0
- package/dist/cjs/serialization/types/Run.d.ts +18 -0
- package/dist/cjs/serialization/types/Run.js +50 -0
- package/dist/cjs/serialization/types/RunReceived.d.ts +10 -0
- package/dist/cjs/serialization/types/RunReceived.js +42 -0
- package/dist/cjs/serialization/types/RunStatus.d.ts +7 -0
- package/dist/cjs/serialization/types/RunStatus.js +39 -0
- package/dist/cjs/serialization/types/RunSummary.d.ts +16 -0
- package/dist/cjs/serialization/types/RunSummary.js +48 -0
- package/dist/cjs/serialization/types/RunsPage.d.ts +11 -0
- package/dist/cjs/serialization/types/RunsPage.js +43 -0
- package/dist/cjs/serialization/types/ScoreAnswer.d.ts +12 -0
- package/dist/cjs/serialization/types/ScoreAnswer.js +44 -0
- package/dist/cjs/serialization/types/ScoreQuestion.d.ts +10 -0
- package/dist/cjs/serialization/types/ScoreQuestion.js +42 -0
- package/dist/cjs/serialization/types/index.d.ts +28 -0
- package/dist/cjs/serialization/types/index.js +44 -0
- package/dist/cjs/version.d.ts +1 -0
- package/dist/cjs/version.js +4 -0
- package/dist/esm/BaseClient.d.mts +54 -0
- package/dist/esm/BaseClient.mjs +40 -0
- package/dist/esm/Client.d.mts +29 -0
- package/dist/esm/Client.mjs +51 -0
- package/dist/esm/api/errors/BadRequestError.d.mts +7 -0
- package/dist/esm/api/errors/BadRequestError.mjs +17 -0
- package/dist/esm/api/errors/ContentTooLargeError.d.mts +7 -0
- package/dist/esm/api/errors/ContentTooLargeError.mjs +17 -0
- package/dist/esm/api/errors/ForbiddenError.d.mts +7 -0
- package/dist/esm/api/errors/ForbiddenError.mjs +17 -0
- package/dist/esm/api/errors/InternalServerError.d.mts +7 -0
- package/dist/esm/api/errors/InternalServerError.mjs +17 -0
- package/dist/esm/api/errors/NotFoundError.d.mts +7 -0
- package/dist/esm/api/errors/NotFoundError.mjs +17 -0
- package/dist/esm/api/errors/PaymentRequiredError.d.mts +7 -0
- package/dist/esm/api/errors/PaymentRequiredError.mjs +17 -0
- package/dist/esm/api/errors/ServiceUnavailableError.d.mts +7 -0
- package/dist/esm/api/errors/ServiceUnavailableError.mjs +17 -0
- package/dist/esm/api/errors/TooManyRequestsError.d.mts +7 -0
- package/dist/esm/api/errors/TooManyRequestsError.mjs +17 -0
- package/dist/esm/api/errors/UnauthorizedError.d.mts +7 -0
- package/dist/esm/api/errors/UnauthorizedError.mjs +17 -0
- package/dist/esm/api/errors/UnsupportedMediaTypeError.d.mts +7 -0
- package/dist/esm/api/errors/UnsupportedMediaTypeError.mjs +17 -0
- package/dist/esm/api/errors/index.d.mts +10 -0
- package/dist/esm/api/errors/index.mjs +10 -0
- package/dist/esm/api/index.d.mts +3 -0
- package/dist/esm/api/index.mjs +3 -0
- package/dist/esm/api/resources/decisions/client/Client.d.mts +284 -0
- package/dist/esm/api/resources/decisions/client/Client.mjs +527 -0
- package/dist/esm/api/resources/decisions/client/index.d.mts +1 -0
- package/dist/esm/api/resources/decisions/client/index.mjs +1 -0
- package/dist/esm/api/resources/decisions/client/requests/DecisionsUpload.d.mts +118 -0
- package/dist/esm/api/resources/decisions/client/requests/DecisionsUpload.mjs +2 -0
- package/dist/esm/api/resources/decisions/client/requests/InputTokensRequest.d.mts +44 -0
- package/dist/esm/api/resources/decisions/client/requests/InputTokensRequest.mjs +2 -0
- package/dist/esm/api/resources/decisions/client/requests/index.d.mts +2 -0
- package/dist/esm/api/resources/decisions/client/requests/index.mjs +1 -0
- package/dist/esm/api/resources/decisions/exports.d.mts +2 -0
- package/dist/esm/api/resources/decisions/exports.mjs +3 -0
- package/dist/esm/api/resources/decisions/index.d.mts +1 -0
- package/dist/esm/api/resources/decisions/index.mjs +1 -0
- package/dist/esm/api/resources/index.d.mts +4 -0
- package/dist/esm/api/resources/index.mjs +4 -0
- package/dist/esm/api/resources/runs/client/Client.d.mts +60 -0
- package/dist/esm/api/resources/runs/client/Client.mjs +269 -0
- package/dist/esm/api/resources/runs/client/index.d.mts +1 -0
- package/dist/esm/api/resources/runs/client/index.mjs +1 -0
- package/dist/esm/api/resources/runs/client/requests/GetRunsRequest.d.mts +10 -0
- package/dist/esm/api/resources/runs/client/requests/GetRunsRequest.mjs +2 -0
- package/dist/esm/api/resources/runs/client/requests/ListRunsRequest.d.mts +19 -0
- package/dist/esm/api/resources/runs/client/requests/ListRunsRequest.mjs +2 -0
- package/dist/esm/api/resources/runs/client/requests/index.d.mts +2 -0
- package/dist/esm/api/resources/runs/client/requests/index.mjs +1 -0
- package/dist/esm/api/resources/runs/exports.d.mts +2 -0
- package/dist/esm/api/resources/runs/exports.mjs +3 -0
- package/dist/esm/api/resources/runs/index.d.mts +1 -0
- package/dist/esm/api/resources/runs/index.mjs +1 -0
- package/dist/esm/api/types/Answer.d.mts +19 -0
- package/dist/esm/api/types/Answer.mjs +2 -0
- package/dist/esm/api/types/Answers.d.mts +7 -0
- package/dist/esm/api/types/Answers.mjs +2 -0
- package/dist/esm/api/types/ChoiceAnswer.d.mts +11 -0
- package/dist/esm/api/types/ChoiceAnswer.mjs +2 -0
- package/dist/esm/api/types/ChoiceQuestion.d.mts +10 -0
- package/dist/esm/api/types/ChoiceQuestion.mjs +2 -0
- package/dist/esm/api/types/Criterion.d.mts +9 -0
- package/dist/esm/api/types/Criterion.mjs +2 -0
- package/dist/esm/api/types/DecisionsRequest.d.mts +9 -0
- package/dist/esm/api/types/DecisionsRequest.mjs +2 -0
- package/dist/esm/api/types/DecisionsResponse.d.mts +10 -0
- package/dist/esm/api/types/DecisionsResponse.mjs +2 -0
- package/dist/esm/api/types/ErrorCode.d.mts +58 -0
- package/dist/esm/api/types/ErrorCode.mjs +58 -0
- package/dist/esm/api/types/ErrorType.d.mts +5 -0
- package/dist/esm/api/types/ErrorType.mjs +5 -0
- package/dist/esm/api/types/Error_.d.mts +15 -0
- package/dist/esm/api/types/Error_.mjs +2 -0
- package/dist/esm/api/types/GatewayError.d.mts +9 -0
- package/dist/esm/api/types/GatewayError.mjs +2 -0
- package/dist/esm/api/types/InputTokensResponse.d.mts +7 -0
- package/dist/esm/api/types/InputTokensResponse.mjs +2 -0
- package/dist/esm/api/types/Moment.d.mts +11 -0
- package/dist/esm/api/types/Moment.mjs +2 -0
- package/dist/esm/api/types/MomentAnswer.d.mts +8 -0
- package/dist/esm/api/types/MomentAnswer.mjs +2 -0
- package/dist/esm/api/types/MomentQuestion.d.mts +7 -0
- package/dist/esm/api/types/MomentQuestion.mjs +2 -0
- package/dist/esm/api/types/NoulAnswer.d.mts +7 -0
- package/dist/esm/api/types/NoulAnswer.mjs +2 -0
- package/dist/esm/api/types/NoulCriteria.d.mts +9 -0
- package/dist/esm/api/types/NoulCriteria.mjs +2 -0
- package/dist/esm/api/types/NoulQuestion.d.mts +9 -0
- package/dist/esm/api/types/NoulQuestion.mjs +2 -0
- package/dist/esm/api/types/Question.d.mts +19 -0
- package/dist/esm/api/types/Question.mjs +2 -0
- package/dist/esm/api/types/Questions.d.mts +7 -0
- package/dist/esm/api/types/Questions.mjs +2 -0
- package/dist/esm/api/types/Received.d.mts +7 -0
- package/dist/esm/api/types/Received.mjs +2 -0
- package/dist/esm/api/types/Run.d.mts +18 -0
- package/dist/esm/api/types/Run.mjs +2 -0
- package/dist/esm/api/types/RunReceived.d.mts +9 -0
- package/dist/esm/api/types/RunReceived.mjs +2 -0
- package/dist/esm/api/types/RunStatus.d.mts +6 -0
- package/dist/esm/api/types/RunStatus.mjs +6 -0
- package/dist/esm/api/types/RunSummary.d.mts +16 -0
- package/dist/esm/api/types/RunSummary.mjs +2 -0
- package/dist/esm/api/types/RunsPage.d.mts +10 -0
- package/dist/esm/api/types/RunsPage.mjs +2 -0
- package/dist/esm/api/types/ScoreAnswer.d.mts +13 -0
- package/dist/esm/api/types/ScoreAnswer.mjs +2 -0
- package/dist/esm/api/types/ScoreQuestion.d.mts +9 -0
- package/dist/esm/api/types/ScoreQuestion.mjs +2 -0
- package/dist/esm/api/types/index.d.mts +28 -0
- package/dist/esm/api/types/index.mjs +28 -0
- package/dist/esm/audio-helpers/bytes.d.mts +6 -0
- package/dist/esm/audio-helpers/bytes.mjs +32 -0
- package/dist/esm/audio-helpers/checks.d.mts +2 -0
- package/dist/esm/audio-helpers/checks.mjs +21 -0
- package/dist/esm/audio-helpers/chunks.d.mts +160 -0
- package/dist/esm/audio-helpers/chunks.mjs +346 -0
- package/dist/esm/audio-helpers/downmix.d.mts +17 -0
- package/dist/esm/audio-helpers/downmix.mjs +287 -0
- package/dist/esm/audio-helpers/errors.d.mts +4 -0
- package/dist/esm/audio-helpers/errors.mjs +8 -0
- package/dist/esm/audio-helpers/files.d.mts +27 -0
- package/dist/esm/audio-helpers/files.mjs +173 -0
- package/dist/esm/audio-helpers/index.d.mts +4 -0
- package/dist/esm/audio-helpers/index.mjs +5 -0
- package/dist/esm/audio-helpers/integers.d.mts +3 -0
- package/dist/esm/audio-helpers/integers.mjs +21 -0
- package/dist/esm/audio-helpers/mp3.d.mts +24 -0
- package/dist/esm/audio-helpers/mp3.mjs +239 -0
- package/dist/esm/audio-helpers/results.d.mts +74 -0
- package/dist/esm/audio-helpers/results.mjs +181 -0
- package/dist/esm/audio-helpers/wav.d.mts +21 -0
- package/dist/esm/audio-helpers/wav.mjs +161 -0
- package/dist/esm/auth/HeaderAuthProvider.d.mts +20 -0
- package/dist/esm/auth/HeaderAuthProvider.mjs +46 -0
- package/dist/esm/auth/index.d.mts +1 -0
- package/dist/esm/auth/index.mjs +1 -0
- package/dist/esm/core/auth/AuthProvider.d.mts +8 -0
- package/dist/esm/core/auth/AuthProvider.mjs +6 -0
- package/dist/esm/core/auth/AuthRequest.d.mts +9 -0
- package/dist/esm/core/auth/AuthRequest.mjs +1 -0
- package/dist/esm/core/auth/BasicAuth.d.mts +8 -0
- package/dist/esm/core/auth/BasicAuth.mjs +30 -0
- package/dist/esm/core/auth/BearerToken.d.mts +7 -0
- package/dist/esm/core/auth/BearerToken.mjs +13 -0
- package/dist/esm/core/auth/NoOpAuthProvider.d.mts +5 -0
- package/dist/esm/core/auth/NoOpAuthProvider.mjs +5 -0
- package/dist/esm/core/auth/index.d.mts +5 -0
- package/dist/esm/core/auth/index.mjs +4 -0
- package/dist/esm/core/base64.d.mts +2 -0
- package/dist/esm/core/base64.mjs +22 -0
- package/dist/esm/core/exports.d.mts +2 -0
- package/dist/esm/core/exports.mjs +2 -0
- package/dist/esm/core/fetcher/APIResponse.d.mts +20 -0
- package/dist/esm/core/fetcher/APIResponse.mjs +1 -0
- package/dist/esm/core/fetcher/BinaryResponse.d.mts +19 -0
- package/dist/esm/core/fetcher/BinaryResponse.mjs +14 -0
- package/dist/esm/core/fetcher/EndpointMetadata.d.mts +13 -0
- package/dist/esm/core/fetcher/EndpointMetadata.mjs +1 -0
- package/dist/esm/core/fetcher/EndpointSupplier.d.mts +12 -0
- package/dist/esm/core/fetcher/EndpointSupplier.mjs +19 -0
- package/dist/esm/core/fetcher/Fetcher.d.mts +56 -0
- package/dist/esm/core/fetcher/Fetcher.mjs +271 -0
- package/dist/esm/core/fetcher/Headers.d.mts +2 -0
- package/dist/esm/core/fetcher/Headers.mjs +82 -0
- package/dist/esm/core/fetcher/HttpResponsePromise.d.mts +58 -0
- package/dist/esm/core/fetcher/HttpResponsePromise.mjs +99 -0
- package/dist/esm/core/fetcher/RawResponse.d.mts +29 -0
- package/dist/esm/core/fetcher/RawResponse.mjs +40 -0
- package/dist/esm/core/fetcher/Supplier.d.mts +4 -0
- package/dist/esm/core/fetcher/Supplier.mjs +19 -0
- package/dist/esm/core/fetcher/createRequestUrl.d.mts +1 -0
- package/dist/esm/core/fetcher/createRequestUrl.mjs +5 -0
- package/dist/esm/core/fetcher/getErrorResponseBody.d.mts +1 -0
- package/dist/esm/core/fetcher/getErrorResponseBody.mjs +55 -0
- package/dist/esm/core/fetcher/getFetchFn.d.mts +1 -0
- package/dist/esm/core/fetcher/getFetchFn.mjs +14 -0
- package/dist/esm/core/fetcher/getHeader.d.mts +1 -0
- package/dist/esm/core/fetcher/getHeader.mjs +8 -0
- package/dist/esm/core/fetcher/getRequestBody.d.mts +7 -0
- package/dist/esm/core/fetcher/getRequestBody.mjs +24 -0
- package/dist/esm/core/fetcher/getResponseBody.d.mts +17 -0
- package/dist/esm/core/fetcher/getResponseBody.mjs +81 -0
- package/dist/esm/core/fetcher/index.d.mts +13 -0
- package/dist/esm/core/fetcher/index.mjs +7 -0
- package/dist/esm/core/fetcher/makePassthroughRequest.d.mts +49 -0
- package/dist/esm/core/fetcher/makePassthroughRequest.mjs +170 -0
- package/dist/esm/core/fetcher/makeRequest.d.mts +11 -0
- package/dist/esm/core/fetcher/makeRequest.mjs +87 -0
- package/dist/esm/core/fetcher/redactUrl.d.mts +2 -0
- package/dist/esm/core/fetcher/redactUrl.mjs +84 -0
- package/dist/esm/core/fetcher/requestWithRetries.d.mts +1 -0
- package/dist/esm/core/fetcher/requestWithRetries.mjs +88 -0
- package/dist/esm/core/fetcher/signals.d.mts +6 -0
- package/dist/esm/core/fetcher/signals.mjs +28 -0
- package/dist/esm/core/file/exports.d.mts +1 -0
- package/dist/esm/core/file/exports.mjs +1 -0
- package/dist/esm/core/file/file.d.mts +10 -0
- package/dist/esm/core/file/file.mjs +188 -0
- package/dist/esm/core/file/index.d.mts +2 -0
- package/dist/esm/core/file/index.mjs +2 -0
- package/dist/esm/core/file/types.d.mts +66 -0
- package/dist/esm/core/file/types.mjs +1 -0
- package/dist/esm/core/form-data-utils/FormDataWrapper.d.mts +15 -0
- package/dist/esm/core/form-data-utils/FormDataWrapper.mjs +154 -0
- package/dist/esm/core/form-data-utils/encodeAsFormParameter.d.mts +1 -0
- package/dist/esm/core/form-data-utils/encodeAsFormParameter.mjs +9 -0
- package/dist/esm/core/form-data-utils/index.d.mts +2 -0
- package/dist/esm/core/form-data-utils/index.mjs +2 -0
- package/dist/esm/core/headers.d.mts +2 -0
- package/dist/esm/core/headers.mjs +27 -0
- package/dist/esm/core/index.d.mts +9 -0
- package/dist/esm/core/index.mjs +9 -0
- package/dist/esm/core/json.d.mts +15 -0
- package/dist/esm/core/json.mjs +19 -0
- package/dist/esm/core/logging/exports.d.mts +18 -0
- package/dist/esm/core/logging/exports.mjs +9 -0
- package/dist/esm/core/logging/index.d.mts +1 -0
- package/dist/esm/core/logging/index.mjs +1 -0
- package/dist/esm/core/logging/logger.d.mts +126 -0
- package/dist/esm/core/logging/logger.mjs +138 -0
- package/dist/esm/core/requestBody.d.mts +12 -0
- package/dist/esm/core/requestBody.mjs +23 -0
- package/dist/esm/core/runtime/index.d.mts +1 -0
- package/dist/esm/core/runtime/index.mjs +1 -0
- package/dist/esm/core/runtime/runtime.d.mts +28 -0
- package/dist/esm/core/runtime/runtime.mjs +172 -0
- package/dist/esm/core/schemas/Schema.d.mts +88 -0
- package/dist/esm/core/schemas/Schema.mjs +22 -0
- package/dist/esm/core/schemas/builders/bigint/bigint.d.mts +2 -0
- package/dist/esm/core/schemas/builders/bigint/bigint.mjs +50 -0
- package/dist/esm/core/schemas/builders/bigint/index.d.mts +1 -0
- package/dist/esm/core/schemas/builders/bigint/index.mjs +1 -0
- package/dist/esm/core/schemas/builders/date/date.d.mts +2 -0
- package/dist/esm/core/schemas/builders/date/date.mjs +59 -0
- package/dist/esm/core/schemas/builders/date/index.d.mts +1 -0
- package/dist/esm/core/schemas/builders/date/index.mjs +1 -0
- package/dist/esm/core/schemas/builders/enum/enum.d.mts +3 -0
- package/dist/esm/core/schemas/builders/enum/enum.mjs +41 -0
- package/dist/esm/core/schemas/builders/enum/index.d.mts +1 -0
- package/dist/esm/core/schemas/builders/enum/index.mjs +1 -0
- package/dist/esm/core/schemas/builders/index.d.mts +14 -0
- package/dist/esm/core/schemas/builders/index.mjs +14 -0
- package/dist/esm/core/schemas/builders/lazy/index.d.mts +3 -0
- package/dist/esm/core/schemas/builders/lazy/index.mjs +2 -0
- package/dist/esm/core/schemas/builders/lazy/lazy.d.mts +5 -0
- package/dist/esm/core/schemas/builders/lazy/lazy.mjs +19 -0
- package/dist/esm/core/schemas/builders/lazy/lazyObject.d.mts +3 -0
- package/dist/esm/core/schemas/builders/lazy/lazyObject.mjs +8 -0
- package/dist/esm/core/schemas/builders/list/index.d.mts +1 -0
- package/dist/esm/core/schemas/builders/list/index.mjs +1 -0
- package/dist/esm/core/schemas/builders/list/list.d.mts +2 -0
- package/dist/esm/core/schemas/builders/list/list.mjs +46 -0
- package/dist/esm/core/schemas/builders/literals/booleanLiteral.d.mts +2 -0
- package/dist/esm/core/schemas/builders/literals/booleanLiteral.mjs +25 -0
- package/dist/esm/core/schemas/builders/literals/index.d.mts +2 -0
- package/dist/esm/core/schemas/builders/literals/index.mjs +2 -0
- package/dist/esm/core/schemas/builders/literals/stringLiteral.d.mts +2 -0
- package/dist/esm/core/schemas/builders/literals/stringLiteral.mjs +25 -0
- package/dist/esm/core/schemas/builders/object/index.d.mts +6 -0
- package/dist/esm/core/schemas/builders/object/index.mjs +3 -0
- package/dist/esm/core/schemas/builders/object/object.d.mts +3 -0
- package/dist/esm/core/schemas/builders/object/object.mjs +350 -0
- package/dist/esm/core/schemas/builders/object/objectWithoutOptionalProperties.d.mts +6 -0
- package/dist/esm/core/schemas/builders/object/objectWithoutOptionalProperties.mjs +4 -0
- package/dist/esm/core/schemas/builders/object/property.d.mts +8 -0
- package/dist/esm/core/schemas/builders/object/property.mjs +11 -0
- package/dist/esm/core/schemas/builders/object/types.d.mts +31 -0
- package/dist/esm/core/schemas/builders/object/types.mjs +1 -0
- package/dist/esm/core/schemas/builders/object-like/getObjectLikeUtils.d.mts +9 -0
- package/dist/esm/core/schemas/builders/object-like/getObjectLikeUtils.mjs +56 -0
- package/dist/esm/core/schemas/builders/object-like/index.d.mts +2 -0
- package/dist/esm/core/schemas/builders/object-like/index.mjs +1 -0
- package/dist/esm/core/schemas/builders/object-like/types.d.mts +7 -0
- package/dist/esm/core/schemas/builders/object-like/types.mjs +1 -0
- package/dist/esm/core/schemas/builders/primitives/any.d.mts +2 -0
- package/dist/esm/core/schemas/builders/primitives/any.mjs +6 -0
- package/dist/esm/core/schemas/builders/primitives/boolean.d.mts +2 -0
- package/dist/esm/core/schemas/builders/primitives/boolean.mjs +22 -0
- package/dist/esm/core/schemas/builders/primitives/index.d.mts +6 -0
- package/dist/esm/core/schemas/builders/primitives/index.mjs +6 -0
- package/dist/esm/core/schemas/builders/primitives/never.d.mts +2 -0
- package/dist/esm/core/schemas/builders/primitives/never.mjs +11 -0
- package/dist/esm/core/schemas/builders/primitives/number.d.mts +2 -0
- package/dist/esm/core/schemas/builders/primitives/number.mjs +22 -0
- package/dist/esm/core/schemas/builders/primitives/string.d.mts +2 -0
- package/dist/esm/core/schemas/builders/primitives/string.mjs +22 -0
- package/dist/esm/core/schemas/builders/primitives/unknown.d.mts +2 -0
- package/dist/esm/core/schemas/builders/primitives/unknown.mjs +3 -0
- package/dist/esm/core/schemas/builders/record/index.d.mts +2 -0
- package/dist/esm/core/schemas/builders/record/index.mjs +1 -0
- package/dist/esm/core/schemas/builders/record/record.d.mts +4 -0
- package/dist/esm/core/schemas/builders/record/record.mjs +127 -0
- package/dist/esm/core/schemas/builders/record/types.d.mts +6 -0
- package/dist/esm/core/schemas/builders/record/types.mjs +1 -0
- package/dist/esm/core/schemas/builders/schema-utils/JsonError.d.mts +5 -0
- package/dist/esm/core/schemas/builders/schema-utils/JsonError.mjs +9 -0
- package/dist/esm/core/schemas/builders/schema-utils/ParseError.d.mts +5 -0
- package/dist/esm/core/schemas/builders/schema-utils/ParseError.mjs +9 -0
- package/dist/esm/core/schemas/builders/schema-utils/getSchemaUtils.d.mts +21 -0
- package/dist/esm/core/schemas/builders/schema-utils/getSchemaUtils.mjs +138 -0
- package/dist/esm/core/schemas/builders/schema-utils/index.d.mts +4 -0
- package/dist/esm/core/schemas/builders/schema-utils/index.mjs +3 -0
- package/dist/esm/core/schemas/builders/schema-utils/stringifyValidationErrors.d.mts +2 -0
- package/dist/esm/core/schemas/builders/schema-utils/stringifyValidationErrors.mjs +6 -0
- package/dist/esm/core/schemas/builders/set/index.d.mts +1 -0
- package/dist/esm/core/schemas/builders/set/index.mjs +1 -0
- package/dist/esm/core/schemas/builders/set/set.d.mts +2 -0
- package/dist/esm/core/schemas/builders/set/set.mjs +40 -0
- package/dist/esm/core/schemas/builders/undiscriminated-union/index.d.mts +2 -0
- package/dist/esm/core/schemas/builders/undiscriminated-union/index.mjs +1 -0
- package/dist/esm/core/schemas/builders/undiscriminated-union/types.d.mts +4 -0
- package/dist/esm/core/schemas/builders/undiscriminated-union/types.mjs +1 -0
- package/dist/esm/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.d.mts +3 -0
- package/dist/esm/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.mjs +36 -0
- package/dist/esm/core/schemas/builders/union/discriminant.d.mts +5 -0
- package/dist/esm/core/schemas/builders/union/discriminant.mjs +6 -0
- package/dist/esm/core/schemas/builders/union/index.d.mts +4 -0
- package/dist/esm/core/schemas/builders/union/index.mjs +2 -0
- package/dist/esm/core/schemas/builders/union/types.d.mts +13 -0
- package/dist/esm/core/schemas/builders/union/types.mjs +1 -0
- package/dist/esm/core/schemas/builders/union/union.d.mts +4 -0
- package/dist/esm/core/schemas/builders/union/union.mjs +123 -0
- package/dist/esm/core/schemas/index.d.mts +2 -0
- package/dist/esm/core/schemas/index.mjs +1 -0
- package/dist/esm/core/schemas/utils/MaybePromise.d.mts +1 -0
- package/dist/esm/core/schemas/utils/MaybePromise.mjs +1 -0
- package/dist/esm/core/schemas/utils/addQuestionMarksToNullableProperties.d.mts +7 -0
- package/dist/esm/core/schemas/utils/addQuestionMarksToNullableProperties.mjs +1 -0
- package/dist/esm/core/schemas/utils/createIdentitySchemaCreator.d.mts +2 -0
- package/dist/esm/core/schemas/utils/createIdentitySchemaCreator.mjs +12 -0
- package/dist/esm/core/schemas/utils/entries.d.mts +1 -0
- package/dist/esm/core/schemas/utils/entries.mjs +3 -0
- package/dist/esm/core/schemas/utils/filterObject.d.mts +1 -0
- package/dist/esm/core/schemas/utils/filterObject.mjs +10 -0
- package/dist/esm/core/schemas/utils/getErrorMessageForIncorrectType.d.mts +1 -0
- package/dist/esm/core/schemas/utils/getErrorMessageForIncorrectType.mjs +24 -0
- package/dist/esm/core/schemas/utils/isPlainObject.d.mts +1 -0
- package/dist/esm/core/schemas/utils/isPlainObject.mjs +12 -0
- package/dist/esm/core/schemas/utils/keys.d.mts +1 -0
- package/dist/esm/core/schemas/utils/keys.mjs +3 -0
- package/dist/esm/core/schemas/utils/maybeSkipValidation.d.mts +2 -0
- package/dist/esm/core/schemas/utils/maybeSkipValidation.mjs +24 -0
- package/dist/esm/core/schemas/utils/partition.d.mts +1 -0
- package/dist/esm/core/schemas/utils/partition.mjs +12 -0
- package/dist/esm/core/url/QueryStringBuilder.d.mts +47 -0
- package/dist/esm/core/url/QueryStringBuilder.mjs +80 -0
- package/dist/esm/core/url/encodePathParam.d.mts +3 -0
- package/dist/esm/core/url/encodePathParam.mjs +24 -0
- package/dist/esm/core/url/index.d.mts +4 -0
- package/dist/esm/core/url/index.mjs +4 -0
- package/dist/esm/core/url/join.d.mts +1 -0
- package/dist/esm/core/url/join.mjs +65 -0
- package/dist/esm/core/url/qs.d.mts +7 -0
- package/dist/esm/core/url/qs.mjs +73 -0
- package/dist/esm/environments.d.mts +4 -0
- package/dist/esm/environments.mjs +4 -0
- package/dist/esm/errors/DecisionsError.d.mts +15 -0
- package/dist/esm/errors/DecisionsError.mjs +49 -0
- package/dist/esm/errors/DecisionsTimeoutError.d.mts +6 -0
- package/dist/esm/errors/DecisionsTimeoutError.mjs +15 -0
- package/dist/esm/errors/handleNonStatusCodeError.d.mts +2 -0
- package/dist/esm/errors/handleNonStatusCodeError.mjs +32 -0
- package/dist/esm/errors/index.d.mts +2 -0
- package/dist/esm/errors/index.mjs +2 -0
- package/dist/esm/exports.d.mts +1 -0
- package/dist/esm/exports.mjs +1 -0
- package/dist/esm/index.d.mts +7 -0
- package/dist/esm/index.mjs +6 -0
- package/dist/esm/serialization/index.d.mts +2 -0
- package/dist/esm/serialization/index.mjs +2 -0
- package/dist/esm/serialization/resources/decisions/client/index.d.mts +1 -0
- package/dist/esm/serialization/resources/decisions/client/index.mjs +1 -0
- package/dist/esm/serialization/resources/decisions/client/requests/InputTokensRequest.d.mts +12 -0
- package/dist/esm/serialization/resources/decisions/client/requests/InputTokensRequest.mjs +8 -0
- package/dist/esm/serialization/resources/decisions/client/requests/index.d.mts +1 -0
- package/dist/esm/serialization/resources/decisions/client/requests/index.mjs +1 -0
- package/dist/esm/serialization/resources/decisions/index.d.mts +1 -0
- package/dist/esm/serialization/resources/decisions/index.mjs +1 -0
- package/dist/esm/serialization/resources/index.d.mts +2 -0
- package/dist/esm/serialization/resources/index.mjs +2 -0
- package/dist/esm/serialization/types/Answer.d.mts +23 -0
- package/dist/esm/serialization/types/Answer.mjs +17 -0
- package/dist/esm/serialization/types/Answers.d.mts +10 -0
- package/dist/esm/serialization/types/Answers.mjs +4 -0
- package/dist/esm/serialization/types/ChoiceAnswer.d.mts +11 -0
- package/dist/esm/serialization/types/ChoiceAnswer.mjs +7 -0
- package/dist/esm/serialization/types/ChoiceQuestion.d.mts +11 -0
- package/dist/esm/serialization/types/ChoiceQuestion.mjs +7 -0
- package/dist/esm/serialization/types/Criterion.d.mts +10 -0
- package/dist/esm/serialization/types/Criterion.mjs +6 -0
- package/dist/esm/serialization/types/DecisionsRequest.d.mts +11 -0
- package/dist/esm/serialization/types/DecisionsRequest.mjs +7 -0
- package/dist/esm/serialization/types/DecisionsResponse.d.mts +13 -0
- package/dist/esm/serialization/types/DecisionsResponse.mjs +9 -0
- package/dist/esm/serialization/types/ErrorCode.d.mts +7 -0
- package/dist/esm/serialization/types/ErrorCode.mjs +18 -0
- package/dist/esm/serialization/types/ErrorType.d.mts +7 -0
- package/dist/esm/serialization/types/ErrorType.mjs +3 -0
- package/dist/esm/serialization/types/Error_.d.mts +15 -0
- package/dist/esm/serialization/types/Error_.mjs +11 -0
- package/dist/esm/serialization/types/GatewayError.d.mts +10 -0
- package/dist/esm/serialization/types/GatewayError.mjs +6 -0
- package/dist/esm/serialization/types/InputTokensResponse.d.mts +9 -0
- package/dist/esm/serialization/types/InputTokensResponse.mjs +5 -0
- package/dist/esm/serialization/types/Moment.d.mts +11 -0
- package/dist/esm/serialization/types/Moment.mjs +7 -0
- package/dist/esm/serialization/types/MomentAnswer.d.mts +10 -0
- package/dist/esm/serialization/types/MomentAnswer.mjs +6 -0
- package/dist/esm/serialization/types/MomentQuestion.d.mts +9 -0
- package/dist/esm/serialization/types/MomentQuestion.mjs +5 -0
- package/dist/esm/serialization/types/NoulAnswer.d.mts +9 -0
- package/dist/esm/serialization/types/NoulAnswer.mjs +5 -0
- package/dist/esm/serialization/types/NoulCriteria.d.mts +10 -0
- package/dist/esm/serialization/types/NoulCriteria.mjs +6 -0
- package/dist/esm/serialization/types/NoulQuestion.d.mts +11 -0
- package/dist/esm/serialization/types/NoulQuestion.mjs +7 -0
- package/dist/esm/serialization/types/Question.d.mts +23 -0
- package/dist/esm/serialization/types/Question.mjs +17 -0
- package/dist/esm/serialization/types/Questions.d.mts +10 -0
- package/dist/esm/serialization/types/Questions.mjs +4 -0
- package/dist/esm/serialization/types/Received.d.mts +9 -0
- package/dist/esm/serialization/types/Received.mjs +5 -0
- package/dist/esm/serialization/types/Run.d.mts +18 -0
- package/dist/esm/serialization/types/Run.mjs +14 -0
- package/dist/esm/serialization/types/RunReceived.d.mts +10 -0
- package/dist/esm/serialization/types/RunReceived.mjs +6 -0
- package/dist/esm/serialization/types/RunStatus.d.mts +7 -0
- package/dist/esm/serialization/types/RunStatus.mjs +3 -0
- package/dist/esm/serialization/types/RunSummary.d.mts +16 -0
- package/dist/esm/serialization/types/RunSummary.mjs +12 -0
- package/dist/esm/serialization/types/RunsPage.d.mts +11 -0
- package/dist/esm/serialization/types/RunsPage.mjs +7 -0
- package/dist/esm/serialization/types/ScoreAnswer.d.mts +12 -0
- package/dist/esm/serialization/types/ScoreAnswer.mjs +8 -0
- package/dist/esm/serialization/types/ScoreQuestion.d.mts +10 -0
- package/dist/esm/serialization/types/ScoreQuestion.mjs +6 -0
- package/dist/esm/serialization/types/index.d.mts +28 -0
- package/dist/esm/serialization/types/index.mjs +28 -0
- package/dist/esm/version.d.mts +1 -0
- package/dist/esm/version.mjs +1 -0
- package/package.json +115 -5
- package/reference.md +327 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type { Uploadable } from "../core/file/index.mjs";
|
|
2
|
+
import { type DownmixStrategy } from "./downmix.mjs";
|
|
3
|
+
declare const SPLITS: readonly ["even", "fixed"];
|
|
4
|
+
export type ChunkSplit = (typeof SPLITS)[number];
|
|
5
|
+
/** One chunk of a longer recording, a complete audio file to send to the Decisions API on its own. */
|
|
6
|
+
export interface AudioChunk {
|
|
7
|
+
/** Position of the chunk in the recording, starting at 0. */
|
|
8
|
+
readonly index: number;
|
|
9
|
+
/**
|
|
10
|
+
* Where the chunk starts in the recording, in milliseconds, rounded to the nearest millisecond.
|
|
11
|
+
* The first chunk of an MP3 file can start a few tens of milliseconds before 0.
|
|
12
|
+
*/
|
|
13
|
+
readonly startMs: number;
|
|
14
|
+
/** Where the chunk ends in the recording, in milliseconds, rounded to the nearest millisecond. */
|
|
15
|
+
readonly endMs: number;
|
|
16
|
+
/** The chunk as a file in the recording's format, after any mixdown `downmixStrategy` asks for. */
|
|
17
|
+
readonly data: Uint8Array;
|
|
18
|
+
}
|
|
19
|
+
export declare namespace iterAudioChunks {
|
|
20
|
+
interface Options {
|
|
21
|
+
/**
|
|
22
|
+
* The longest a chunk can be, in milliseconds, from 1 to 300000. A WAV chunk must also be at
|
|
23
|
+
* most 24,000,000 bytes, which leaves room for the rest of its request within the API's limit
|
|
24
|
+
* of 25,000,000 bytes. 5 minutes of WAV fits only at just under 80,000 bytes per second, and
|
|
25
|
+
* always fits for mono or stereo under "mix". With "even", a WAV file that does not fit is cut
|
|
26
|
+
* into shorter chunks that do. With "fixed", it throws, and 16-bit stereo that is not mixed
|
|
27
|
+
* down needs a `maxChunkMs` of at most 136054 at 44.1 kHz and 124999 at 48 kHz.
|
|
28
|
+
*/
|
|
29
|
+
maxChunkMs: number;
|
|
30
|
+
/** Where in the recording to start, in milliseconds. Defaults to the start of the recording. */
|
|
31
|
+
startMs?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Where in the recording to stop, in milliseconds, no later than the recording's duration.
|
|
34
|
+
* Defaults to the end of the recording.
|
|
35
|
+
*/
|
|
36
|
+
endMs?: number;
|
|
37
|
+
/**
|
|
38
|
+
* "even" for the fewest chunks of equal length, or "fixed" for chunks of `maxChunkMs` with a
|
|
39
|
+
* shorter last chunk. Defaults to "even".
|
|
40
|
+
*/
|
|
41
|
+
split?: ChunkSplit;
|
|
42
|
+
/**
|
|
43
|
+
* How a WAV file is mixed down before it is cut. Audio above 16 kHz is resampled to 16 kHz
|
|
44
|
+
* with the filter the API uses, and audio at 16 kHz or below keeps its rate. Resampled audio
|
|
45
|
+
* is written as 32-bit floating point, the format the API converts every file to, so loud
|
|
46
|
+
* audio cannot clip.
|
|
47
|
+
*
|
|
48
|
+
* 1. "mix", the default, mixes two channels into one the way the API does, adding them at
|
|
49
|
+
* -3 dB each, so the model hears the same audio as it would from the original file. A file
|
|
50
|
+
* that this would not make smaller, such as 16-bit mono at 16 kHz, is cut as it is, and so
|
|
51
|
+
* is audio with more than two channels, or two channels whose header places them anywhere
|
|
52
|
+
* but front left and front right, because the API weighs those channels by the speaker
|
|
53
|
+
* positions the header declares.
|
|
54
|
+
* 2. "first_channel" keeps only the first channel of a file with more than one, so the model
|
|
55
|
+
* hears only that channel. The channel is copied exactly in the recording's sample format
|
|
56
|
+
* when that is no larger than resampling it, as it is at 16 kHz or below for every sample
|
|
57
|
+
* format but 64-bit floating point. Use it when that channel holds the speaker to judge.
|
|
58
|
+
* Mono audio is treated as by "mix".
|
|
59
|
+
* 3. "none" cuts the audio as it is.
|
|
60
|
+
*/
|
|
61
|
+
downmixStrategy?: DownmixStrategy;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** A chunk's place in the recording, with its data left to be copied when it is needed. */
|
|
65
|
+
interface PlannedChunk {
|
|
66
|
+
readonly index: number;
|
|
67
|
+
readonly startMs: number;
|
|
68
|
+
readonly endMs: number;
|
|
69
|
+
readonly build: () => Uint8Array;
|
|
70
|
+
}
|
|
71
|
+
/** A recording's chunks, with the filename and content type its upload would carry. */
|
|
72
|
+
export interface PlannedRecording {
|
|
73
|
+
readonly filename: string | undefined;
|
|
74
|
+
readonly contentType: string | undefined;
|
|
75
|
+
readonly chunks: Iterable<PlannedChunk>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Splits a recording, or part of one, into chunks short enough for the Decisions API.
|
|
79
|
+
*
|
|
80
|
+
* `maxChunkMs` is the longest a chunk can be, and `split` decides how the recording is divided:
|
|
81
|
+
*
|
|
82
|
+
* 1. "even", the default, cuts the fewest chunks that fit, of equal length, so that the last chunk
|
|
83
|
+
* is not a short remainder: 10 minutes and 1 second at a `maxChunkMs` of 300000 is cut into 3
|
|
84
|
+
* chunks of about 200 seconds.
|
|
85
|
+
* 2. "fixed" makes every chunk `maxChunkMs` long except the last, which holds what remains: the
|
|
86
|
+
* same recording is cut into 2 chunks of 5 minutes and 1 of 1 second. The last chunk is billed
|
|
87
|
+
* for its context and questions like any other, however short it is. Use it when chunks must be
|
|
88
|
+
* the same length across recordings.
|
|
89
|
+
*
|
|
90
|
+
* No chunk is empty. Cuts fall where the format allows, as described below, so `startMs` and
|
|
91
|
+
* `endMs` on each chunk give where it actually starts and ends.
|
|
92
|
+
*
|
|
93
|
+
* The model hears audio at 16 kHz in one channel: the API resamples and mixes down every file
|
|
94
|
+
* before the model hears it. A WAV file is mixed down the same way before it is cut, by default, so
|
|
95
|
+
* that the chunks are smaller to upload while the model hears the same audio. `downmixStrategy`
|
|
96
|
+
* describes how. MP3 files are cut as they are, because they are already compressed.
|
|
97
|
+
*
|
|
98
|
+
* The whole recording is read into memory, mixed down and checked before the first chunk is
|
|
99
|
+
* produced, so that a file that cannot be split is rejected before any chunk is. The options are
|
|
100
|
+
* checked by this call, and the file when iteration starts, so errors about the file are thrown by
|
|
101
|
+
* the first `next()`. The mixdown runs on the calling thread, taking several seconds for an hour of
|
|
102
|
+
* audio above 16 kHz, and pauses regularly to let other work run. Each chunk's `data` is a copy, made
|
|
103
|
+
* as the chunk is produced, so keeping every chunk holds the recording in memory twice.
|
|
104
|
+
*
|
|
105
|
+
* Apart from the WAV mixdown `downmixStrategy` asks for, the audio is copied as it is, never decoded
|
|
106
|
+
* or re-encoded, so cuts fall where the format allows:
|
|
107
|
+
*
|
|
108
|
+
* 1. A WAV file is cut between samples, after the mixdown. With "fixed", a cut can fall up to one
|
|
109
|
+
* sample before `startMs` plus a whole multiple of `maxChunkMs`, so the cuts stay on that grid.
|
|
110
|
+
* Each chunk is a new WAV file in the sample format of the mixed-down audio, holding only its
|
|
111
|
+
* audio; other chunks in the file, such as metadata, are left out.
|
|
112
|
+
* 2. An MP3 file is cut between frames, which last 24 to 72 ms depending on the sample rate, so
|
|
113
|
+
* chunks can differ in length by a frame, and a "fixed" chunk can be up to one frame shorter
|
|
114
|
+
* than `maxChunkMs`. `startMs` and `endMs` move to the nearest frame boundary. A frame can store
|
|
115
|
+
* part of its audio data in the frames before it, and its sound continues from the frame before,
|
|
116
|
+
* so each chunk also starts with the frames its first new frame needs to decode exactly. That is
|
|
117
|
+
* usually a few frames, and up to about 2 seconds at the lowest bitrates. Those frames count
|
|
118
|
+
* toward `maxChunkMs` and repeat the end of the previous chunk, or start before `startMs`. Each
|
|
119
|
+
* chunk holds only the recording's frames; tags, and the header frame that states the whole
|
|
120
|
+
* file's length, are left out. When that header frame has a LAME tag, as files from LAME and
|
|
121
|
+
* ffmpeg do, it states the silence the encoder added at each end, which players skip. Times are
|
|
122
|
+
* then measured from where a player starts the whole file, so the first chunk starts before 0,
|
|
123
|
+
* by about 25 ms for a typical 44.1 kHz file, and the last ends where the player stops.
|
|
124
|
+
*
|
|
125
|
+
* @param file The recording, an MP3 or WAV file, in any form `create` accepts. MP3 files of MPEG-1,
|
|
126
|
+
* 2 and 2.5 layer III are supported, except free format. WAV files of integer PCM (8, 16, 24 or
|
|
127
|
+
* 32-bit) and floating point (32 or 64-bit) are supported, with either the basic or the extensible
|
|
128
|
+
* WAV header. A stream is read from where it is to its end. `{ path }` needs file system access,
|
|
129
|
+
* which browsers do not have.
|
|
130
|
+
* @param options How to cut the recording.
|
|
131
|
+
* @returns The chunks in order. Their times are measured from the start of the recording, not from
|
|
132
|
+
* `startMs`.
|
|
133
|
+
*
|
|
134
|
+
* @throws {TypeError} From this call, if `maxChunkMs`, `startMs` or `endMs` is not a safe integer, or
|
|
135
|
+
* `file` is a string, which is not read as a path.
|
|
136
|
+
* @throws {RangeError} From this call, if `split` is not "even" or "fixed", `downmixStrategy` is not
|
|
137
|
+
* "mix", "first_channel" or "none", `maxChunkMs` is out of range, or `startMs` and `endMs` do not
|
|
138
|
+
* select a range. From iteration, if `startMs` and `endMs` do
|
|
139
|
+
* not select audio within the recording, `maxChunkMs` is too long with "fixed" for a WAV chunk to
|
|
140
|
+
* fit the API's size limit, or too short for an MP3 chunk to hold a new frame and the frames it
|
|
141
|
+
* needs.
|
|
142
|
+
* @throws {UnsupportedAudioError} From iteration, if the recording is empty or not a file this helper supports, such
|
|
143
|
+
* as a compressed WAV or RF64 file. Any damage to an MP3 file is found before the first chunk, so no
|
|
144
|
+
* chunk is produced from a file that cannot be read to the end.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* import { iterAudioChunks } from "@humeai/audio-decisions/audio-helpers";
|
|
148
|
+
*
|
|
149
|
+
* for await (const chunk of iterAudioChunks({ path: "call.wav" }, { maxChunkMs: 60_000 })) {
|
|
150
|
+
* console.log(chunk.index, chunk.startMs, chunk.endMs, chunk.data.length);
|
|
151
|
+
* }
|
|
152
|
+
*/
|
|
153
|
+
export declare function iterAudioChunks(file: Uploadable, options: iterAudioChunks.Options): AsyncGenerator<AudioChunk, void, undefined>;
|
|
154
|
+
/**
|
|
155
|
+
* Checks `options` and `file`, and returns a function that reads the file, mixes it down and plans
|
|
156
|
+
* the chunks `iterAudioChunks` gives, without copying any chunk's data. The function rejects with a
|
|
157
|
+
* DecisionsError if `signal` aborts during the mixdown.
|
|
158
|
+
*/
|
|
159
|
+
export declare function prepareChunks(file: Uploadable, options: iterAudioChunks.Options): (signal?: AbortSignal) => Promise<PlannedRecording>;
|
|
160
|
+
export {};
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
// Maintained by hand and listed in .fernignore, so SDK regeneration leaves it in place.
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
12
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
13
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
14
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
15
|
+
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
16
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
17
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
18
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
19
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
20
|
+
function fulfill(value) { resume("next", value); }
|
|
21
|
+
function reject(value) { resume("throw", value); }
|
|
22
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
23
|
+
};
|
|
24
|
+
import { checkChoice, checkInteger } from "./checks.mjs";
|
|
25
|
+
import { checkDownmixStrategy, downmixWav } from "./downmix.mjs";
|
|
26
|
+
import { UnsupportedAudioError } from "./errors.mjs";
|
|
27
|
+
import { checkFile, readFile } from "./files.mjs";
|
|
28
|
+
import { ceilDiv, floorDiv, roundDiv } from "./integers.mjs";
|
|
29
|
+
import { framesNeededBefore, isMp3, mp3Chunk, parseMp3 } from "./mp3.mjs";
|
|
30
|
+
import { isWav, parseWav, wavChunk } from "./wav.mjs";
|
|
31
|
+
// The Decisions API accepts audio up to 5 minutes long.
|
|
32
|
+
const MAX_CHUNK_MS = 300000;
|
|
33
|
+
// The API accepts a request body of up to this many bytes, its JSON part and multipart headers included.
|
|
34
|
+
const MAX_REQUEST_BYTES = 25000000;
|
|
35
|
+
// The rest is left for the JSON part and multipart headers, so a chunk this size is accepted with any
|
|
36
|
+
// common request.
|
|
37
|
+
const MAX_CHUNK_BYTES = 24000000;
|
|
38
|
+
const SPLITS = ["even", "fixed"];
|
|
39
|
+
/**
|
|
40
|
+
* Splits a recording, or part of one, into chunks short enough for the Decisions API.
|
|
41
|
+
*
|
|
42
|
+
* `maxChunkMs` is the longest a chunk can be, and `split` decides how the recording is divided:
|
|
43
|
+
*
|
|
44
|
+
* 1. "even", the default, cuts the fewest chunks that fit, of equal length, so that the last chunk
|
|
45
|
+
* is not a short remainder: 10 minutes and 1 second at a `maxChunkMs` of 300000 is cut into 3
|
|
46
|
+
* chunks of about 200 seconds.
|
|
47
|
+
* 2. "fixed" makes every chunk `maxChunkMs` long except the last, which holds what remains: the
|
|
48
|
+
* same recording is cut into 2 chunks of 5 minutes and 1 of 1 second. The last chunk is billed
|
|
49
|
+
* for its context and questions like any other, however short it is. Use it when chunks must be
|
|
50
|
+
* the same length across recordings.
|
|
51
|
+
*
|
|
52
|
+
* No chunk is empty. Cuts fall where the format allows, as described below, so `startMs` and
|
|
53
|
+
* `endMs` on each chunk give where it actually starts and ends.
|
|
54
|
+
*
|
|
55
|
+
* The model hears audio at 16 kHz in one channel: the API resamples and mixes down every file
|
|
56
|
+
* before the model hears it. A WAV file is mixed down the same way before it is cut, by default, so
|
|
57
|
+
* that the chunks are smaller to upload while the model hears the same audio. `downmixStrategy`
|
|
58
|
+
* describes how. MP3 files are cut as they are, because they are already compressed.
|
|
59
|
+
*
|
|
60
|
+
* The whole recording is read into memory, mixed down and checked before the first chunk is
|
|
61
|
+
* produced, so that a file that cannot be split is rejected before any chunk is. The options are
|
|
62
|
+
* checked by this call, and the file when iteration starts, so errors about the file are thrown by
|
|
63
|
+
* the first `next()`. The mixdown runs on the calling thread, taking several seconds for an hour of
|
|
64
|
+
* audio above 16 kHz, and pauses regularly to let other work run. Each chunk's `data` is a copy, made
|
|
65
|
+
* as the chunk is produced, so keeping every chunk holds the recording in memory twice.
|
|
66
|
+
*
|
|
67
|
+
* Apart from the WAV mixdown `downmixStrategy` asks for, the audio is copied as it is, never decoded
|
|
68
|
+
* or re-encoded, so cuts fall where the format allows:
|
|
69
|
+
*
|
|
70
|
+
* 1. A WAV file is cut between samples, after the mixdown. With "fixed", a cut can fall up to one
|
|
71
|
+
* sample before `startMs` plus a whole multiple of `maxChunkMs`, so the cuts stay on that grid.
|
|
72
|
+
* Each chunk is a new WAV file in the sample format of the mixed-down audio, holding only its
|
|
73
|
+
* audio; other chunks in the file, such as metadata, are left out.
|
|
74
|
+
* 2. An MP3 file is cut between frames, which last 24 to 72 ms depending on the sample rate, so
|
|
75
|
+
* chunks can differ in length by a frame, and a "fixed" chunk can be up to one frame shorter
|
|
76
|
+
* than `maxChunkMs`. `startMs` and `endMs` move to the nearest frame boundary. A frame can store
|
|
77
|
+
* part of its audio data in the frames before it, and its sound continues from the frame before,
|
|
78
|
+
* so each chunk also starts with the frames its first new frame needs to decode exactly. That is
|
|
79
|
+
* usually a few frames, and up to about 2 seconds at the lowest bitrates. Those frames count
|
|
80
|
+
* toward `maxChunkMs` and repeat the end of the previous chunk, or start before `startMs`. Each
|
|
81
|
+
* chunk holds only the recording's frames; tags, and the header frame that states the whole
|
|
82
|
+
* file's length, are left out. When that header frame has a LAME tag, as files from LAME and
|
|
83
|
+
* ffmpeg do, it states the silence the encoder added at each end, which players skip. Times are
|
|
84
|
+
* then measured from where a player starts the whole file, so the first chunk starts before 0,
|
|
85
|
+
* by about 25 ms for a typical 44.1 kHz file, and the last ends where the player stops.
|
|
86
|
+
*
|
|
87
|
+
* @param file The recording, an MP3 or WAV file, in any form `create` accepts. MP3 files of MPEG-1,
|
|
88
|
+
* 2 and 2.5 layer III are supported, except free format. WAV files of integer PCM (8, 16, 24 or
|
|
89
|
+
* 32-bit) and floating point (32 or 64-bit) are supported, with either the basic or the extensible
|
|
90
|
+
* WAV header. A stream is read from where it is to its end. `{ path }` needs file system access,
|
|
91
|
+
* which browsers do not have.
|
|
92
|
+
* @param options How to cut the recording.
|
|
93
|
+
* @returns The chunks in order. Their times are measured from the start of the recording, not from
|
|
94
|
+
* `startMs`.
|
|
95
|
+
*
|
|
96
|
+
* @throws {TypeError} From this call, if `maxChunkMs`, `startMs` or `endMs` is not a safe integer, or
|
|
97
|
+
* `file` is a string, which is not read as a path.
|
|
98
|
+
* @throws {RangeError} From this call, if `split` is not "even" or "fixed", `downmixStrategy` is not
|
|
99
|
+
* "mix", "first_channel" or "none", `maxChunkMs` is out of range, or `startMs` and `endMs` do not
|
|
100
|
+
* select a range. From iteration, if `startMs` and `endMs` do
|
|
101
|
+
* not select audio within the recording, `maxChunkMs` is too long with "fixed" for a WAV chunk to
|
|
102
|
+
* fit the API's size limit, or too short for an MP3 chunk to hold a new frame and the frames it
|
|
103
|
+
* needs.
|
|
104
|
+
* @throws {UnsupportedAudioError} From iteration, if the recording is empty or not a file this helper supports, such
|
|
105
|
+
* as a compressed WAV or RF64 file. Any damage to an MP3 file is found before the first chunk, so no
|
|
106
|
+
* chunk is produced from a file that cannot be read to the end.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* import { iterAudioChunks } from "@humeai/audio-decisions/audio-helpers";
|
|
110
|
+
*
|
|
111
|
+
* for await (const chunk of iterAudioChunks({ path: "call.wav" }, { maxChunkMs: 60_000 })) {
|
|
112
|
+
* console.log(chunk.index, chunk.startMs, chunk.endMs, chunk.data.length);
|
|
113
|
+
* }
|
|
114
|
+
*/
|
|
115
|
+
export function iterAudioChunks(file, options) {
|
|
116
|
+
return produceChunks(prepareChunks(file, options));
|
|
117
|
+
}
|
|
118
|
+
function produceChunks(planRecording) {
|
|
119
|
+
return __asyncGenerator(this, arguments, function* produceChunks_1() {
|
|
120
|
+
for (const chunk of (yield __await(planRecording())).chunks) {
|
|
121
|
+
yield yield __await({ index: chunk.index, startMs: chunk.startMs, endMs: chunk.endMs, data: chunk.build() });
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Checks `options` and `file`, and returns a function that reads the file, mixes it down and plans
|
|
127
|
+
* the chunks `iterAudioChunks` gives, without copying any chunk's data. The function rejects with a
|
|
128
|
+
* DecisionsError if `signal` aborts during the mixdown.
|
|
129
|
+
*/
|
|
130
|
+
export function prepareChunks(file, options) {
|
|
131
|
+
const checked = checkChunkOptions(options);
|
|
132
|
+
checkFile(file);
|
|
133
|
+
// A generator that read the file itself would keep the recording in memory for the whole job, even
|
|
134
|
+
// after a WAV file is mixed down into a smaller copy.
|
|
135
|
+
return (signal) => __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
const { data, filename, contentType } = yield readFile(file);
|
|
137
|
+
return { filename, contentType, chunks: yield planAudioChunks(data, checked, signal) };
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function checkChunkOptions(options) {
|
|
141
|
+
const split = checkChoice("split", options.split === undefined ? "even" : options.split, SPLITS);
|
|
142
|
+
const downmixStrategy = checkDownmixStrategy(options.downmixStrategy);
|
|
143
|
+
const maxChunkMs = checkInteger("maxChunkMs", options.maxChunkMs);
|
|
144
|
+
if (maxChunkMs < 1 || maxChunkMs > MAX_CHUNK_MS) {
|
|
145
|
+
throw new RangeError(`maxChunkMs must be between 1 and ${MAX_CHUNK_MS}, got ${maxChunkMs}.`);
|
|
146
|
+
}
|
|
147
|
+
const startMs = options.startMs === undefined ? 0 : checkInteger("startMs", options.startMs);
|
|
148
|
+
if (startMs < 0) {
|
|
149
|
+
throw new RangeError(`startMs must not be negative, got ${startMs}.`);
|
|
150
|
+
}
|
|
151
|
+
const endMs = options.endMs === undefined ? undefined : checkInteger("endMs", options.endMs);
|
|
152
|
+
if (endMs !== undefined && endMs <= startMs) {
|
|
153
|
+
throw new RangeError(`endMs must be greater than startMs, got ${endMs}.`);
|
|
154
|
+
}
|
|
155
|
+
return { maxChunkMs, startMs, endMs, split, downmixStrategy };
|
|
156
|
+
}
|
|
157
|
+
function planAudioChunks(data, options, signal) {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
var _a;
|
|
160
|
+
if (isWav(data)) {
|
|
161
|
+
const wav = parseWav(data);
|
|
162
|
+
const mixed = (_a = (yield downmixWav(data, wav, options.downmixStrategy, signal))) !== null && _a !== void 0 ? _a : { data, wav };
|
|
163
|
+
return wavChunks(mixed.data, mixed.wav, options);
|
|
164
|
+
}
|
|
165
|
+
if (isMp3(data)) {
|
|
166
|
+
return mp3Chunks(data, parseMp3(data), options);
|
|
167
|
+
}
|
|
168
|
+
throw new UnsupportedAudioError("Unsupported audio format. Only MP3 and WAV files can be split into chunks.");
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/** The first and last positions of the range `startMs` and `endMs` select from `length` positions. */
|
|
172
|
+
function selectRange(length, msAt, positionAt, startMs, endMs) {
|
|
173
|
+
if (length === 0) {
|
|
174
|
+
throw new UnsupportedAudioError("The audio is empty.");
|
|
175
|
+
}
|
|
176
|
+
// The longest range allowed ends at the duration that the final chunk reports.
|
|
177
|
+
// A recording shorter than half a millisecond has a duration of 0 ms but still starts at 0.
|
|
178
|
+
const durationMs = msAt(length);
|
|
179
|
+
if (startMs > 0 && startMs >= durationMs) {
|
|
180
|
+
throw new RangeError(`startMs must be less than the recording's duration of ${durationMs} ms, got ${startMs}.`);
|
|
181
|
+
}
|
|
182
|
+
if (endMs !== undefined && endMs > durationMs) {
|
|
183
|
+
throw new RangeError(`endMs must not exceed the recording's duration of ${durationMs} ms, got ${endMs}.`);
|
|
184
|
+
}
|
|
185
|
+
// The duration is rounded to the millisecond, so it can fall short of the final position. An MP3
|
|
186
|
+
// recording can start and end partway through a frame, so its first and last frames are kept whole.
|
|
187
|
+
const first = startMs === 0 ? 0 : positionAt(startMs);
|
|
188
|
+
const last = endMs === undefined || endMs >= durationMs ? length : Math.min(positionAt(endMs), length);
|
|
189
|
+
return [first, last];
|
|
190
|
+
}
|
|
191
|
+
function wavChunks(data, wav, { maxChunkMs, startMs, endMs, split }) {
|
|
192
|
+
const msAt = (sample) => toMs(sample, wav.sampleRate);
|
|
193
|
+
const [first, last] = selectRange(wav.sampleCount, msAt, (ms) => toSample(ms, wav.sampleRate), startMs, endMs);
|
|
194
|
+
// When maxChunkMs is not a whole number of samples, a chunk can be up to one sample longer.
|
|
195
|
+
const longest = ceilDiv(maxChunkMs * wav.sampleRate, 1000);
|
|
196
|
+
const fitting = wavSamplesThatFit(wav);
|
|
197
|
+
let cuts;
|
|
198
|
+
if (split === "even") {
|
|
199
|
+
cuts = evenWavCuts(first, last, Math.min(longest, fitting));
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
checkWavSize(wav, Math.min(longest, last - first), fitting);
|
|
203
|
+
cuts = fixedWavCuts(wav, maxChunkMs, startMs, first, last);
|
|
204
|
+
}
|
|
205
|
+
return plan(cuts, msAt, (start, end) => wavChunk(data, wav, start, end));
|
|
206
|
+
}
|
|
207
|
+
function wavSamplesThatFit(wav) {
|
|
208
|
+
// An MP3 chunk needs no such limit: at the highest bitrate, 5 minutes of MP3 is about 12 MB.
|
|
209
|
+
// The header holds the RIFF, fmt and data chunk headers, and the data can need a padding byte.
|
|
210
|
+
const headerBytes = 28 + wav.fmt.length + 1;
|
|
211
|
+
return floorDiv(MAX_CHUNK_BYTES - headerBytes, wav.frameBytes);
|
|
212
|
+
}
|
|
213
|
+
function checkWavSize(wav, longest, fitting) {
|
|
214
|
+
if (longest <= fitting) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const fittingMs = floorDiv(fitting * 1000, wav.sampleRate);
|
|
218
|
+
throw new RangeError(`maxChunkMs must be at most ${fittingMs} for this WAV file with split="fixed", so that the request for` +
|
|
219
|
+
` each chunk fits within the API limit of ${MAX_REQUEST_BYTES.toLocaleString("en-US")} bytes.` +
|
|
220
|
+
` split="even" cuts shorter chunks that fit instead, and mono or stereo audio mixed down with` +
|
|
221
|
+
` downmixStrategy="mix" fits 5-minute chunks.`);
|
|
222
|
+
}
|
|
223
|
+
function mp3Chunks(data, mp3, { maxChunkMs, startMs, endMs, split }) {
|
|
224
|
+
const msAt = (frame) => mp3TimeMs(mp3, frame);
|
|
225
|
+
const [first, last] = selectRange(mp3.frameCount, msAt, (ms) => frameAt(mp3, ms), startMs, endMs);
|
|
226
|
+
// Rounding down keeps every chunk within maxChunkMs, so a maxChunkMs of 300000 stays within the
|
|
227
|
+
// API's limit.
|
|
228
|
+
const framesPerChunk = floorDiv(maxChunkMs * mp3.sampleRate, 1000 * mp3.samplesPerFrame);
|
|
229
|
+
const frameMs = framesMs(mp3, 1);
|
|
230
|
+
if (framesPerChunk === 0) {
|
|
231
|
+
throw new RangeError(`maxChunkMs must be at least ${frameMs} ms, the length of one frame of this MP3 file.`);
|
|
232
|
+
}
|
|
233
|
+
if (last <= first) {
|
|
234
|
+
throw new RangeError(`startMs and endMs must be at least ${frameMs} ms apart, the length of one frame of this MP3 file.`);
|
|
235
|
+
}
|
|
236
|
+
// A chunk that could hold only the frames needed before its first new frame would never advance.
|
|
237
|
+
// Filling fails only when this check does, which also rejects a maxChunkMs that happens to work
|
|
238
|
+
// for this range's cuts but not for every frame in it.
|
|
239
|
+
let neededBefore = 0;
|
|
240
|
+
for (let frame = first; frame < last; frame++) {
|
|
241
|
+
neededBefore = Math.max(neededBefore, framesNeededBefore(mp3, frame));
|
|
242
|
+
}
|
|
243
|
+
const filled = fillMp3Chunks(mp3, framesPerChunk, first, last);
|
|
244
|
+
if (filled === undefined || framesPerChunk <= neededBefore) {
|
|
245
|
+
throw new RangeError(`maxChunkMs must be at least ${framesMs(mp3, neededBefore + 1)} ms for this MP3 file. Its frames` +
|
|
246
|
+
` need up to ${neededBefore} frames before them to decode, and a chunk must hold those along with` +
|
|
247
|
+
" at least one new frame.");
|
|
248
|
+
}
|
|
249
|
+
const cuts = split === "even" ? evenMp3Cuts(mp3, filled, framesPerChunk, first, last) : filled;
|
|
250
|
+
return plan(cuts, msAt, (start, end) => mp3Chunk(data, mp3, start, end));
|
|
251
|
+
}
|
|
252
|
+
function frameAt(mp3, ms) {
|
|
253
|
+
// Times given by the caller are often ones a chunk reported, which are rounded to the
|
|
254
|
+
// millisecond, so they move to the nearest frame boundary rather than the one before.
|
|
255
|
+
return roundDiv(ms * mp3.sampleRate + 1000 * mp3.leadingSamples, 1000 * mp3.samplesPerFrame);
|
|
256
|
+
}
|
|
257
|
+
function framesMs(mp3, frames) {
|
|
258
|
+
return ceilDiv(frames * mp3.samplesPerFrame * 1000, mp3.sampleRate);
|
|
259
|
+
}
|
|
260
|
+
function mp3TimeMs(mp3, frame) {
|
|
261
|
+
// Times are measured from where a player starts the recording, after the samples the encoder and
|
|
262
|
+
// decoder add, so the first chunk can start before 0 ms. The player also stops before the
|
|
263
|
+
// samples added at the end.
|
|
264
|
+
return toMs(Math.min(frame * mp3.samplesPerFrame, mp3.endSample) - mp3.leadingSamples, mp3.sampleRate);
|
|
265
|
+
}
|
|
266
|
+
function evenMp3Cuts(mp3, filled, framesPerChunk, first, last) {
|
|
267
|
+
// Filling every chunk gives the fewest chunks but can leave a short last chunk. The shortest
|
|
268
|
+
// chunk length that needs no more chunks than that shares the frames out evenly instead.
|
|
269
|
+
let cuts = filled;
|
|
270
|
+
let low = 1;
|
|
271
|
+
let high = framesPerChunk;
|
|
272
|
+
while (low < high) {
|
|
273
|
+
const middle = Math.floor((low + high) / 2);
|
|
274
|
+
const shorter = fillMp3Chunks(mp3, middle, first, last);
|
|
275
|
+
if (shorter !== undefined && shorter.length <= cuts.length) {
|
|
276
|
+
cuts = shorter;
|
|
277
|
+
high = middle;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
low = middle + 1;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return cuts;
|
|
284
|
+
}
|
|
285
|
+
/** Cuts chunks of `framesPerChunk` frames, or undefined when a chunk cannot hold a new frame. */
|
|
286
|
+
function fillMp3Chunks(mp3, framesPerChunk, first, last) {
|
|
287
|
+
const cuts = [];
|
|
288
|
+
let next = first;
|
|
289
|
+
while (next < last) {
|
|
290
|
+
// Without the frames before it, the first new frame decodes wrongly. They repeat the end of
|
|
291
|
+
// the previous chunk.
|
|
292
|
+
const start = next - framesNeededBefore(mp3, next);
|
|
293
|
+
if (start + framesPerChunk <= next) {
|
|
294
|
+
return undefined;
|
|
295
|
+
}
|
|
296
|
+
const end = Math.min(start + framesPerChunk, last);
|
|
297
|
+
cuts.push([start, end]);
|
|
298
|
+
next = end;
|
|
299
|
+
}
|
|
300
|
+
return cuts;
|
|
301
|
+
}
|
|
302
|
+
function* evenWavCuts(first, last, longest) {
|
|
303
|
+
const length = last - first;
|
|
304
|
+
const count = ceilDiv(length, longest);
|
|
305
|
+
// Chunk i starts at first + floor(length * i / count). That product can pass
|
|
306
|
+
// Number.MAX_SAFE_INTEGER, so the cuts are stepped by the quotient and carry the remainder.
|
|
307
|
+
const step = floorDiv(length, count);
|
|
308
|
+
const extra = length - step * count;
|
|
309
|
+
let start = first;
|
|
310
|
+
let remainder = 0;
|
|
311
|
+
for (let index = 0; index < count; index++) {
|
|
312
|
+
let end = start + step;
|
|
313
|
+
remainder += extra;
|
|
314
|
+
if (remainder >= count) {
|
|
315
|
+
remainder -= count;
|
|
316
|
+
end += 1;
|
|
317
|
+
}
|
|
318
|
+
yield [start, end];
|
|
319
|
+
start = end;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function* fixedWavCuts(wav, maxChunkMs, startMs, first, last) {
|
|
323
|
+
let start = first;
|
|
324
|
+
let index = 0;
|
|
325
|
+
while (start < last) {
|
|
326
|
+
// Each cut is computed from startMs rather than from the previous cut, so rounding does not
|
|
327
|
+
// accumulate.
|
|
328
|
+
const end = Math.min(toSample(startMs + (index + 1) * maxChunkMs, wav.sampleRate), last);
|
|
329
|
+
yield [start, end];
|
|
330
|
+
index += 1;
|
|
331
|
+
start = end;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
function* plan(cuts, msAt, build) {
|
|
335
|
+
let index = 0;
|
|
336
|
+
for (const [start, end] of cuts) {
|
|
337
|
+
yield { index, startMs: msAt(start), endMs: msAt(end), build: () => build(start, end) };
|
|
338
|
+
index += 1;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
function toSample(ms, sampleRate) {
|
|
342
|
+
return floorDiv(ms * sampleRate, 1000);
|
|
343
|
+
}
|
|
344
|
+
function toMs(sample, sampleRate) {
|
|
345
|
+
return roundDiv(sample * 1000, sampleRate);
|
|
346
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type WavAudio } from "./wav.mjs";
|
|
2
|
+
declare const STRATEGIES: readonly ["mix", "first_channel", "none"];
|
|
3
|
+
/** How a WAV file is mixed down before it is sent: "mix", "first_channel", or "none" to send it as it is. */
|
|
4
|
+
export type DownmixStrategy = (typeof STRATEGIES)[number];
|
|
5
|
+
interface Downmixed {
|
|
6
|
+
readonly data: Uint8Array;
|
|
7
|
+
readonly wav: WavAudio;
|
|
8
|
+
}
|
|
9
|
+
export declare function checkDownmixStrategy(strategy?: unknown): DownmixStrategy;
|
|
10
|
+
/**
|
|
11
|
+
* The samples of `wav` mixed down by `strategy` into one channel, with a description of them, or
|
|
12
|
+
* undefined when the file is best sent as it is: the API would mix it the same way and converting it
|
|
13
|
+
* would not make it smaller. Resampled audio is at most MODEL_SAMPLE_RATE, in 32-bit floating point.
|
|
14
|
+
* Rejects with a DecisionsError once `signal` aborts.
|
|
15
|
+
*/
|
|
16
|
+
export declare function downmixWav(data: Uint8Array, wav: WavAudio, strategy: DownmixStrategy, signal?: AbortSignal): Promise<Downmixed | undefined>;
|
|
17
|
+
export {};
|