AssemblyAIAudioTranscriptLoaderAssemblyAI API를 사용하여 오디오 파일을 텍스트로 변환하고, 변환된 텍스트를 document로 로드합니다. 이를 사용하려면 assemblyai python package가 설치되어 있어야 하며, 환경 변수 ASSEMBLYAI_API_KEY에 API key가 설정되어 있어야 합니다. 또는 API key를 인자로 전달할 수도 있습니다. AssemblyAI에 대한 자세한 정보:

Installation

먼저 assemblyai python package를 설치해야 합니다. 자세한 정보는 assemblyai-python-sdk GitHub repo에서 확인할 수 있습니다.
pip install -qU  assemblyai

Example

AssemblyAIAudioTranscriptLoader는 최소한 file_path 인자가 필요합니다. 오디오 파일은 URL 또는 로컬 파일 경로로 지정할 수 있습니다.
from langchain_community.document_loaders import AssemblyAIAudioTranscriptLoader

audio_file = "https://storage.googleapis.com/aai-docs-samples/nbc.mp3"
# or a local file path: audio_file = "./nbc.mp3"

loader = AssemblyAIAudioTranscriptLoader(file_path=audio_file)

docs = loader.load()
참고: loader.load()를 호출하면 텍스트 변환이 완료될 때까지 차단됩니다. 변환된 텍스트는 page_content에서 확인할 수 있습니다:
docs[0].page_content
"Load time, a new president and new congressional makeup. Same old ..."
metadata에는 추가 메타 정보가 포함된 전체 JSON response가 들어 있습니다:
docs[0].metadata
{'language_code': <LanguageCode.en_us: 'en_us'>,
 'audio_url': 'https://storage.googleapis.com/aai-docs-samples/nbc.mp3',
 'punctuate': True,
 'format_text': True,
  ...
}

Transcript Formats

다양한 형식을 위해 transcript_format 인자를 지정할 수 있습니다. 형식에 따라 하나 이상의 document가 반환됩니다. 다음은 사용 가능한 TranscriptFormat 옵션입니다:
  • TEXT: 텍스트 변환 내용이 담긴 하나의 document
  • SENTENCES: 여러 개의 document, 텍스트 변환 내용을 문장별로 분할
  • PARAGRAPHS: 여러 개의 document, 텍스트 변환 내용을 단락별로 분할
  • SUBTITLES_SRT: SRT 자막 형식으로 내보낸 텍스트 변환 내용이 담긴 하나의 document
  • SUBTITLES_VTT: VTT 자막 형식으로 내보낸 텍스트 변환 내용이 담긴 하나의 document
from langchain_community.document_loaders.assemblyai import TranscriptFormat

loader = AssemblyAIAudioTranscriptLoader(
    file_path="./your_file.mp3",
    transcript_format=TranscriptFormat.SENTENCES,
)

docs = loader.load()

Transcription Config

다양한 audio intelligence model을 사용하기 위해 config 인자를 지정할 수도 있습니다. 사용 가능한 모든 model에 대한 개요는 AssemblyAI API Documentation을 참조하세요!
import assemblyai as aai

config = aai.TranscriptionConfig(
    speaker_labels=True, auto_chapters=True, entity_detection=True
)

loader = AssemblyAIAudioTranscriptLoader(file_path="./your_file.mp3", config=config)

Pass the API Key as argument

API key를 환경 변수 ASSEMBLYAI_API_KEY로 설정하는 것 외에도, 인자로 전달하는 것도 가능합니다.
loader = AssemblyAIAudioTranscriptLoader(
    file_path="./your_file.mp3", api_key="YOUR_KEY"
)

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I