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,7 +147,8 @@ void serviceREC(char* path_video, char* sublanguage, | ||
| 147 | (int) atoi(sublanguage), | 147 | (int) atoi(sublanguage), |
| 148 | (int) atoi(position), | 148 | (int) atoi(position), |
| 149 | (int) atoi(size), | 149 | (int) atoi(size), |
| 150 | - (int) atoi(transparency), 3); | 150 | + (int) atoi(transparency), |
| 151 | + id, 3); | ||
| 151 | 152 | ||
| 152 | try{ | 153 | try{ |
| 153 | service_rec->initialize(); | 154 | service_rec->initialize(); |
recognize/src/include/recognize.h
| @@ -16,8 +16,8 @@ class Recognize { | @@ -16,8 +16,8 @@ class Recognize { | ||
| 16 | 16 | ||
| 17 | public: | 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 | ~Recognize(); | 21 | ~Recognize(); |
| 22 | 22 | ||
| 23 | /* | 23 | /* |
| @@ -42,6 +42,7 @@ public: | @@ -42,6 +42,7 @@ public: | ||
| 42 | private: | 42 | private: |
| 43 | 43 | ||
| 44 | char* pathVideo; | 44 | char* pathVideo; |
| 45 | + string id; | ||
| 45 | bool finished; | 46 | bool finished; |
| 46 | 47 | ||
| 47 | float sizeScores; | 48 | float sizeScores; |
| @@ -63,5 +64,6 @@ private: | @@ -63,5 +64,6 @@ private: | ||
| 63 | void confidenceJulius(); | 64 | void confidenceJulius(); |
| 64 | void notifyListeners(char* text); | 65 | void notifyListeners(char* text); |
| 65 | void cleanFiles(); | 66 | void cleanFiles(); |
| 67 | + void createDir(); | ||
| 66 | 68 | ||
| 67 | }; | 69 | }; |
recognize/src/recognize.cpp
| @@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
| 8 | 8 | ||
| 9 | #include <iostream> | 9 | #include <iostream> |
| 10 | #include <string> | 10 | #include <string> |
| 11 | +#include <sys/stat.h> | ||
| 11 | 12 | ||
| 12 | #include <lavidlib/io/FileIO.h> | 13 | #include <lavidlib/io/FileIO.h> |
| 13 | 14 | ||
| @@ -19,41 +20,47 @@ | @@ -19,41 +20,47 @@ | ||
| 19 | #define SIZE_BUFFER 256 | 20 | #define SIZE_BUFFER 256 |
| 20 | #define CONFIDENCE_RATE 0.80 | 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 | #define FIND_CONFIDENCE "\"cmscore1:\"" | 31 | #define FIND_CONFIDENCE "\"cmscore1:\"" |
| 32 | #define FIND_SENTENCE "\"pass1_best:\"" | 32 | #define FIND_SENTENCE "\"pass1_best:\"" |
| 33 | 33 | ||
| 34 | +#define FILENAME_AUDIOPART "audio00" | ||
| 35 | + | ||
| 34 | #define PROGRAM "ffmpeg" // ffmpeg | 36 | #define PROGRAM "ffmpeg" // ffmpeg |
| 35 | #define PTS_PATTERN 1000 | 37 | #define PTS_PATTERN 1000 |
| 36 | 38 | ||
| 37 | using namespace std; | 39 | using namespace std; |
| 38 | 40 | ||
| 39 | 41 | ||
| 40 | -Recognize::Recognize(char* _pathVideo) { | 42 | +Recognize::Recognize(char* _pathVideo, char* _id) { |
| 41 | 43 | ||
| 42 | listeners = new list<RecognizeListener*>(); | 44 | listeners = new list<RecognizeListener*>(); |
| 43 | pathVideo = _pathVideo; | 45 | pathVideo = _pathVideo; |
| 44 | inputType = INPUT_PATTERN; | 46 | inputType = INPUT_PATTERN; |
| 45 | frequency = FREQUENCY_PATTERN; | 47 | frequency = FREQUENCY_PATTERN; |
| 46 | sizeBlocs = BLOCS_PATTERN; | 48 | sizeBlocs = BLOCS_PATTERN; |
| 49 | + stringstream ss; | ||
| 50 | + ss << _id; | ||
| 51 | + ss >> id; | ||
| 52 | + printf("ID: %s\n", id.c_str()); | ||
| 47 | DPRINTF("Done!\n"); | 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 | listeners = new list<RecognizeListener*>(); | 58 | listeners = new list<RecognizeListener*>(); |
| 53 | pathVideo = _pathVideo; | 59 | pathVideo = _pathVideo; |
| 54 | inputType = _inputType; | 60 | inputType = _inputType; |
| 55 | frequency = FREQUENCY_PATTERN; | 61 | frequency = FREQUENCY_PATTERN; |
| 56 | sizeBlocs = BLOCS_PATTERN; | 62 | sizeBlocs = BLOCS_PATTERN; |
| 63 | + id = _id; | ||
| 57 | DPRINTF("Done!\n"); | 64 | DPRINTF("Done!\n"); |
| 58 | } | 65 | } |
| 59 | 66 | ||
| @@ -79,6 +86,8 @@ void Recognize::initialize() { | @@ -79,6 +86,8 @@ void Recognize::initialize() { | ||
| 79 | 86 | ||
| 80 | finished = false; | 87 | finished = false; |
| 81 | 88 | ||
| 89 | + createDir(); | ||
| 90 | + | ||
| 82 | extractAudioFromVideo(); | 91 | extractAudioFromVideo(); |
| 83 | 92 | ||
| 84 | breakVideoParts(getTimeMediaSec()); | 93 | breakVideoParts(getTimeMediaSec()); |
| @@ -124,7 +133,10 @@ char* Recognize::extractAudioFromVideo() { | @@ -124,7 +133,10 @@ char* Recognize::extractAudioFromVideo() { | ||
| 124 | //command.append(strFreq).append(" -ac 1 -f wav ").append(PATH_AUDIO_ORIGIN).append(" &"); | 133 | //command.append(strFreq).append(" -ac 1 -f wav ").append(PATH_AUDIO_ORIGIN).append(" &"); |
| 125 | command.append(strFreq). | 134 | command.append(strFreq). |
| 126 | append(" -ac 1 -f wav "). | 135 | append(" -ac 1 -f wav "). |
| 136 | + append(PATH_GTAAAS_WEB). | ||
| 137 | + append(id). | ||
| 127 | append(PATH_AUDIO_ORIGIN). | 138 | append(PATH_AUDIO_ORIGIN). |
| 139 | + | ||
| 128 | append(" -v quiet"); | 140 | append(" -v quiet"); |
| 129 | 141 | ||
| 130 | /*string tmp = "echo "; | 142 | /*string tmp = "echo "; |
| @@ -139,7 +151,7 @@ char* Recognize::extractAudioFromVideo() { | @@ -139,7 +151,7 @@ char* Recognize::extractAudioFromVideo() { | ||
| 139 | int Recognize::getTimeMediaSec() { | 151 | int Recognize::getTimeMediaSec() { |
| 140 | 152 | ||
| 141 | string command = PROGRAM; | 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 | command.append(" 2>&1 | grep Duration >> outfile"); | 155 | command.append(" 2>&1 | grep Duration >> outfile"); |
| 144 | system(command.c_str()); | 156 | system(command.c_str()); |
| 145 | 157 | ||
| @@ -171,7 +183,7 @@ void Recognize::breakVideoParts(int timeTotal) { | @@ -171,7 +183,7 @@ void Recognize::breakVideoParts(int timeTotal) { | ||
| 171 | int t = 0; | 183 | int t = 0; |
| 172 | bool consume = true; | 184 | bool consume = true; |
| 173 | 185 | ||
| 174 | - string filename = FILENAME_AUDIOPART; | 186 | + string filename= FILENAME_AUDIOPART; |
| 175 | char tmp [filename.length()]; | 187 | char tmp [filename.length()]; |
| 176 | sprintf(tmp, "%i", ss); | 188 | sprintf(tmp, "%i", ss); |
| 177 | ss_str = tmp; | 189 | ss_str = tmp; |
| @@ -198,7 +210,7 @@ void Recognize::breakVideoParts(int timeTotal) { | @@ -198,7 +210,7 @@ void Recognize::breakVideoParts(int timeTotal) { | ||
| 198 | ss_str = tmp; | 210 | ss_str = tmp; |
| 199 | 211 | ||
| 200 | command = "sox "; | 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 | sprintf(tmp, "%i", count++); | 214 | sprintf(tmp, "%i", count++); |
| 203 | filename.append(tmp).append(".wav"); | 215 | filename.append(tmp).append(".wav"); |
| 204 | command.append(filename).append(" trim ").append(ss_str).append(" ").append(t_str); | 216 | command.append(filename).append(" trim ").append(ss_str).append(" ").append(t_str); |
| @@ -206,7 +218,7 @@ void Recognize::breakVideoParts(int timeTotal) { | @@ -206,7 +218,7 @@ void Recognize::breakVideoParts(int timeTotal) { | ||
| 206 | system(command.c_str()); | 218 | system(command.c_str()); |
| 207 | 219 | ||
| 208 | string apcomm = "echo "; | 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 | system(apcomm.c_str()); | 222 | system(apcomm.c_str()); |
| 211 | 223 | ||
| 212 | filename = FILENAME_AUDIOPART; | 224 | filename = FILENAME_AUDIOPART; |
| @@ -225,7 +237,7 @@ void Recognize::executeJuliusEngine() { | @@ -225,7 +237,7 @@ void Recognize::executeJuliusEngine() { | ||
| 225 | command = "julius -C gtaaas_user/gtaaas/recognize/src/julius.jconf -input "; | 237 | command = "julius -C gtaaas_user/gtaaas/recognize/src/julius.jconf -input "; |
| 226 | if (inputType == 1) { | 238 | if (inputType == 1) { |
| 227 | type = "rawfile"; | 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 | } else { | 241 | } else { |
| 230 | type = "mic"; | 242 | type = "mic"; |
| 231 | } | 243 | } |
| @@ -233,6 +245,7 @@ void Recognize::executeJuliusEngine() { | @@ -233,6 +245,7 @@ void Recognize::executeJuliusEngine() { | ||
| 233 | command.append(" -smpFreq "). | 245 | command.append(" -smpFreq "). |
| 234 | append(cfreq). | 246 | append(cfreq). |
| 235 | append(" -nolog >> "). | 247 | append(" -nolog >> "). |
| 248 | + append(PATH_GTAAAS_WEB).append(id). | ||
| 236 | append(FILENAME_RECOGNIZED_OUT); | 249 | append(FILENAME_RECOGNIZED_OUT); |
| 237 | 250 | ||
| 238 | printf("\n\nCommand for executeJuliusEngine: %s\n", command.c_str()); | 251 | printf("\n\nCommand for executeJuliusEngine: %s\n", command.c_str()); |
| @@ -243,13 +256,15 @@ void Recognize::executeJuliusEngine() { | @@ -243,13 +256,15 @@ void Recognize::executeJuliusEngine() { | ||
| 243 | void Recognize::confidenceJulius() { | 256 | void Recognize::confidenceJulius() { |
| 244 | 257 | ||
| 245 | string command = "cat "; | 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 | system(command.c_str()); | 262 | system(command.c_str()); |
| 250 | printf("\n\n---> command: %s\n\n", command.c_str()); | 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 | if (!in) { | 269 | if (!in) { |
| 255 | perror("Error: "); | 270 | perror("Error: "); |
| @@ -275,10 +290,13 @@ void Recognize::confidenceJulius() { | @@ -275,10 +290,13 @@ void Recognize::confidenceJulius() { | ||
| 275 | avgScores /= sizeScores; | 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 | finished = true; | 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,15 +306,17 @@ std::list<char*>* Recognize::filterOutputJulius() { | ||
| 288 | sentences = new std::list<char*>(); | 306 | sentences = new std::list<char*>(); |
| 289 | 307 | ||
| 290 | string command = "cat "; | 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 | system(command.c_str()); | 312 | system(command.c_str()); |
| 295 | printf("\n\n---> command: %s\n\n", command.c_str()); | 313 | printf("\n\n---> command: %s\n\n", command.c_str()); |
| 296 | 314 | ||
| 297 | int count_lines = 0; | 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 | string strFilter; | 320 | string strFilter; |
| 301 | 321 | ||
| 302 | if (!in) { | 322 | if (!in) { |
| @@ -349,13 +369,16 @@ bool Recognize::isFinished() { | @@ -349,13 +369,16 @@ bool Recognize::isFinished() { | ||
| 349 | 369 | ||
| 350 | void Recognize::cleanFiles() { | 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 | system(command.c_str()); | 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,10 +17,7 @@ private: | ||
| 17 | 17 | ||
| 18 | public: | 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 | ~ServiceWindowGenerationFromREC(); | 22 | ~ServiceWindowGenerationFromREC(); |
| 26 | void initialize(); | 23 | void initialize(); |
servico/src/serviceWindowGenerationFromREC.cpp
| @@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
| 3 | using namespace std; | 3 | using namespace std; |
| 4 | 4 | ||
| 5 | ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( | 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 | path_input = path_video; | 8 | path_input = path_video; |
| 9 | setSubLanguage(sublanguage); | 9 | setSubLanguage(sublanguage); |
| @@ -11,6 +11,7 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( | @@ -11,6 +11,7 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( | ||
| 11 | setSize(size); | 11 | setSize(size); |
| 12 | setTransparency(transparency); | 12 | setTransparency(transparency); |
| 13 | setServiceType(_serviceType); | 13 | setServiceType(_serviceType); |
| 14 | + rec = new Recognize(path_input, id); | ||
| 14 | DPRINTF("Done!\n"); | 15 | DPRINTF("Done!\n"); |
| 15 | } | 16 | } |
| 16 | 17 | ||
| @@ -21,7 +22,6 @@ ServiceWindowGenerationFromREC::~ServiceWindowGenerationFromREC() { | @@ -21,7 +22,6 @@ ServiceWindowGenerationFromREC::~ServiceWindowGenerationFromREC() { | ||
| 21 | } | 22 | } |
| 22 | 23 | ||
| 23 | void ServiceWindowGenerationFromREC::initialize() { | 24 | void ServiceWindowGenerationFromREC::initialize() { |
| 24 | - rec = new Recognize(path_input); | ||
| 25 | rec->addListener(this); | 25 | rec->addListener(this); |
| 26 | 26 | ||
| 27 | ServiceWindowGeneration::initialize(); | 27 | ServiceWindowGeneration::initialize(); |