Astro / tools /transcriber.py
Abraham E. Tavarez
Astro final challenge agent
2125ce6
raw
history blame contribute delete
930 Bytes
# Use a pipeline as a high-level helper
from transformers import pipeline
from smolagents import tool
import os
# print(os.getcwd() + "/audio/interview.mp3")
transcriber_pipeline = pipeline(
"automatic-speech-recognition", model="facebook/wav2vec2-base-960h"
)
@tool
def transcribe_audio(audio_file_path: str) -> str:
"""Transcribe an audio file into text.
Args:
audio_file_path: The path to the audio file to transcribe.
Returns:
The transcribed text.
"""
try:
if os.path.isfile(audio_file_path):
return transcriber_pipeline(audio_file_path)["text"]
else:
raise FileNotFoundError(f"Audio file not found: {audio_file_path}")
except FileNotFoundError as e:
return f"Error: {str(e)}"
# file = os.getcwd() + "/audio/interview.mp3"
# result = transcribe_audio(file)
# print(result)
# transcribe_audio_tool = transcribe_audio.push_to_hub()