-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path0_Whisper_Offline.py
47 lines (40 loc) · 1.68 KB
/
0_Whisper_Offline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import gradio as gr
import whisper
paramfp16=False # Set to True if you want to use fp16 precision on GPU
def transcribe(audio):
model = whisper.load_model("base")
result = model.transcribe(audio,fp16=paramfp16)
print(result["text"])
return result["text"]
paramfp16=False # Set to True if you want to use fp16 precision on GPU
def processAudio(audio1,audio2,choiceTranslate):
model = whisper.load_model("base")
if audio1 is None and audio2 is None:
return "No audio inputs were provided."
elif audio1 is None:
# Process only the second audio input
# Your audio processing code here
# For this example, we'll just return the second audio input
audioOk = audio2
elif audio2 is None:
# Process only the first audio input
# Your audio processing code here
# For this example, we'll just return the first audio input
audioOk = audio1
else:
audioOk = audio1
result = model.transcribe(audioOk,fp16=paramfp16)
print(result["text"])
return result["text"]
demo = gr.Interface(
processAudio,
[
gr.Audio(source="microphone", type="filepath", label="Record Audio", show_label=True, optional=True),
gr.Audio(source="upload", type="filepath", label="Upload Audio", show_label=True, optional=True)
],
"textbox",
title="Demo App 0: Whisper model in offline mode",
description="Record your speech via microphone or upload an audio file and press the Submit button to transcribe it into text. Please, note that the size of the audio file should be less than 25 MB."
)
if __name__ == "__main__":
demo.launch()