1234567891011121314151617181920212223242526272829303132333435 |
- from langchain_community.document_loaders import AssemblyAIAudioTranscriptLoader
- from langchain_community.document_loaders.assemblyai import TranscriptFormat
- import assemblyai as aai
- from dotenv import load_dotenv, find_dotenv
- import os
- class Audio:
- audio_file_path = ""
- api_key = ""
- def __init__(self):
- load_dotenv(find_dotenv())
- self.api_key = os.getenv("AI_AUDIO_TRANSCRIPT_KEY")
- def transcribe(self, audio_file_path):
- # Validar que el archivo existe
- self.audio_file_path = audio_file_path
- config = aai.TranscriptionConfig(
- speaker_labels=True,
- auto_chapters=False,
- entity_detection=True,
- language_code=aai.LanguageCode.es,
- )
- loader = AssemblyAIAudioTranscriptLoader(
- file_path=self.audio_file_path,
- api_key=self.api_key,
- config=config,
- transcript_format=TranscriptFormat.TEXT,
- )
- docs = loader.load()
- return docs[0].page_content
|