camparchimedes commited on
Commit
451ca09
·
verified ·
1 Parent(s): 501c4cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -12
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(audio_file, batch_size=16, sample_rate=16000):
73
- audio_file = filepath.read(audio_file)
74
- waveform, sample_rate = torchaudio.load(audio_file)
75
-
76
- if samples.ndim > 1:
77
- samples = samples[0, :]
 
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(samples, sampling_rate=sample_rate, batch_size=batch_size, return_timestamps=False)
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