File size: 965 Bytes
6220346 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
from smolagents import Tool
from transformers import pipeline
class ConvertAudioToTextTool(Tool):
name = "convert_audio_to_text"
description = "Transcribe an audio file to text using a free Hugging Face template."
inputs = {
"audio_path": {
"type": "string",
"description": "The path of the audio file to elaborate"
}
}
output_type = "string"
def __init__(self):
super().__init__()
self.model = "openai/whisper-small"
self.transcriber = pipeline(
"automatic-speech-recognition",
model=self.model,
return_timestamps=True
)
def forward(self, audio_path: str) -> str:
try:
result = self.transcriber(audio_path)
return f"Audio transcribed: {result['text']}"
except Exception as e:
return f"Error convert_audio_to_text is not working properly error: {e}, please skip this tool."
|