epdavid2 commited on
Commit
ba1ce2e
1 Parent(s): 2e6d43b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -3
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
3
 
4
  pipe = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
5
 
@@ -45,14 +46,40 @@ dictionary = {' ': '/',
45
  }
46
 
47
 
 
48
  def asr(speech):
 
 
 
 
 
49
  transcript = pipe(speech)['text']
50
  morseCode = ""
51
  for character in transcript:
52
  morseCode += dictionary[character] + " "
53
- return morseCode
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  gr.Interface(fn=asr,
56
- inputs = gr.inputs.Audio(source="upload", type="filepath", label="Upload your audio file here"),
57
- outputs = gr.outputs.Textbox(type="str",label="Output Text"),
 
 
 
 
 
 
 
58
  ).launch()
1
  import gradio as gr
2
  from transformers import pipeline
3
+ from pydub import AudioSegment
4
 
5
  pipe = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
6
 
46
  }
47
 
48
 
49
+
50
  def asr(speech):
51
+ dummy = AudioSegment.from_file("dummy.mp3", format="mp3")
52
+ dot = AudioSegment.from_file("dot.mp3", format="mp3")
53
+ dash = AudioSegment.from_file("dash.mp3", format="mp3")
54
+ space = AudioSegment.from_file("space.mp3", format="mp3")
55
+ i=0
56
  transcript = pipe(speech)['text']
57
  morseCode = ""
58
  for character in transcript:
59
  morseCode += dictionary[character] + " "
60
+ while i<len(morseCode):
61
+ if morseCode[i] == ".":
62
+ dummy = dummy + dot
63
+ i = i+1
64
+ elif morseCode[i] == "-":
65
+ dummy = dummy + dash
66
+ i = i+1
67
+ elif morseCode[i] == " ":
68
+ dummy = dummy + space
69
+ i = i+1
70
+ else:
71
+ i = i+1
72
+ morseAudio = dummy.export("output.mp3", format="mp3")
73
+ return transcript, morseCode, "output.mp3"
74
 
75
  gr.Interface(fn=asr,
76
+ inputs = gr.inputs.Audio(source="microphone", type="filepath", optional=False, label="Please record your voice"),
77
+ # inputs = gr.inputs.Audio(source="upload", type="filepath", label="Upload your audio file here"),
78
+ outputs = [gr.outputs.Textbox(type="str", label="Text Translation"),
79
+ gr.outputs.Textbox(type="str", label="Morse Code"),
80
+ gr.outputs.Audio(type="file", label="Audio Translation")],
81
+ title = "Speech to Morse Code",
82
+ description = "This app will translate your speech into text, morse code, and audio.",
83
+ examples = [["hello world.mp3"], ["intro.mp3"]],
84
+ article = "Author: <a href=\"https://huggingface.co/epdavid2\">Edson</a>"
85
  ).launch()