Agent_GAIA_Benchmark / agent_tools /AudioInterpreterTool.py
Daksh Chaudhary
Update agent_tools/AudioInterpreterTool.py
728c556 verified
raw
history blame contribute delete
819 Bytes
import os
from llama_index.readers.assemblyai import AssemblyAIAudioTranscriptReader
from llama_index.core.tools import FunctionTool
def transcribe_audio(audio_file_path: str) -> str:
"""
Transcribes audio file and returns the transcript string as output.
Args:
audio_file_path (str): Local path to the audio file
"""
reader = AssemblyAIAudioTranscriptReader(api_key= os.getenv("ASSEMBLYAI_API_KEY") ,file_path=audio_file_path)
docs = reader.load_data()
return docs[0].text
def get_transcribe_audio() -> FunctionTool:
return FunctionTool.from_defaults(
fn=transcribe_audio,
name="audio_file_transcriber",
description="A tool that transcribes audio files (such as mp3). It takes the file_path to the downloaded audio file and returns the transcripts."
)