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 the simple problem", article = "Models: Wav2Vec2-Base-960h, fastspeech2-en-ljspeech", examples=["additionTest.mp3","minusTest.mp3","multiplyTest.mp3","divideTest.mp3"] ).launch()