ThirdIringan commited on
Commit
0833e1a
1 Parent(s): c9c5915

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from pydub import AudioSegment
4
+ import wordtodigits
5
+
6
+ model = pipeline("automatic-speech-recognition",
7
+ "facebook/wav2vec2-base-960h")
8
+
9
+ model2 = gr.Interface.load("huggingface/facebook/fastspeech2-en-ljspeech")
10
+
11
+
12
+ def asr(speech):
13
+ transcript = model(speech)['text']
14
+ strings = transcript.split()
15
+ text = ""
16
+ equation = ""
17
+ symbols = {"plus":"+","minus":"-","times":"*","divide":"/"}
18
+ for i in range(len(strings)):
19
+ if strings[i].lower() in symbols:
20
+ text = wordtodigits.convert(text)
21
+ equation += text + symbols[strings[i].lower()]
22
+ text=""
23
+ continue
24
+ text += strings[i].lower() + " "
25
+ if i == len(strings)-1:
26
+ text = wordtodigits.convert(text)
27
+ equation += text
28
+
29
+ ans = round(eval(equation),2)
30
+
31
+ return transcript, equation, ans, model2(str(ans))
32
+
33
+ gr.Interface(fn=asr,
34
+ #inputs = gr.inputs.Audio(source="microphone", type="filepath", optional=False, label="Please record your voice"),
35
+ inputs = gr.inputs.Audio(source="upload", type="filepath", label="Upload your audio file here"),
36
+ outputs = [gr.outputs.Textbox(type="str", label="Text Translation"),
37
+ gr.outputs.Textbox(type="str", label="Equation"),
38
+ gr.outputs.Textbox(type="str", label="Answer"),
39
+ gr.outputs.Audio(type="file", label="Speech Answer")],
40
+ title = "Speech Equation Solver",
41
+ description = "This app will translate your speech into text, morse code, and audio using wav2vec2-base-960h",
42
+ article = "Model: <a href=\"https://huggingface.co/facebook/wav2vec2-base-960h\">Wav2Vec2-Base-960h</a>"
43
+ ).launch()