Spaces:
Runtime error
Runtime error
Commit
·
fbcb979
1
Parent(s):
c31f0fe
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import pipeline
|
4 |
+
import soundfile as sf
|
5 |
+
import tempfile
|
6 |
+
import shutil
|
7 |
+
import os
|
8 |
+
import librosa
|
9 |
+
import time
|
10 |
+
|
11 |
+
|
12 |
+
def resample_to_16k(audio, orig_sr):
|
13 |
+
y_resampled = librosa.resample(y=audio, orig_sr=orig_sr, target_sr = 16000)
|
14 |
+
return y_resampled
|
15 |
+
|
16 |
+
def transcribe(audio,):
|
17 |
+
sr,y = audio
|
18 |
+
y = y.astype(np.float32)
|
19 |
+
y /= np.max(np.abs(y))
|
20 |
+
y_resampled = resample_to_16k(y, sr)
|
21 |
+
|
22 |
+
|
23 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_audio:
|
24 |
+
temp_audio_path = temp_audio.name
|
25 |
+
sf.write(temp_audio_path, y_resampled, 16000)
|
26 |
+
|
27 |
+
command = f"""main.exe -m 'I:\\ASR\\Whisper CPP\\SubGen\\whisper_blas_bin_v1_3_0\\models\\ggml-model-whisper-small.en.bin' -osrt -f '{temp_audio_path}' -nt"""
|
28 |
+
|
29 |
+
start_time = time.time()
|
30 |
+
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
31 |
+
end_time = time.time()
|
32 |
+
print("Output",result.stdout)
|
33 |
+
print("Error",result.stderr)
|
34 |
+
transcription = result.stdout
|
35 |
+
print(transcription)
|
36 |
+
|
37 |
+
print("--------------------------")
|
38 |
+
print(f"Execution time: {end_time - start_time} seconds")
|
39 |
+
return transcription
|