pratikshahp commited on
Commit
b521892
·
verified ·
1 Parent(s): 821e791

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -12,12 +12,23 @@ from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq
12
  def transcribe_audio(audio_bytes):
13
  processor = AutoProcessor.from_pretrained("openai/whisper-large")
14
  model = AutoModelForSpeechSeq2Seq.from_pretrained("openai/whisper-large")
 
 
15
  audio_array = np.frombuffer(audio_bytes, dtype=np.int16)
 
 
16
  audio_tensor = torch.tensor(audio_array, dtype=torch.float64) / 32768.0
17
- inputs = processor(feature_extractor=audio_tensor, sampling_rate=16000, return_tensors="pt")
 
 
 
 
18
  logits = model(**inputs).logits
 
 
19
  predicted_ids = torch.argmax(logits, dim=-1)
20
  transcription = processor.decode(predicted_ids[0])
 
21
  return transcription
22
 
23
 
 
12
  def transcribe_audio(audio_bytes):
13
  processor = AutoProcessor.from_pretrained("openai/whisper-large")
14
  model = AutoModelForSpeechSeq2Seq.from_pretrained("openai/whisper-large")
15
+
16
+ # Convert audio bytes to numpy array
17
  audio_array = np.frombuffer(audio_bytes, dtype=np.int16)
18
+
19
+ # Normalize audio array
20
  audio_tensor = torch.tensor(audio_array, dtype=torch.float64) / 32768.0
21
+
22
+ # Provide inputs to the processor
23
+ inputs = processor(audio=audio_tensor, sampling_rate=16000, return_tensors="pt")
24
+
25
+ # Generate logits from the model
26
  logits = model(**inputs).logits
27
+
28
+ # Decode the predicted IDs to get the transcription
29
  predicted_ids = torch.argmax(logits, dim=-1)
30
  transcription = processor.decode(predicted_ids[0])
31
+
32
  return transcription
33
 
34