camparchimedes commited on
Commit
9e87cc4
·
verified ·
1 Parent(s): ebe1913

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -55,7 +55,7 @@ SIDEBAR_INFO = f"""
55
  </div>
56
  """
57
 
58
- # ------------transcribe section------------
59
 
60
  @spaces.GPU()
61
  def convert_to_wav(filepath):
@@ -64,13 +64,20 @@ def convert_to_wav(filepath):
64
  os.system(f'ffmpeg -i "{filepath}" -ar 16000 -ac 1 -c:a pcm_s16le "{audio_file}"')
65
  return audio_file
66
 
67
- pipe = pipeline("automatic-speech-recognition", model="NbAiLab/nb-whisper-large", chunk_length_s=30)
68
 
69
  @spaces.GPU()
70
  def transcribe_audio(audio_file, batch_size=16):
 
 
 
 
 
71
  start_time = time.time()
72
 
73
- outputs = pipe(audio_file, batch_size=batch_size, return_timestamps=False)
 
 
74
 
75
  end_time = time.time()
76
 
@@ -97,6 +104,7 @@ def transcribe_audio(audio_file, batch_size=16):
97
 
98
  return text.strip(), system_info
99
 
 
100
  # ------------summary section------------
101
 
102
 
 
55
  </div>
56
  """
57
 
58
+ # ------------transcribe section------------
59
 
60
  @spaces.GPU()
61
  def convert_to_wav(filepath):
 
64
  os.system(f'ffmpeg -i "{filepath}" -ar 16000 -ac 1 -c:a pcm_s16le "{audio_file}"')
65
  return audio_file
66
 
67
+ pipe = pipeline("automatic-speech-recognition", model="NbAiLab/nb-whisper-large", chunk_length_s=30, generate_kwargs={'task': 'transcribe', 'language': 'no'})
68
 
69
  @spaces.GPU()
70
  def transcribe_audio(audio_file, batch_size=16):
71
+ # Load the audio file into a numpy array
72
+ audio = AudioSegment.from_wav(audio_file)
73
+ samples = np.array(audio.get_array_of_samples())
74
+ sample_rate = audio.frame_rate
75
+
76
  start_time = time.time()
77
 
78
+ # Transcribe the audio file
79
+ outputs = pipe(samples, sampling_rate=sample_rate, batch_size=batch_size, return_timestamps=False)
80
+ text = outputs["text"]
81
 
82
  end_time = time.time()
83
 
 
104
 
105
  return text.strip(), system_info
106
 
107
+
108
  # ------------summary section------------
109
 
110