Update app.py
Browse files
app.py
CHANGED
@@ -5,9 +5,82 @@ import os
|
|
5 |
import speech_recognition as sr
|
6 |
|
7 |
|
8 |
-
html_seeker='''
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
</div>
|
12 |
|
13 |
|
@@ -17,6 +90,7 @@ html_seeker1='''</div>
|
|
17 |
<script>
|
18 |
|
19 |
var $a = document.querySelector("audio");
|
|
|
20 |
window.onkeydown = function(ev) {
|
21 |
if(ev.keyCode == 32) {
|
22 |
ev.preventDefault();
|
@@ -97,7 +171,8 @@ function update() {
|
|
97 |
}
|
98 |
|
99 |
var INLINE_JSON='''
|
100 |
-
html_seeker2=''';
|
|
|
101 |
</script>'''
|
102 |
'''
|
103 |
model_name = "voidful/wav2vec2-xlsr-multilingual-56"
|
@@ -122,7 +197,7 @@ def predict_fa(speech,model):
|
|
122 |
text = model0(speech,return_timestamps="word" )
|
123 |
'''
|
124 |
text={"text": "\u0627\u06cc\u0646\u0627\u0646 \u06a9\u0631\u0627\u0644\u0627\u0644 \u0648 \u06a9\u0648\u0631\u0646\u062f \u0648 \u0644\u0632\u0627 \u0627\u0632 \u06af\u0645\u0631\u0627\u0647\u06cc \u0628\u0647 \u0631\u0627\u0647 \u0628\u0627\u0632 \u0646\u0645\u06cc\u06a9\u0631\u062f\u0646\u062f", "chunks": [{"text": "\u0627\u06cc\u0646\u0627\u0646", "timestamp": [0.0, 0.72]}, {"text": "\u06a9\u0631\u0627\u0644\u0627\u0644", "timestamp": [0.92, 1.6]}, {"text": "\u0648", "timestamp": [1.72, 1.74]}, {"text": "\u06a9\u0648\u0631\u0646\u062f", "timestamp": [1.9, 2.54]}, {"text": "\u0648", "timestamp": [2.76, 2.78]}, {"text": "\u0644\u0632\u0627", "timestamp": [2.88, 3.16]}, {"text": "\u0627\u0632", "timestamp": [3.4, 3.5]}, {"text": "\u06af\u0645\u0631\u0627\u0647\u06cc", "timestamp": [3.64, 4.3]}, {"text": "\u0628\u0647", "timestamp": [4.6, 4.68]}, {"text": "\u0631\u0627\u0647", "timestamp": [4.78, 5.12]}, {"text": "\u0628\u0627\u0632", "timestamp": [5.3, 5.58]}, {"text": "\u0646\u0645\u06cc\u06a9\u0631\u062f\u0646\u062f", "timestamp": [5.68, 7.14]}]}
|
125 |
-
return [text['text'],json.dumps(text),html_seeker+
|
126 |
|
127 |
|
128 |
def convert_to_wav(filename):
|
|
|
5 |
import speech_recognition as sr
|
6 |
|
7 |
|
8 |
+
html_seeker='''<style>
|
9 |
+
html, body {
|
10 |
+
margin: 0;
|
11 |
+
padding: 0;
|
12 |
+
min-width: 900px;
|
13 |
+
}
|
14 |
+
#header {
|
15 |
+
/*position: fixed;*/
|
16 |
+
top: 0;
|
17 |
+
left: 0;
|
18 |
+
height: 50px;
|
19 |
+
min-width: 900px;
|
20 |
+
line-height: 50px;
|
21 |
+
width: 100%;
|
22 |
+
background-color: #999;
|
23 |
+
box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.5);
|
24 |
+
font-family: Helvetica, sans-serif;
|
25 |
+
}
|
26 |
+
#header, #header a {
|
27 |
+
color: white;
|
28 |
+
}
|
29 |
+
|
30 |
+
.home {
|
31 |
+
margin: 0;
|
32 |
+
font-weight: bold;
|
33 |
+
text-transform: lowercase;
|
34 |
+
width: 100px;
|
35 |
+
}
|
36 |
+
h4.home {
|
37 |
+
margin: 0;
|
38 |
+
background: #666;
|
39 |
+
padding-left: 25px;
|
40 |
+
padding-right: 30px;
|
41 |
+
margin-right: 20px;
|
42 |
+
float: left;
|
43 |
+
text-decoration: none;
|
44 |
+
}
|
45 |
+
.home:hover a {
|
46 |
+
background: #555;
|
47 |
+
}
|
48 |
+
#audio {
|
49 |
+
margin-top: 9px;
|
50 |
+
width: 500px;
|
51 |
+
display: inline-block;
|
52 |
+
}
|
53 |
+
#transcript {
|
54 |
+
margin: 0 15px;
|
55 |
+
margin-bottom: 5em;
|
56 |
+
white-space: pre-wrap;
|
57 |
+
line-height: 2em;
|
58 |
+
max-width: 600px;
|
59 |
+
color: #999;
|
60 |
+
clear: both;
|
61 |
+
margin-top: 75px;
|
62 |
+
/*direction: rtl;*/
|
63 |
+
}
|
64 |
+
.success {
|
65 |
+
color: black;
|
66 |
+
|
67 |
+
}
|
68 |
+
.success:hover {
|
69 |
+
text-decoration: underline;
|
70 |
+
}
|
71 |
+
.active {
|
72 |
+
color: magenta;
|
73 |
+
background-color: yellow;
|
74 |
+
}
|
75 |
+
#preloader {
|
76 |
+
visibility: hidden;
|
77 |
+
}
|
78 |
+
|
79 |
+
|
80 |
+
</style><div id="header">
|
81 |
+
<h4 class="home">Model name</h4>
|
82 |
+
<audio id="audio" src="17.mp3" controls="true"></audio>
|
83 |
+
</div>
|
84 |
</div>
|
85 |
|
86 |
|
|
|
90 |
<script>
|
91 |
|
92 |
var $a = document.querySelector("audio");
|
93 |
+
$a.src=document.querySelector('audio').src;
|
94 |
window.onkeydown = function(ev) {
|
95 |
if(ev.keyCode == 32) {
|
96 |
ev.preventDefault();
|
|
|
171 |
}
|
172 |
|
173 |
var INLINE_JSON='''
|
174 |
+
html_seeker2=''';
|
175 |
+
update();
|
176 |
</script>'''
|
177 |
'''
|
178 |
model_name = "voidful/wav2vec2-xlsr-multilingual-56"
|
|
|
197 |
text = model0(speech,return_timestamps="word" )
|
198 |
'''
|
199 |
text={"text": "\u0627\u06cc\u0646\u0627\u0646 \u06a9\u0631\u0627\u0644\u0627\u0644 \u0648 \u06a9\u0648\u0631\u0646\u062f \u0648 \u0644\u0632\u0627 \u0627\u0632 \u06af\u0645\u0631\u0627\u0647\u06cc \u0628\u0647 \u0631\u0627\u0647 \u0628\u0627\u0632 \u0646\u0645\u06cc\u06a9\u0631\u062f\u0646\u062f", "chunks": [{"text": "\u0627\u06cc\u0646\u0627\u0646", "timestamp": [0.0, 0.72]}, {"text": "\u06a9\u0631\u0627\u0644\u0627\u0644", "timestamp": [0.92, 1.6]}, {"text": "\u0648", "timestamp": [1.72, 1.74]}, {"text": "\u06a9\u0648\u0631\u0646\u062f", "timestamp": [1.9, 2.54]}, {"text": "\u0648", "timestamp": [2.76, 2.78]}, {"text": "\u0644\u0632\u0627", "timestamp": [2.88, 3.16]}, {"text": "\u0627\u0632", "timestamp": [3.4, 3.5]}, {"text": "\u06af\u0645\u0631\u0627\u0647\u06cc", "timestamp": [3.64, 4.3]}, {"text": "\u0628\u0647", "timestamp": [4.6, 4.68]}, {"text": "\u0631\u0627\u0647", "timestamp": [4.78, 5.12]}, {"text": "\u0628\u0627\u0632", "timestamp": [5.3, 5.58]}, {"text": "\u0646\u0645\u06cc\u06a9\u0631\u062f\u0646\u062f", "timestamp": [5.68, 7.14]}]}
|
200 |
+
return [text['text'],json.dumps(text),html_seeker+json.dumps(text)+html_seeker2]
|
201 |
|
202 |
|
203 |
def convert_to_wav(filename):
|