maher13 commited on
Commit
0fce504
·
1 Parent(s): 00592d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -2,18 +2,21 @@ from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
2
  import soundfile as sf
3
  import torch
4
  import gradio as gr
5
-
6
 
7
  # load model and processor
8
  processor = Wav2Vec2Processor.from_pretrained("maher13/arabic-iti")
9
  model = Wav2Vec2ForCTC.from_pretrained("maher13/arabic-iti").eval()
10
  # define function to read in sound file
11
  def map_to_array(file):
12
- speech, sr= sf.read(file)
13
  if sr != 16000:
14
- transform = torchaudio.transforms.Resample(orig_freq=sampling_rate,
15
  new_freq=16000)
16
- speech= transform(speech)[0].numpy()
 
 
 
17
  return speech
18
 
19
  # tokenize
@@ -57,4 +60,5 @@ gradio_ui = gr.Interface(
57
  gr.outputs.Textbox(label="Auto-Transcript")
58
  ],
59
  )
 
60
  gradio_ui.launch(share=True)
 
2
  import soundfile as sf
3
  import torch
4
  import gradio as gr
5
+ import torchaudio
6
 
7
  # load model and processor
8
  processor = Wav2Vec2Processor.from_pretrained("maher13/arabic-iti")
9
  model = Wav2Vec2ForCTC.from_pretrained("maher13/arabic-iti").eval()
10
  # define function to read in sound file
11
  def map_to_array(file):
12
+ speech, sr = torchaudio.load(file)
13
  if sr != 16000:
14
+ transform = torchaudio.transforms.Resample(orig_freq=sr,
15
  new_freq=16000)
16
+ speech= transform(speech)
17
+ speech = speech[0]
18
+ speech = speech.numpy()
19
+
20
  return speech
21
 
22
  # tokenize
 
60
  gr.outputs.Textbox(label="Auto-Transcript")
61
  ],
62
  )
63
+
64
  gradio_ui.launch(share=True)