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(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 will translate your speech into text, morse code, and audio using wav2vec2-base-960h", article = "Model: Wav2Vec2-Base-960h" ).launch()