Spaces:
Sleeping
Sleeping
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) | |