Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -21,18 +21,20 @@ def asr_transcript(audio_file, language):
|
|
21 |
model = Wav2Vec2ForCTC.from_pretrained(model)
|
22 |
|
23 |
#read the file and resample to 16KHz
|
24 |
-
stream = librosa.stream(audio_file.name, block_length=20, frame_length=16000, hop_length=16000)
|
|
|
|
|
|
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
speech = speech[:, 0] + speech[:, 1]
|
29 |
|
30 |
-
|
31 |
-
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
|
37 |
return transcript
|
38 |
|
|
|
21 |
model = Wav2Vec2ForCTC.from_pretrained(model)
|
22 |
|
23 |
#read the file and resample to 16KHz
|
24 |
+
#stream = librosa.stream(audio_file.name, block_length=20, frame_length=16000, hop_length=16000)
|
25 |
+
|
26 |
+
#read the file
|
27 |
+
speech, sample_rate = librosa.load(input_file, 16000)
|
28 |
|
29 |
+
if len(speech.shape) > 1:
|
30 |
+
speech = speech[:, 0] + speech[:, 1]
|
|
|
31 |
|
32 |
+
input_values = tokenizer(speech, return_tensors="pt").input_values
|
33 |
+
logits = model(input_values).logits
|
34 |
|
35 |
+
predicted_ids = torch.argmax(logits, dim=-1)
|
36 |
+
transcription = tokenizer.batch_decode(predicted_ids)[0]
|
37 |
+
transcript = transcription.lower()
|
38 |
|
39 |
return transcript
|
40 |
|