Unit4-GAIA / tools /audio_transcription.py
Romain Lembo
Remove unused language parameter from audio transcription function
baf6239
raw
history blame
785 Bytes
"""Tool for transcribing audio files to text."""
import os
from langchain_core.tools import tool
from langchain_community.document_loaders import AssemblyAIAudioTranscriptLoader
@tool
def audio_transcription(file_path: str) -> str:
"""
Transcribe an audio file to text using AssemblyAI.
Args:
file_path: The path to the audio file.
Returns:
The transcribed text from the audio file.
"""
search_docs = AssemblyAIAudioTranscriptLoader(file_path=file_path).load()
formatted_search_docs = "\n\n---\n\n".join(
[
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
for doc in search_docs
])
return {"audio_results": formatted_search_docs}