import gradio as gr from transformers import pipeline from pydub import AudioSegment pipe = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h") #morse code dictionary dictionary = {' ': '/', "'": '.----.', '0': '-----', '1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....', '6': '-....', '7': '--...', '8': '---..', '9': '----.', '?': '..--..', 'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.', 'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..', 'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.', 'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-', 'Y': '-.--', 'Z': '--..', } def asr(speech): dummy = AudioSegment.from_file("dummy.mp3", format="mp3") #load audio files dot = AudioSegment.from_file("dot.mp3", format="mp3") dash = AudioSegment.from_file("dash.mp3", format="mp3") space = AudioSegment.from_file("space.mp3", format="mp3") i=0 transcript = pipe(speech)['text'] #convert input speech to text morseCode = "" for character in transcript: morseCode += dictionary[character] + " " while iWav2Vec2-Base-960h" ).launch()