File size: 930 Bytes
2125ce6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
# 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()