Files
langchain/docs/versioned_docs/version-0.2.x/integrations/document_loaders/assemblyai.ipynb
Jacob Lee aff771923a Jacob/new docs (#20570)
Use docusaurus versioning with a callout, merged master as well

@hwchase17 @baskaryan

---------

Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Rahul Tripathi <rauhl.psit.ec@gmail.com>
Co-authored-by: Leonid Ganeline <leo.gan.57@gmail.com>
Co-authored-by: Leonid Kuligin <lkuligin@yandex.ru>
Co-authored-by: Averi Kitsch <akitsch@google.com>
Co-authored-by: Erick Friis <erick@langchain.dev>
Co-authored-by: Nuno Campos <nuno@langchain.dev>
Co-authored-by: Nuno Campos <nuno@boringbits.io>
Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
Co-authored-by: Martín Gotelli Ferenaz <martingotelliferenaz@gmail.com>
Co-authored-by: Fayfox <admin@fayfox.com>
Co-authored-by: Eugene Yurtsev <eugene@langchain.dev>
Co-authored-by: Dawson Bauer <105886620+djbauer2@users.noreply.github.com>
Co-authored-by: Ravindu Somawansa <ravindu.somawansa@gmail.com>
Co-authored-by: Dhruv Chawla <43818888+Dominastorm@users.noreply.github.com>
Co-authored-by: ccurme <chester.curme@gmail.com>
Co-authored-by: Bagatur <baskaryan@gmail.com>
Co-authored-by: WeichenXu <weichen.xu@databricks.com>
Co-authored-by: Benito Geordie <89472452+benitoThree@users.noreply.github.com>
Co-authored-by: kartikTAI <129414343+kartikTAI@users.noreply.github.com>
Co-authored-by: Kartik Sarangmath <kartik@thirdai.com>
Co-authored-by: Sevin F. Varoglu <sfvaroglu@octoml.ai>
Co-authored-by: MacanPN <martin.triska@gmail.com>
Co-authored-by: Prashanth Rao <35005448+prrao87@users.noreply.github.com>
Co-authored-by: Hyeongchan Kim <kozistr@gmail.com>
Co-authored-by: sdan <git@sdan.io>
Co-authored-by: Guangdong Liu <liugddx@gmail.com>
Co-authored-by: Rahul Triptahi <rahul.psit.ec@gmail.com>
Co-authored-by: Rahul Tripathi <rauhl.psit.ec@gmail.com>
Co-authored-by: pjb157 <84070455+pjb157@users.noreply.github.com>
Co-authored-by: Eun Hye Kim <ehkim1440@gmail.com>
Co-authored-by: kaijietti <43436010+kaijietti@users.noreply.github.com>
Co-authored-by: Pengcheng Liu <pcliu.fd@gmail.com>
Co-authored-by: Tomer Cagan <tomer@tomercagan.com>
Co-authored-by: Christophe Bornet <cbornet@hotmail.com>
2024-04-18 11:10:55 -07:00

217 lines
5.7 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# AssemblyAI Audio Transcripts\n",
"\n",
"The `AssemblyAIAudioTranscriptLoader` allows to transcribe audio files with the [AssemblyAI API](https://www.assemblyai.com) and loads the transcribed text into documents.\n",
"\n",
"To use it, you should have the `assemblyai` python package installed, and the\n",
"environment variable `ASSEMBLYAI_API_KEY` set with your API key. Alternatively, the API key can also be passed as an argument.\n",
"\n",
"More info about AssemblyAI:\n",
"\n",
"- [Website](https://www.assemblyai.com/)\n",
"- [Get a Free API key](https://www.assemblyai.com/dashboard/signup)\n",
"- [AssemblyAI API Docs](https://www.assemblyai.com/docs)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Installation\n",
"\n",
"First, you need to install the `assemblyai` python package.\n",
"\n",
"You can find more info about it inside the [assemblyai-python-sdk GitHub repo](https://github.com/AssemblyAI/assemblyai-python-sdk)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet assemblyai"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Example\n",
"\n",
"The `AssemblyAIAudioTranscriptLoader` needs at least the `file_path` argument. Audio files can be specified as an URL or a local file path."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from langchain_community.document_loaders import AssemblyAIAudioTranscriptLoader\n",
"\n",
"audio_file = \"https://storage.googleapis.com/aai-docs-samples/nbc.mp3\"\n",
"# or a local file path: audio_file = \"./nbc.mp3\"\n",
"\n",
"loader = AssemblyAIAudioTranscriptLoader(file_path=audio_file)\n",
"\n",
"docs = loader.load()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note: Calling `loader.load()` blocks until the transcription is finished."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The transcribed text is available in the `page_content`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"docs[0].page_content"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```\n",
"\"Load time, a new president and new congressional makeup. Same old ...\"\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `metadata` contains the full JSON response with more meta information:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"docs[0].metadata"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```\n",
"{'language_code': <LanguageCode.en_us: 'en_us'>,\n",
" 'audio_url': 'https://storage.googleapis.com/aai-docs-samples/nbc.mp3',\n",
" 'punctuate': True,\n",
" 'format_text': True,\n",
" ...\n",
"}\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Transcript Formats\n",
"\n",
"You can specify the `transcript_format` argument for different formats.\n",
"\n",
"Depending on the format, one or more documents are returned. These are the different `TranscriptFormat` options:\n",
"\n",
"- `TEXT`: One document with the transcription text\n",
"- `SENTENCES`: Multiple documents, splits the transcription by each sentence\n",
"- `PARAGRAPHS`: Multiple documents, splits the transcription by each paragraph\n",
"- `SUBTITLES_SRT`: One document with the transcript exported in SRT subtitles format\n",
"- `SUBTITLES_VTT`: One document with the transcript exported in VTT subtitles format"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from langchain_community.document_loaders.assemblyai import TranscriptFormat\n",
"\n",
"loader = AssemblyAIAudioTranscriptLoader(\n",
" file_path=\"./your_file.mp3\",\n",
" transcript_format=TranscriptFormat.SENTENCES,\n",
")\n",
"\n",
"docs = loader.load()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Transcription Config\n",
"\n",
"You can also specify the `config` argument to use different audio intelligence models.\n",
"\n",
"Visit the [AssemblyAI API Documentation](https://www.assemblyai.com/docs) to get an overview of all available models!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import assemblyai as aai\n",
"\n",
"config = aai.TranscriptionConfig(\n",
" speaker_labels=True, auto_chapters=True, entity_detection=True\n",
")\n",
"\n",
"loader = AssemblyAIAudioTranscriptLoader(file_path=\"./your_file.mp3\", config=config)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Pass the API Key as argument\n",
"\n",
"Next to setting the API key as environment variable `ASSEMBLYAI_API_KEY`, it is also possible to pass it as argument."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"loader = AssemblyAIAudioTranscriptLoader(\n",
" file_path=\"./your_file.mp3\", api_key=\"YOUR_KEY\"\n",
")"
]
}
],
"metadata": {
"language_info": {
"name": "python"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}