Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -21,8 +21,7 @@ pipe = pipeline(
|
|
21 |
"automatic-speech-recognition",
|
22 |
model=model,
|
23 |
tokenizer=processor.tokenizer,
|
24 |
-
feature_extractor=processor.feature_extractor
|
25 |
-
generate_kwargs = {"task":"transcribe", "language":"<|ar|>"}
|
26 |
)
|
27 |
|
28 |
|
@@ -33,15 +32,17 @@ async def transcribe_audio(request: Request):
|
|
33 |
audio_data = await request.body()
|
34 |
# Convert binary data to a file-like object
|
35 |
audio_file = io.BytesIO(audio_data)
|
36 |
-
# Load the audio file using pydub
|
37 |
-
audio_array, sampling_rate = librosa.load(audio_file, sr=16000)
|
38 |
-
# Process the audio array
|
39 |
-
input_features = processor(audio_array, sampling_rate=sampling_rate, return_tensors="pt").input_features
|
40 |
-
# Generate token ids
|
41 |
-
predicted_ids = model.generate(input_features)
|
42 |
-
# Decode token ids to text
|
43 |
-
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
|
|
|
44 |
# Print the transcription
|
|
|
45 |
print(transcription[0]) # Display the transcriptiontry:
|
46 |
return {"transcription": transcription[0]}
|
47 |
except Exception as e:
|
|
|
21 |
"automatic-speech-recognition",
|
22 |
model=model,
|
23 |
tokenizer=processor.tokenizer,
|
24 |
+
feature_extractor=processor.feature_extractor
|
|
|
25 |
)
|
26 |
|
27 |
|
|
|
32 |
audio_data = await request.body()
|
33 |
# Convert binary data to a file-like object
|
34 |
audio_file = io.BytesIO(audio_data)
|
35 |
+
# # Load the audio file using pydub
|
36 |
+
# audio_array, sampling_rate = librosa.load(audio_file, sr=16000)
|
37 |
+
# # Process the audio array
|
38 |
+
# input_features = processor(audio_array, sampling_rate=sampling_rate, return_tensors="pt").input_features
|
39 |
+
# # Generate token ids
|
40 |
+
# predicted_ids = model.generate(input_features)
|
41 |
+
# # Decode token ids to text
|
42 |
+
# transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
|
43 |
+
transcription = pipe(audio_file,generate_kwargs = {"task":"transcribe", "language":"<|ar|>"})
|
44 |
# Print the transcription
|
45 |
+
print(transcription)
|
46 |
print(transcription[0]) # Display the transcriptiontry:
|
47 |
return {"transcription": transcription[0]}
|
48 |
except Exception as e:
|