UNPKG

@burncloud/inference

Version:

Typescript client for the Hugging Face Inference Providers and Inference Endpoints

26 lines (25 loc) 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.automaticSpeechRecognition = automaticSpeechRecognition; const getInferenceProviderMapping_js_1 = require("../../lib/getInferenceProviderMapping.js"); const getProviderHelper_js_1 = require("../../lib/getProviderHelper.js"); const InferenceOutputError_js_1 = require("../../lib/InferenceOutputError.js"); const request_js_1 = require("../../utils/request.js"); /** * This task reads some audio input and outputs the said words within the audio files. * Recommended model (english language): facebook/wav2vec2-large-960h-lv60-self */ async function automaticSpeechRecognition(args, options) { const provider = await (0, getInferenceProviderMapping_js_1.resolveProvider)(args.provider, args.model, args.endpointUrl); const providerHelper = (0, getProviderHelper_js_1.getProviderHelper)(provider, "automatic-speech-recognition"); const payload = await providerHelper.preparePayloadAsync(args); const { data: res } = await (0, request_js_1.innerRequest)(payload, providerHelper, { ...options, task: "automatic-speech-recognition", }); const isValidOutput = typeof res?.text === "string"; if (!isValidOutput) { throw new InferenceOutputError_js_1.InferenceOutputError("Expected {text: string}"); } return providerHelper.getResponse(res); }