New approach using pipeline
Browse files
app.py
CHANGED
|
@@ -63,6 +63,19 @@ def inference(audio):
|
|
| 63 |
|
| 64 |
return "\n".join(total_prediction) + "\n\n" + ' '.join(words)
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
inputs = gr.Audio(label="Input Audio", sources="microphone", type="filepath")
|
| 68 |
outputs = "text"
|
|
@@ -74,7 +87,7 @@ examples = [
|
|
| 74 |
["sample2.mp3"],
|
| 75 |
]
|
| 76 |
gr.Interface(
|
| 77 |
-
|
| 78 |
inputs,
|
| 79 |
outputs,
|
| 80 |
title=title,
|
|
|
|
| 63 |
|
| 64 |
return "\n".join(total_prediction) + "\n\n" + ' '.join(words)
|
| 65 |
|
| 66 |
+
pipe = pipeline(
|
| 67 |
+
task="automatic-speech-recognition",
|
| 68 |
+
model=model_name,
|
| 69 |
+
chunk_length_s=10,
|
| 70 |
+
device=device,
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
def transcribe(inputs):
|
| 74 |
+
if inputs is None:
|
| 75 |
+
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
| 76 |
+
|
| 77 |
+
text = pipe(inputs, batch_size=1, return_timestamps=True)["text"]
|
| 78 |
+
return text
|
| 79 |
|
| 80 |
inputs = gr.Audio(label="Input Audio", sources="microphone", type="filepath")
|
| 81 |
outputs = "text"
|
|
|
|
| 87 |
["sample2.mp3"],
|
| 88 |
]
|
| 89 |
gr.Interface(
|
| 90 |
+
transcribe,
|
| 91 |
inputs,
|
| 92 |
outputs,
|
| 93 |
title=title,
|