Update app.py
Browse files
app.py
CHANGED
|
@@ -27,17 +27,36 @@ def process_audio(audio_file, num_speakers, model_size="medium", language="Engli
|
|
| 27 |
with open(path, "wb") as f:
|
| 28 |
f.write(audio_file.read())
|
| 29 |
|
|
|
|
|
|
|
| 30 |
# Convert audio to WAV if it's not already
|
| 31 |
if path[-3:] != 'wav':
|
| 32 |
wav_path = path.replace(path.split('.')[-1], 'wav')
|
| 33 |
subprocess.call(['ffmpeg', '-i', path, wav_path, '-y'])
|
| 34 |
path = wav_path
|
| 35 |
|
|
|
|
|
|
|
| 36 |
# Load Whisper model
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
segments = result["segments"]
|
| 40 |
|
|
|
|
|
|
|
|
|
|
| 41 |
# Get audio duration
|
| 42 |
with contextlib.closing(wave.open(path, 'r')) as f:
|
| 43 |
frames = f.getnframes()
|
|
|
|
| 27 |
with open(path, "wb") as f:
|
| 28 |
f.write(audio_file.read())
|
| 29 |
|
| 30 |
+
print(f"Audio file saved to: {path}")
|
| 31 |
+
|
| 32 |
# Convert audio to WAV if it's not already
|
| 33 |
if path[-3:] != 'wav':
|
| 34 |
wav_path = path.replace(path.split('.')[-1], 'wav')
|
| 35 |
subprocess.call(['ffmpeg', '-i', path, wav_path, '-y'])
|
| 36 |
path = wav_path
|
| 37 |
|
| 38 |
+
print(f"Audio converted to: {path}")
|
| 39 |
+
|
| 40 |
# Load Whisper model
|
| 41 |
+
try:
|
| 42 |
+
model = whisper.load_model(model_size)
|
| 43 |
+
print("Whisper model loaded successfully.")
|
| 44 |
+
except Exception as e:
|
| 45 |
+
print(f"Error loading Whisper model: {e}")
|
| 46 |
+
return f"Error loading Whisper model: {e}"
|
| 47 |
+
|
| 48 |
+
try:
|
| 49 |
+
result = model.transcribe(path)
|
| 50 |
+
print(f"Transcription result: {result}")
|
| 51 |
+
except Exception as e:
|
| 52 |
+
print(f"Error during transcription: {e}")
|
| 53 |
+
return f"Error during transcription: {e}"
|
| 54 |
+
|
| 55 |
segments = result["segments"]
|
| 56 |
|
| 57 |
+
# Remaining processing code...
|
| 58 |
+
|
| 59 |
+
|
| 60 |
# Get audio duration
|
| 61 |
with contextlib.closing(wave.open(path, 'r')) as f:
|
| 62 |
frames = f.getnframes()
|