File size: 979 Bytes
b3b0b53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
import sys
import whisper

def transcribe_audio(file_path):
    """
    Transcribes an audio file using Whisper.
    """
    try:
        # Load the base model. You can change this to 'tiny', 'small', 'medium', or 'large'
        # depending on your server's performance and desired accuracy.
        # 'base' is a good starting point.
        model = whisper.load_model("base")

        # Transcribe the audio file
        result = model.transcribe(file_path)

        # Return the transcribed text
        return result["text"]
    except Exception as e:
        # Return the error message if something goes wrong
        return f"Error during transcription: {str(e)}"

if __name__ == "__main__":
    # The script expects exactly one argument: the audio file path
    if len(sys.argv) != 2:
        print("Usage: python asr.py <audio_file_path>")
        sys.exit(1)

    audio_file = sys.argv[1]
    transcribed_text = transcribe_audio(audio_file)
    print(transcribed_text)