Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -69,27 +69,23 @@ def convert_to_wav(filepath):
|
|
69 |
pipe = pipeline("automatic-speech-recognition", model="NbAiLab/nb-whisper-large", chunk_length_s=30, generate_kwargs={'task': 'transcribe', 'language': 'no'})
|
70 |
|
71 |
@spaces.GPU()
|
72 |
-
def transcribe_audio(
|
73 |
-
|
74 |
-
waveform, sample_rate = torchaudio.load(
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
78 |
|
79 |
# --waveform to ndnumpy array
|
80 |
samples = waveform.numpy()
|
81 |
|
82 |
start_time = time.time()
|
83 |
-
|
84 |
-
# --convert to mono
|
85 |
-
if len(samples.shape) > 1:
|
86 |
-
samples = samples[:, 0]
|
87 |
|
88 |
-
start_time = time.time()
|
89 |
|
90 |
# --pipe it
|
91 |
with torch.no_grad():
|
92 |
-
outputs = pipe(
|
93 |
|
94 |
end_time = time.time()
|
95 |
|
|
|
69 |
pipe = pipeline("automatic-speech-recognition", model="NbAiLab/nb-whisper-large", chunk_length_s=30, generate_kwargs={'task': 'transcribe', 'language': 'no'})
|
70 |
|
71 |
@spaces.GPU()
|
72 |
+
def transcribe_audio(filepath, batch_size=16, sample_rate=16000):
|
73 |
+
|
74 |
+
waveform, sample_rate = torchaudio.load(filepath)
|
75 |
+
|
76 |
+
# --convert to mono
|
77 |
+
if waveform.ndim > 1:
|
78 |
+
waveform = waveform[0, :]
|
79 |
|
80 |
# --waveform to ndnumpy array
|
81 |
samples = waveform.numpy()
|
82 |
|
83 |
start_time = time.time()
|
|
|
|
|
|
|
|
|
84 |
|
|
|
85 |
|
86 |
# --pipe it
|
87 |
with torch.no_grad():
|
88 |
+
outputs = pipe(waveform, sampling_rate=sample_rate, batch_size=batch_size, return_timestamps=False)
|
89 |
|
90 |
end_time = time.time()
|
91 |
|