Commit 8c83f30951f649bf94c535a8e2a2c392edffa027
1 parent
7d325c52
Exists in
master
and in
2 other branches
Recognizer gerando seus arquivos na pasta gtaaas_web de acordo seu ID.
Showing
6 changed files
with
65 additions
and
39 deletions
Show diff stats
.gitignore
main.cpp
... | ... | @@ -147,7 +147,8 @@ void serviceREC(char* path_video, char* sublanguage, |
147 | 147 | (int) atoi(sublanguage), |
148 | 148 | (int) atoi(position), |
149 | 149 | (int) atoi(size), |
150 | - (int) atoi(transparency), 3); | |
150 | + (int) atoi(transparency), | |
151 | + id, 3); | |
151 | 152 | |
152 | 153 | try{ |
153 | 154 | service_rec->initialize(); | ... | ... |
recognize/src/include/recognize.h
... | ... | @@ -16,8 +16,8 @@ class Recognize { |
16 | 16 | |
17 | 17 | public: |
18 | 18 | |
19 | - Recognize(char* _pathVideo); | |
20 | - Recognize(char* _pathVideo, int _inputType); | |
19 | + Recognize(char* _pathVideo, char* id); | |
20 | + Recognize(char* _pathVideo, int _inputType, char* id); | |
21 | 21 | ~Recognize(); |
22 | 22 | |
23 | 23 | /* |
... | ... | @@ -42,6 +42,7 @@ public: |
42 | 42 | private: |
43 | 43 | |
44 | 44 | char* pathVideo; |
45 | + string id; | |
45 | 46 | bool finished; |
46 | 47 | |
47 | 48 | float sizeScores; |
... | ... | @@ -63,5 +64,6 @@ private: |
63 | 64 | void confidenceJulius(); |
64 | 65 | void notifyListeners(char* text); |
65 | 66 | void cleanFiles(); |
67 | + void createDir(); | |
66 | 68 | |
67 | 69 | }; | ... | ... |
recognize/src/recognize.cpp
... | ... | @@ -8,6 +8,7 @@ |
8 | 8 | |
9 | 9 | #include <iostream> |
10 | 10 | #include <string> |
11 | +#include <sys/stat.h> | |
11 | 12 | |
12 | 13 | #include <lavidlib/io/FileIO.h> |
13 | 14 | |
... | ... | @@ -19,41 +20,47 @@ |
19 | 20 | #define SIZE_BUFFER 256 |
20 | 21 | #define CONFIDENCE_RATE 0.80 |
21 | 22 | |
22 | - | |
23 | -#define PATH_AUDIO_ORIGIN "gtaaas_user/gtaaas/recognize/src/audio/origin/audio_origin.wav" | |
24 | -#define PATH_AUDIO_PARTS "gtaaas_user/gtaaas/recognize/src/audio/parts/" | |
25 | -#define FILENAME_AUDIOPART "audio00" | |
26 | -#define FILENAME_AUDIOLIST "gtaaas_user/gtaaas/recognize/src/audio/audiolist" | |
27 | -#define FILENAME_FILTEROUT "gtaaas_user/gtaaas/recognize/src/audio/filter" | |
28 | -#define FILENAME_CONFIDENCEOUT "gtaaas_user/gtaaas/recognize/src/audio/confidence" | |
29 | -#define FILENAME_RECOGNIZED_OUT "gtaaas_user/gtaaas/recognize/src/audio/recognized.out" | |
23 | +#define PATH_GTAAAS_WEB "gtaaas_user/gtaaas_web/public/uploads/videos/" | |
24 | +#define PATH_AUDIO_ORIGIN "/audio/origin/audio_origin.wav" | |
25 | +#define PATH_AUDIO_PARTS "/audio/parts/" | |
26 | +#define FILENAME_RECOGNIZED_OUT "/audio/recognized.out" | |
27 | +#define FILENAME_AUDIOLIST "/audio/audiolist" | |
28 | +#define FILENAME_FILTEROUT "/audio/filter" | |
29 | +#define FILENAME_CONFIDENCEOUT "/audio/confidence" | |
30 | 30 | |
31 | 31 | #define FIND_CONFIDENCE "\"cmscore1:\"" |
32 | 32 | #define FIND_SENTENCE "\"pass1_best:\"" |
33 | 33 | |
34 | +#define FILENAME_AUDIOPART "audio00" | |
35 | + | |
34 | 36 | #define PROGRAM "ffmpeg" // ffmpeg |
35 | 37 | #define PTS_PATTERN 1000 |
36 | 38 | |
37 | 39 | using namespace std; |
38 | 40 | |
39 | 41 | |
40 | -Recognize::Recognize(char* _pathVideo) { | |
42 | +Recognize::Recognize(char* _pathVideo, char* _id) { | |
41 | 43 | |
42 | 44 | listeners = new list<RecognizeListener*>(); |
43 | 45 | pathVideo = _pathVideo; |
44 | 46 | inputType = INPUT_PATTERN; |
45 | 47 | frequency = FREQUENCY_PATTERN; |
46 | 48 | sizeBlocs = BLOCS_PATTERN; |
49 | + stringstream ss; | |
50 | + ss << _id; | |
51 | + ss >> id; | |
52 | + printf("ID: %s\n", id.c_str()); | |
47 | 53 | DPRINTF("Done!\n"); |
48 | 54 | } |
49 | 55 | |
50 | -Recognize::Recognize(char* _pathVideo, int _inputType) { | |
56 | +Recognize::Recognize(char* _pathVideo, int _inputType, char* _id) { | |
51 | 57 | |
52 | 58 | listeners = new list<RecognizeListener*>(); |
53 | 59 | pathVideo = _pathVideo; |
54 | 60 | inputType = _inputType; |
55 | 61 | frequency = FREQUENCY_PATTERN; |
56 | 62 | sizeBlocs = BLOCS_PATTERN; |
63 | + id = _id; | |
57 | 64 | DPRINTF("Done!\n"); |
58 | 65 | } |
59 | 66 | |
... | ... | @@ -79,6 +86,8 @@ void Recognize::initialize() { |
79 | 86 | |
80 | 87 | finished = false; |
81 | 88 | |
89 | + createDir(); | |
90 | + | |
82 | 91 | extractAudioFromVideo(); |
83 | 92 | |
84 | 93 | breakVideoParts(getTimeMediaSec()); |
... | ... | @@ -124,7 +133,10 @@ char* Recognize::extractAudioFromVideo() { |
124 | 133 | //command.append(strFreq).append(" -ac 1 -f wav ").append(PATH_AUDIO_ORIGIN).append(" &"); |
125 | 134 | command.append(strFreq). |
126 | 135 | append(" -ac 1 -f wav "). |
136 | + append(PATH_GTAAAS_WEB). | |
137 | + append(id). | |
127 | 138 | append(PATH_AUDIO_ORIGIN). |
139 | + | |
128 | 140 | append(" -v quiet"); |
129 | 141 | |
130 | 142 | /*string tmp = "echo "; |
... | ... | @@ -139,7 +151,7 @@ char* Recognize::extractAudioFromVideo() { |
139 | 151 | int Recognize::getTimeMediaSec() { |
140 | 152 | |
141 | 153 | string command = PROGRAM; |
142 | - command.append(" -i ").append(PATH_AUDIO_ORIGIN); | |
154 | + command.append(" -i ").append(PATH_GTAAAS_WEB).append(id).append(PATH_AUDIO_ORIGIN); | |
143 | 155 | command.append(" 2>&1 | grep Duration >> outfile"); |
144 | 156 | system(command.c_str()); |
145 | 157 | |
... | ... | @@ -171,7 +183,7 @@ void Recognize::breakVideoParts(int timeTotal) { |
171 | 183 | int t = 0; |
172 | 184 | bool consume = true; |
173 | 185 | |
174 | - string filename = FILENAME_AUDIOPART; | |
186 | + string filename= FILENAME_AUDIOPART; | |
175 | 187 | char tmp [filename.length()]; |
176 | 188 | sprintf(tmp, "%i", ss); |
177 | 189 | ss_str = tmp; |
... | ... | @@ -198,7 +210,7 @@ void Recognize::breakVideoParts(int timeTotal) { |
198 | 210 | ss_str = tmp; |
199 | 211 | |
200 | 212 | command = "sox "; |
201 | - command.append(PATH_AUDIO_ORIGIN).append(" ").append(PATH_AUDIO_PARTS); | |
213 | + command.append(PATH_GTAAAS_WEB).append(id).append(PATH_AUDIO_ORIGIN).append(" ").append(PATH_GTAAAS_WEB).append(id).append(PATH_AUDIO_PARTS); | |
202 | 214 | sprintf(tmp, "%i", count++); |
203 | 215 | filename.append(tmp).append(".wav"); |
204 | 216 | command.append(filename).append(" trim ").append(ss_str).append(" ").append(t_str); |
... | ... | @@ -206,7 +218,7 @@ void Recognize::breakVideoParts(int timeTotal) { |
206 | 218 | system(command.c_str()); |
207 | 219 | |
208 | 220 | string apcomm = "echo "; |
209 | - apcomm.append(PATH_AUDIO_PARTS).append(filename).append(" >> ").append(FILENAME_AUDIOLIST); | |
221 | + apcomm.append(PATH_GTAAAS_WEB).append(id).append(PATH_AUDIO_PARTS).append(filename).append(" >> ").append(PATH_GTAAAS_WEB).append(id).append(FILENAME_AUDIOLIST); | |
210 | 222 | system(apcomm.c_str()); |
211 | 223 | |
212 | 224 | filename = FILENAME_AUDIOPART; |
... | ... | @@ -225,7 +237,7 @@ void Recognize::executeJuliusEngine() { |
225 | 237 | command = "julius -C gtaaas_user/gtaaas/recognize/src/julius.jconf -input "; |
226 | 238 | if (inputType == 1) { |
227 | 239 | type = "rawfile"; |
228 | - command.append(type).append(" -filelist ").append(FILENAME_AUDIOLIST); | |
240 | + command.append(type).append(" -filelist ").append(PATH_GTAAAS_WEB).append(id).append(FILENAME_AUDIOLIST); | |
229 | 241 | } else { |
230 | 242 | type = "mic"; |
231 | 243 | } |
... | ... | @@ -233,6 +245,7 @@ void Recognize::executeJuliusEngine() { |
233 | 245 | command.append(" -smpFreq "). |
234 | 246 | append(cfreq). |
235 | 247 | append(" -nolog >> "). |
248 | + append(PATH_GTAAAS_WEB).append(id). | |
236 | 249 | append(FILENAME_RECOGNIZED_OUT); |
237 | 250 | |
238 | 251 | printf("\n\nCommand for executeJuliusEngine: %s\n", command.c_str()); |
... | ... | @@ -243,13 +256,15 @@ void Recognize::executeJuliusEngine() { |
243 | 256 | void Recognize::confidenceJulius() { |
244 | 257 | |
245 | 258 | string command = "cat "; |
246 | - command.append(FILENAME_RECOGNIZED_OUT).append(" | grep "). | |
247 | - append(FIND_CONFIDENCE).append(" >> ").append(FILENAME_CONFIDENCEOUT); | |
259 | + command.append(PATH_GTAAAS_WEB).append(id).append(FILENAME_RECOGNIZED_OUT).append(" | grep "). | |
260 | + append(FIND_CONFIDENCE).append(" >> ").append(PATH_GTAAAS_WEB).append(id).append(FILENAME_CONFIDENCEOUT); | |
248 | 261 | |
249 | 262 | system(command.c_str()); |
250 | 263 | printf("\n\n---> command: %s\n\n", command.c_str()); |
251 | 264 | |
252 | - ifstream in(FILENAME_CONFIDENCEOUT); | |
265 | + string path; | |
266 | + path.append(PATH_GTAAAS_WEB).append(id).append(FILENAME_CONFIDENCEOUT); | |
267 | + ifstream in(path.c_str()); | |
253 | 268 | |
254 | 269 | if (!in) { |
255 | 270 | perror("Error: "); |
... | ... | @@ -275,10 +290,13 @@ void Recognize::confidenceJulius() { |
275 | 290 | avgScores /= sizeScores; |
276 | 291 | } |
277 | 292 | |
293 | + cout << "Média: " << avgScores << endl; | |
278 | 294 | |
279 | - if (avgScores < CONFIDENCE_RATE) | |
295 | + if (avgScores < CONFIDENCE_RATE){ | |
280 | 296 | finished = true; |
281 | - throw RecognizeException("Desculpe, não podemos concluir pois o vídeo tem baixa qualidade. Tente novamente com outro vídeo."); | |
297 | + cleanFiles(); | |
298 | + throw RecognizeException("O vídeo selecionado tem baixa qualidade. Tente novamente com outro vídeo."); | |
299 | + } | |
282 | 300 | } |
283 | 301 | |
284 | 302 | |
... | ... | @@ -288,15 +306,17 @@ std::list<char*>* Recognize::filterOutputJulius() { |
288 | 306 | sentences = new std::list<char*>(); |
289 | 307 | |
290 | 308 | string command = "cat "; |
291 | - command.append(FILENAME_RECOGNIZED_OUT).append(" | grep "). | |
292 | - append(FIND_SENTENCE).append(" >> ").append(FILENAME_FILTEROUT); | |
309 | + command.append(PATH_GTAAAS_WEB).append(id).append(FILENAME_RECOGNIZED_OUT).append(" | grep "). | |
310 | + append(FIND_SENTENCE).append(" >> ").append(PATH_GTAAAS_WEB).append(id).append(FILENAME_FILTEROUT); | |
293 | 311 | |
294 | 312 | system(command.c_str()); |
295 | 313 | printf("\n\n---> command: %s\n\n", command.c_str()); |
296 | 314 | |
297 | 315 | int count_lines = 0; |
298 | 316 | |
299 | - ifstream in(FILENAME_FILTEROUT); | |
317 | + string path; | |
318 | + path.append(PATH_GTAAAS_WEB).append(id).append(FILENAME_CONFIDENCEOUT); | |
319 | + ifstream in(path.c_str()); | |
300 | 320 | string strFilter; |
301 | 321 | |
302 | 322 | if (!in) { |
... | ... | @@ -349,13 +369,16 @@ bool Recognize::isFinished() { |
349 | 369 | |
350 | 370 | void Recognize::cleanFiles() { |
351 | 371 | |
352 | - string command = "rm "; | |
353 | - command.append(PATH_AUDIO_ORIGIN).append(" "). | |
354 | - append(FILENAME_AUDIOLIST).append(" "). | |
355 | - append(FILENAME_FILTEROUT).append(" "). | |
356 | - append(FILENAME_CONFIDENCEOUT).append(" "). | |
357 | - append(PATH_AUDIO_PARTS).append("* "). | |
358 | - append(FILENAME_RECOGNIZED_OUT); | |
372 | + string command = "rm -r "; | |
373 | + command.append(PATH_GTAAAS_WEB).append(id).append("/audio"); | |
359 | 374 | system(command.c_str()); |
375 | +} | |
360 | 376 | |
377 | +void Recognize::createDir(){ | |
378 | + string command = "mkdir "; | |
379 | + command.append(PATH_GTAAAS_WEB).append(id).append("/audio").append(" && mkdir "). | |
380 | + append(PATH_GTAAAS_WEB).append(id).append("/audio/parts").append(" && mkdir "). | |
381 | + append(PATH_GTAAAS_WEB).append(id).append("/audio/origin"); | |
382 | + printf("%s\n", command.c_str()); | |
383 | + system(command.c_str()); | |
361 | 384 | } | ... | ... |
servico/src/include/serviceWindowGenerationFromREC.h
... | ... | @@ -17,10 +17,7 @@ private: |
17 | 17 | |
18 | 18 | public: |
19 | 19 | |
20 | - ServiceWindowGenerationFromREC( | |
21 | - char* path_video, int sublanguage, int position, int size, int transparency, int _serviceType); | |
22 | - | |
23 | - ServiceWindowGenerationFromREC(char* path_video, char* _video_path_file, int transparency, int _serviceType); | |
20 | + ServiceWindowGenerationFromREC(char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType); | |
24 | 21 | |
25 | 22 | ~ServiceWindowGenerationFromREC(); |
26 | 23 | void initialize(); | ... | ... |
servico/src/serviceWindowGenerationFromREC.cpp
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | using namespace std; |
4 | 4 | |
5 | 5 | ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( |
6 | - char* path_video, int sublanguage, int position, int size, int transparency, int _serviceType) { | |
6 | + char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType) { | |
7 | 7 | |
8 | 8 | path_input = path_video; |
9 | 9 | setSubLanguage(sublanguage); |
... | ... | @@ -11,6 +11,7 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( |
11 | 11 | setSize(size); |
12 | 12 | setTransparency(transparency); |
13 | 13 | setServiceType(_serviceType); |
14 | + rec = new Recognize(path_input, id); | |
14 | 15 | DPRINTF("Done!\n"); |
15 | 16 | } |
16 | 17 | |
... | ... | @@ -21,7 +22,6 @@ ServiceWindowGenerationFromREC::~ServiceWindowGenerationFromREC() { |
21 | 22 | } |
22 | 23 | |
23 | 24 | void ServiceWindowGenerationFromREC::initialize() { |
24 | - rec = new Recognize(path_input); | |
25 | 25 | rec->addListener(this); |
26 | 26 | |
27 | 27 | ServiceWindowGeneration::initialize(); | ... | ... |