Update app.py
Browse files
app.py
CHANGED
@@ -34,13 +34,18 @@ MODELS = {
|
|
34 |
}
|
35 |
|
36 |
def convert_audio_to_wav(audio_path):
|
|
|
|
|
37 |
wav_path = "converted_audio.wav"
|
38 |
command = ["ffmpeg", "-i", audio_path, "-ac", "1", "-ar", "16000", wav_path]
|
39 |
subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
40 |
return wav_path
|
41 |
|
42 |
def detect_language(audio_path):
|
43 |
-
|
|
|
|
|
|
|
44 |
|
45 |
processor = WhisperProcessor.from_pretrained("openai/whisper-base")
|
46 |
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-base")
|
|
|
34 |
}
|
35 |
|
36 |
def convert_audio_to_wav(audio_path):
|
37 |
+
if os.path.isdir(audio_path):
|
38 |
+
raise ValueError(f"The path provided is a directory: {audio_path}")
|
39 |
wav_path = "converted_audio.wav"
|
40 |
command = ["ffmpeg", "-i", audio_path, "-ac", "1", "-ar", "16000", wav_path]
|
41 |
subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
42 |
return wav_path
|
43 |
|
44 |
def detect_language(audio_path):
|
45 |
+
try:
|
46 |
+
speech, _ = librosa.load(audio_path, sr=16000, duration=30)
|
47 |
+
except Exception as e:
|
48 |
+
raise ValueError(f"Error loading audio file with librosa: {e}")
|
49 |
|
50 |
processor = WhisperProcessor.from_pretrained("openai/whisper-base")
|
51 |
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-base")
|