Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ from transformers import pipeline
|
|
3 |
from pydub import AudioSegment
|
4 |
|
5 |
pipe = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
|
6 |
-
|
7 |
dictionary = {' ': '/',
|
8 |
"'": '.----.',
|
9 |
'0': '-----',
|
@@ -48,16 +48,16 @@ dictionary = {' ': '/',
|
|
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
|
@@ -69,7 +69,7 @@ def asr(speech):
|
|
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,
|
@@ -79,7 +79,7 @@ gr.Interface(fn=asr,
|
|
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 = ["helloworld.mp3"],
|
84 |
article = "Author: <a href=\"https://huggingface.co/epdavid2\">Edson</a>"
|
85 |
).launch()
|
|
|
3 |
from pydub import AudioSegment
|
4 |
|
5 |
pipe = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
|
6 |
+
#morse code dictionary
|
7 |
dictionary = {' ': '/',
|
8 |
"'": '.----.',
|
9 |
'0': '-----',
|
|
|
48 |
|
49 |
|
50 |
def asr(speech):
|
51 |
+
dummy = AudioSegment.from_file("dummy.mp3", format="mp3") #load audio files
|
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'] #convert input speech to text
|
57 |
morseCode = ""
|
58 |
for character in transcript:
|
59 |
morseCode += dictionary[character] + " "
|
60 |
+
while i<len(morseCode): #append dash and dot sounds
|
61 |
if morseCode[i] == ".":
|
62 |
dummy = dummy + dot
|
63 |
i = i+1
|
|
|
69 |
i = i+1
|
70 |
else:
|
71 |
i = i+1
|
72 |
+
morseAudio = dummy.export("output.mp3", format="mp3") #export final audio
|
73 |
return transcript, morseCode, "output.mp3"
|
74 |
|
75 |
gr.Interface(fn=asr,
|
|
|
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 using wav2vec2-base-960h",
|
83 |
+
examples = [["helloworld.mp3"], ["SOS.mp3"], ["SMS.mp3]"]],
|
84 |
article = "Author: <a href=\"https://huggingface.co/epdavid2\">Edson</a>"
|
85 |
).launch()
|