| 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." | |