csukuangfj
commited on
Commit
•
46930c1
1
Parent(s):
682c8c3
print time info
Browse files
app.py
CHANGED
@@ -43,12 +43,18 @@ from model import (
|
|
43 |
languages = list(language_to_models.keys())
|
44 |
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
def convert_to_wav(in_filename: str) -> str:
|
47 |
"""Convert the input audio file to a wave file"""
|
48 |
out_filename = str(uuid.uuid4())
|
49 |
out_filename = f"{in_filename}.wav"
|
50 |
|
51 |
-
|
52 |
_ = os.system(
|
53 |
f"ffmpeg -hide_banner -loglevel error -i '{in_filename}' -ar 16000 -ac 1 '{out_filename}' -y"
|
54 |
)
|
@@ -74,7 +80,7 @@ def process_url(
|
|
74 |
add_punct: str,
|
75 |
url: str,
|
76 |
):
|
77 |
-
|
78 |
with tempfile.NamedTemporaryFile() as f:
|
79 |
try:
|
80 |
urllib.request.urlretrieve(url, f.name)
|
@@ -88,7 +94,7 @@ def process_url(
|
|
88 |
add_punct=add_punct,
|
89 |
)
|
90 |
except Exception as e:
|
91 |
-
|
92 |
return "", build_html_output(str(e), "result_item_error")
|
93 |
|
94 |
|
@@ -107,7 +113,7 @@ def process_uploaded_file(
|
|
107 |
"result_item_error",
|
108 |
)
|
109 |
|
110 |
-
|
111 |
try:
|
112 |
return process(
|
113 |
in_filename=in_filename,
|
@@ -118,7 +124,7 @@ def process_uploaded_file(
|
|
118 |
add_punct=add_punct,
|
119 |
)
|
120 |
except Exception as e:
|
121 |
-
|
122 |
return "", build_html_output(str(e), "result_item_error")
|
123 |
|
124 |
|
@@ -138,7 +144,7 @@ def process_microphone(
|
|
138 |
"result_item_error",
|
139 |
)
|
140 |
|
141 |
-
|
142 |
try:
|
143 |
return process(
|
144 |
in_filename=in_filename,
|
@@ -149,7 +155,7 @@ def process_microphone(
|
|
149 |
add_punct=add_punct,
|
150 |
)
|
151 |
except Exception as e:
|
152 |
-
|
153 |
return "", build_html_output(str(e), "result_item_error")
|
154 |
|
155 |
|
@@ -162,17 +168,17 @@ def process(
|
|
162 |
add_punct: str,
|
163 |
in_filename: str,
|
164 |
):
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
|
171 |
filename = convert_to_wav(in_filename)
|
172 |
|
173 |
now = datetime.now()
|
174 |
date_time = now.strftime("%Y-%m-%d %H:%M:%S.%f")
|
175 |
-
|
176 |
|
177 |
start = time.time()
|
178 |
|
@@ -194,7 +200,7 @@ def process(
|
|
194 |
duration = metadata.num_frames / sample_rate
|
195 |
rtf = (end - start) / duration
|
196 |
|
197 |
-
|
198 |
|
199 |
info = f"""
|
200 |
Wave duration : {duration: .3f} s <br/>
|
@@ -207,8 +213,8 @@ def process(
|
|
207 |
"Please run again to measure the real RTF.<br/>"
|
208 |
)
|
209 |
|
210 |
-
|
211 |
-
|
212 |
|
213 |
return text, build_html_output(info)
|
214 |
|
|
|
43 |
languages = list(language_to_models.keys())
|
44 |
|
45 |
|
46 |
+
def MyPrint(s):
|
47 |
+
now = datetime.now()
|
48 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S.%f")
|
49 |
+
print(f"{date_time}: {s}")
|
50 |
+
|
51 |
+
|
52 |
def convert_to_wav(in_filename: str) -> str:
|
53 |
"""Convert the input audio file to a wave file"""
|
54 |
out_filename = str(uuid.uuid4())
|
55 |
out_filename = f"{in_filename}.wav"
|
56 |
|
57 |
+
MyPrint(f"Converting '{in_filename}' to '{out_filename}'")
|
58 |
_ = os.system(
|
59 |
f"ffmpeg -hide_banner -loglevel error -i '{in_filename}' -ar 16000 -ac 1 '{out_filename}' -y"
|
60 |
)
|
|
|
80 |
add_punct: str,
|
81 |
url: str,
|
82 |
):
|
83 |
+
MyPrint(f"Processing URL: {url}")
|
84 |
with tempfile.NamedTemporaryFile() as f:
|
85 |
try:
|
86 |
urllib.request.urlretrieve(url, f.name)
|
|
|
94 |
add_punct=add_punct,
|
95 |
)
|
96 |
except Exception as e:
|
97 |
+
MyPrint(str(e))
|
98 |
return "", build_html_output(str(e), "result_item_error")
|
99 |
|
100 |
|
|
|
113 |
"result_item_error",
|
114 |
)
|
115 |
|
116 |
+
MyPrint(f"Processing uploaded file: {in_filename}")
|
117 |
try:
|
118 |
return process(
|
119 |
in_filename=in_filename,
|
|
|
124 |
add_punct=add_punct,
|
125 |
)
|
126 |
except Exception as e:
|
127 |
+
MyPrint(str(e))
|
128 |
return "", build_html_output(str(e), "result_item_error")
|
129 |
|
130 |
|
|
|
144 |
"result_item_error",
|
145 |
)
|
146 |
|
147 |
+
MyPrint(f"Processing microphone: {in_filename}")
|
148 |
try:
|
149 |
return process(
|
150 |
in_filename=in_filename,
|
|
|
155 |
add_punct=add_punct,
|
156 |
)
|
157 |
except Exception as e:
|
158 |
+
MyPrint(str(e))
|
159 |
return "", build_html_output(str(e), "result_item_error")
|
160 |
|
161 |
|
|
|
168 |
add_punct: str,
|
169 |
in_filename: str,
|
170 |
):
|
171 |
+
MyPrint(f"language: {language}")
|
172 |
+
MyPrint(f"repo_id: {repo_id}")
|
173 |
+
MyPrint(f"decoding_method: {decoding_method}")
|
174 |
+
MyPrint(f"num_active_paths: {num_active_paths}")
|
175 |
+
MyPrint(f"in_filename: {in_filename}")
|
176 |
|
177 |
filename = convert_to_wav(in_filename)
|
178 |
|
179 |
now = datetime.now()
|
180 |
date_time = now.strftime("%Y-%m-%d %H:%M:%S.%f")
|
181 |
+
MyPrint(f"Started at {date_time}")
|
182 |
|
183 |
start = time.time()
|
184 |
|
|
|
200 |
duration = metadata.num_frames / sample_rate
|
201 |
rtf = (end - start) / duration
|
202 |
|
203 |
+
MyPrint(f"Finished at {date_time} s. Elapsed: {end - start: .3f} s")
|
204 |
|
205 |
info = f"""
|
206 |
Wave duration : {duration: .3f} s <br/>
|
|
|
213 |
"Please run again to measure the real RTF.<br/>"
|
214 |
)
|
215 |
|
216 |
+
MyPrint(info)
|
217 |
+
MyPrint(f"\nrepo_id: {repo_id}\nhyp: {text}")
|
218 |
|
219 |
return text, build_html_output(info)
|
220 |
|