Petita commited on
Commit
a10dae8
1 Parent(s): c5a9897

Put basic transcription in app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -4
app.py CHANGED
@@ -1,7 +1,43 @@
 
 
 
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ from whisper_online import *
3
+ import librosa
4
  import gradio as gr
5
 
6
+ @lru_cache
7
+ def load_audio(fname):
8
+ a, _ = librosa.load(fname, sr=16000, dtype=np.float32)
9
+ return a
10
 
11
+
12
+ asr = FasterWhisperASR("en", "large-v2") # loads and wraps Whisper model
13
+ online = OnlineASRProcessor(asr) # create processing object with default buffer trimming option
14
+
15
+ def transcribe(audio_file)
16
+ try:
17
+ audio_data = load_audio(audio_file)
18
+
19
+ # Insert audio chunk into the ASR processor
20
+ online.insert_audio_chunk(audio_data)
21
+
22
+ # Process the audio chunk
23
+ o = online.process_iter()
24
+
25
+ # Send current partial output
26
+ return o
27
+
28
+ except Exception as e:
29
+ return str(e)
30
+
31
+ def finish_stream():
32
+ try:
33
+ # Finish audio processing
34
+ o = online.finish()
35
+
36
+ # Send last output
37
+ return o
38
+
39
+ except Exception as e:
40
+ return str(e)
41
+
42
+ iface = gr.Interface(fn=transcribe,inputs = "text", outputs = "text")
43
+ iface.launch()