Spaces:
Runtime error
Runtime error
File size: 1,934 Bytes
0833e1a 4f60d64 0833e1a b116fe8 6d438a7 f69f557 0833e1a |
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 |
import gradio as gr
from transformers import pipeline
from pydub import AudioSegment
import wordtodigits
model = pipeline("automatic-speech-recognition",
"facebook/wav2vec2-base-960h")
model2 = gr.Interface.load("huggingface/facebook/fastspeech2-en-ljspeech")
def asr(speech):
transcript = model(speech)['text']
strings = transcript.split()
text = ""
equation = ""
symbols = {"plus":"+","minus":"-","times":"*","divide":"/"}
for i in range(len(strings)):
if strings[i].lower() in symbols:
text = wordtodigits.convert(text)
equation += text + symbols[strings[i].lower()]
text=""
continue
text += strings[i].lower() + " "
if i == len(strings)-1:
text = wordtodigits.convert(text)
equation += text
ans = round(eval(equation),2)
return transcript, equation, ans, model2("The answer is "+str(ans))
gr.Interface(fn=asr,
#inputs = gr.inputs.Audio(source="microphone", type="filepath", optional=False, label="Please record your voice"),
inputs = gr.inputs.Audio(source="upload", type="filepath", label="Upload your audio file here"),
outputs = [gr.outputs.Textbox(type="str", label="Text Translation"),
gr.outputs.Textbox(type="str", label="Equation"),
gr.outputs.Textbox(type="str", label="Answer"),
gr.outputs.Audio(type="file", label="Speech Answer")],
title = "Speech Equation Solver",
description = "This app aims to translate speech into an equation, solve the equation and generate a speech to tell the user the answer to a problem\n Addition : x plus y \n Subtraction: x minus y \n Multiplication: x times y \n Division: x divide y",
article = "Models: Wav2Vec2-Base-960h, fastspeech2-en-ljspeech",
examples=["additionTest.mp3","minusTest.mp3","multiplyTest.mp3","divideTest.mp3"]
).launch() |