@langchain/community
Version:
Third-party integrations for LangChain.js
1 lines • 2.68 kB
Source Map (JSON)
{"version":3,"file":"sonix_audio.cjs","names":["BaseDocumentLoader","SonixSpeechRecognitionService","Document"],"sources":["../../../src/document_loaders/web/sonix_audio.ts"],"sourcesContent":["import { SonixSpeechRecognitionService } from \"sonix-speech-recognition\";\nimport { SpeechToTextRequest } from \"sonix-speech-recognition/lib/types.js\";\nimport { Document } from \"@langchain/core/documents\";\nimport { BaseDocumentLoader } from \"@langchain/core/document_loaders/base\";\n\n/**\n * A class that represents a document loader for transcribing audio files\n * using the Sonix Speech Recognition service.\n * @example\n * ```typescript\n * const loader = new SonixAudioTranscriptionLoader({\n * sonixAuthKey: \"SONIX_AUTH_KEY\",\n * request: {\n * audioFilePath: \"LOCAL_AUDIO_FILE_PATH\",\n * fileName: \"FILE_NAME\",\n * language: \"en\",\n * },\n * });\n * const docs = await loader.load();\n * ```\n */\nexport class SonixAudioTranscriptionLoader extends BaseDocumentLoader {\n private readonly sonixSpeechRecognitionService: SonixSpeechRecognitionService;\n\n private readonly speechToTextRequest: SpeechToTextRequest;\n\n constructor({\n sonixAuthKey,\n request: speechToTextRequest,\n }: {\n sonixAuthKey: string;\n request: SpeechToTextRequest;\n }) {\n super();\n this.sonixSpeechRecognitionService = new SonixSpeechRecognitionService(\n sonixAuthKey\n );\n this.speechToTextRequest = speechToTextRequest;\n }\n\n /**\n * Performs the speech-to-text transcription using the\n * SonixSpeechRecognitionService and returns the transcribed text as a\n * Document object.\n * @returns An array of Document objects containing the transcribed text.\n */\n async load(): Promise<Document[]> {\n const { text, status, error } =\n await this.sonixSpeechRecognitionService.speechToText(\n this.speechToTextRequest\n );\n\n if (status === \"failed\") {\n throw new Error(`Failed to transcribe audio file. Error: ${error}`);\n }\n\n const document = new Document({\n pageContent: text,\n metadata: {\n fileName: this.speechToTextRequest.fileName,\n },\n });\n\n return [document];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAqBA,IAAa,gCAAb,cAAmDA,0DAAmB;CACpE,AAAiB;CAEjB,AAAiB;CAEjB,YAAY,EACV,cACA,SAAS,qBAIV,EAAE;EACD,OAAO;EACP,KAAK,gCAAgC,IAAIC,uDACvC;EAEF,KAAK,sBAAsB;CAC5B;;;;;;;CAQD,MAAM,OAA4B;EAChC,MAAM,EAAE,MAAM,QAAQ,OAAO,GAC3B,MAAM,KAAK,8BAA8B,aACvC,KAAK,oBACN;AAEH,MAAI,WAAW,SACb,OAAM,IAAI,MAAM,CAAC,wCAAwC,EAAE,OAAO;EAGpE,MAAM,WAAW,IAAIC,oCAAS;GAC5B,aAAa;GACb,UAAU,EACR,UAAU,KAAK,oBAAoB,SACpC;EACF;AAED,SAAO,CAAC,QAAS;CAClB;AACF"}