Spaces:
Sleeping
Sleeping
modal loads
Browse files
app.py
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
from faster_whisper import WhisperModel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
model = WhisperModel("tiny.en")
|
| 6 |
|
| 7 |
def normaliseData(audioInput, stream):
|
| 8 |
sr, y = audioInput
|
|
@@ -18,9 +39,11 @@ def normaliseData(audioInput, stream):
|
|
| 18 |
stream = np.concatenate([stream, y])
|
| 19 |
else:
|
| 20 |
stream = y
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# Return the stream as state and a string representation of the array for display
|
| 23 |
-
return stream,
|
| 24 |
|
| 25 |
|
| 26 |
with gr.Blocks() as demo:
|
|
@@ -35,11 +58,3 @@ with gr.Blocks() as demo:
|
|
| 35 |
)
|
| 36 |
demo.launch()
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
segments, info = model.transcribe("audio.mp3")
|
| 43 |
-
for segment in segments:
|
| 44 |
-
print("[%.2fs -> %.2fs] %s" % (segment.start, segment.end, segment.text))
|
| 45 |
-
|
|
|
|
| 1 |
+
|
| 2 |
import gradio as gr
|
| 3 |
import numpy as np
|
| 4 |
from faster_whisper import WhisperModel
|
| 5 |
+
from faster_whisper.transcribe import Segment
|
| 6 |
+
|
| 7 |
+
audio_model = WhisperModel("tiny.en", device="cpu", compute_type="int8")
|
| 8 |
+
transcription = ['']
|
| 9 |
+
|
| 10 |
+
def transcribe(SampleRate, data):
|
| 11 |
+
segments, info = audio_model.transcribe(data, beam_size=5)
|
| 12 |
+
result = (list(segments))
|
| 13 |
+
text = ""
|
| 14 |
+
|
| 15 |
+
if result and len(result) > 0:
|
| 16 |
+
text = result[0].text
|
| 17 |
+
print("Text:", text)
|
| 18 |
+
else:
|
| 19 |
+
text = ""
|
| 20 |
+
print("No text found")
|
| 21 |
+
print(result)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
return(text)
|
| 26 |
|
|
|
|
| 27 |
|
| 28 |
def normaliseData(audioInput, stream):
|
| 29 |
sr, y = audioInput
|
|
|
|
| 39 |
stream = np.concatenate([stream, y])
|
| 40 |
else:
|
| 41 |
stream = y
|
| 42 |
+
|
| 43 |
+
words = transcribe(sr, y)
|
| 44 |
|
| 45 |
# Return the stream as state and a string representation of the array for display
|
| 46 |
+
return stream, words,
|
| 47 |
|
| 48 |
|
| 49 |
with gr.Blocks() as demo:
|
|
|
|
| 58 |
)
|
| 59 |
demo.launch()
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|