{"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,sCAAAA,mBAAmB;CACpE;CAEA;CAEA,YAAY,EACV,cACA,SAAS,uBAIR;AACD,SAAO;AACP,OAAK,gCAAgC,IAAIC,yBAAAA,8BACvC,aACD;AACD,OAAK,sBAAsB;;;;;;;;CAS7B,MAAM,OAA4B;EAChC,MAAM,EAAE,MAAM,QAAQ,UACpB,MAAM,KAAK,8BAA8B,aACvC,KAAK,oBACN;AAEH,MAAI,WAAW,SACb,OAAM,IAAI,MAAM,2CAA2C,QAAQ;AAUrE,SAAO,CAPU,IAAIC,0BAAAA,SAAS;GAC5B,aAAa;GACb,UAAU,EACR,UAAU,KAAK,oBAAoB,UACpC;GACF,CAAC,CAEe"}