Commit 5195b02a2662263d0f8787453017aac450cb4c2e
1 parent
b886dc37
Exists in
master
and in
1 other branch
Adiciona reconhecimento de voz pelo Google [DEFAULT]
Showing
11 changed files
with
552 additions
and
24 deletions
Show diff stats
Makefile
| ... | ... | @@ -4,17 +4,18 @@ REVISION=`svn info |grep Rev | sed 2d | cut -d" " -f2` |
| 4 | 4 | CC=g++ |
| 5 | 5 | FLAGS=-g |
| 6 | 6 | |
| 7 | -#LIBS= -L libs/jthread/lib -L libs/jcommon/lib -L libs/jsocket/lib -ljthread -lpthread -ljcommon -ljsocket | |
| 8 | - | |
| 9 | 7 | LIBS= \ |
| 10 | - `pkg-config --cflags jlibcpp` \ | |
| 11 | 8 | `pkg-config --libs jlibcpp` \ |
| 12 | - `pkg-config --cflags jsoncpp` \ | |
| 13 | 9 | `pkg-config --libs jsoncpp` \ |
| 14 | - -lpython2.7 -llavid_base -llavid_io -llavid_net | |
| 10 | + -lpython2.7 -llavid_base -llavid_io -llavid_net \ | |
| 11 | + -ljulius -ldl -lsent | |
| 15 | 12 | |
| 16 | 13 | INCLUDES= \ |
| 14 | + `pkg-config --cflags jlibcpp` \ | |
| 15 | + `pkg-config --cflags jsoncpp` \ | |
| 17 | 16 | -I /usr/include/python2.7 \ |
| 17 | + -I /usr/include/julius \ | |
| 18 | + -I /usr/include/sent \ | |
| 18 | 19 | -I util/src/include \ |
| 19 | 20 | -I tradutor/src/include \ |
| 20 | 21 | -I extrator/src/include \ |
| ... | ... | @@ -23,8 +24,7 @@ INCLUDES= \ |
| 23 | 24 | -I synchronizer/src/include \ |
| 24 | 25 | -I renderer/src/include \ |
| 25 | 26 | -I mixer/src/include \ |
| 26 | - -I recognize/src/include | |
| 27 | -#-I libs/jthread/include -I libs/jcommon/include -I libs/jsocket/include -Wall | |
| 27 | + -I recognize/src/include | |
| 28 | 28 | |
| 29 | 29 | utilObjs= \ |
| 30 | 30 | logger.o |
| ... | ... | @@ -58,7 +58,10 @@ mixerObjs= \ |
| 58 | 58 | |
| 59 | 59 | recognizeObjs = \ |
| 60 | 60 | recognize.o \ |
| 61 | - recognizeException.o | |
| 61 | + recognizeException.o \ | |
| 62 | + wavcut.o \ | |
| 63 | + audiofile.o \ | |
| 64 | + recognizer.o | |
| 62 | 65 | |
| 63 | 66 | utilObjsPre = $(addprefix util/src/,$(utilObjs) ) |
| 64 | 67 | tradutorObjsPre = $(addprefix tradutor/src/,$(tradutorObjs) ) |
| ... | ... | @@ -79,6 +82,7 @@ OBJECTS = \ |
| 79 | 82 | $(rendererObjsPre) \ |
| 80 | 83 | $(mixerObjsPre) \ |
| 81 | 84 | $(recognizeObjsPre) \ |
| 85 | + $(wavcutObjsPre) $(grecognizerObjsPre) \ | |
| 82 | 86 | main.o |
| 83 | 87 | |
| 84 | 88 | all: user_config libras |
| ... | ... | @@ -91,7 +95,7 @@ user_config: |
| 91 | 95 | fi |
| 92 | 96 | |
| 93 | 97 | libras: $(OBJECTS) |
| 94 | - $(CC) -o vlibras $(OBJECTS) $(LIBS) $(INCLUDES) $(FLAGS) | |
| 98 | + $(CC) $(INCLUDES) -o vlibras $(OBJECTS) $(LIBS) $(FLAGS) | |
| 95 | 99 | |
| 96 | 100 | |
| 97 | 101 | .c.o: $< | ... | ... |
| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | +#include "audiofile.h" | |
| 2 | + | |
| 3 | +Audiofile::Audiofile(char *_file_path,float _start_seg,float _end_seg){ | |
| 4 | + | |
| 5 | + file_path = _file_path; | |
| 6 | + start_seg = _start_seg; | |
| 7 | + end_seg = _end_seg; | |
| 8 | +} | |
| 9 | + | |
| 10 | +Audiofile::~Audiofile(){ | |
| 11 | + | |
| 12 | + | |
| 13 | +} | |
| 0 | 14 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | +#ifndef AUDIOFILE_H | |
| 2 | +#define AUDIOFILE_H | |
| 3 | + | |
| 4 | +class Audiofile | |
| 5 | +{ | |
| 6 | + | |
| 7 | +public: | |
| 8 | + | |
| 9 | + Audiofile(char *_file_path,float _start_seg,float _end_seg); | |
| 10 | + ~Audiofile(); | |
| 11 | + | |
| 12 | + char* file_path; | |
| 13 | + float start_seg; | |
| 14 | + float end_seg; | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | +}; | |
| 20 | + | |
| 21 | +#endif // AUDIOFILE_H | |
| 0 | 22 | \ No newline at end of file | ... | ... |
recognize/src/include/recognize.h
| 1 | +#ifndef RECOGNIZE_H | |
| 2 | +#define RECOGNIZE_H | |
| 3 | + | |
| 4 | + | |
| 1 | 5 | #include "jthread.h" |
| 2 | 6 | #include <iostream> |
| 3 | 7 | #include <stdlib.h> |
| ... | ... | @@ -17,13 +21,18 @@ |
| 17 | 21 | #include "recognizeListener.h" |
| 18 | 22 | #include "recognizeException.h" |
| 19 | 23 | |
| 24 | +#include "wavcut.h" | |
| 25 | +#include "recognizer.h" | |
| 26 | + | |
| 20 | 27 | #define FREQUENCY_PATTERN 22050 |
| 21 | 28 | #define INPUT_PATTERN 1 /* 1 = Raw file, 2 = Mic */ |
| 22 | 29 | #define BLOCS_PATTERN 10 |
| 23 | 30 | #define SIZE_BUFFER 256 |
| 24 | 31 | #define CONFIDENCE_RATE 0.10 |
| 25 | 32 | |
| 33 | +#define RECOGNIZER_MODE 1 // 0 = Julius, 1 = Google | |
| 26 | 34 | #define PATH_JCONFIG "vlibras_user/vlibras-core/recognize/src/julius.jconf" |
| 35 | +#define PATH_WCONFIG "vlibras_user/vlibras-core/recognize/src/wavcut.jconf" | |
| 27 | 36 | #define PATH_AUDIO_ORIGIN "/audio/origin/audio_origin.wav" |
| 28 | 37 | #define PATH_AUDIO_PARTS "/audio/parts/" |
| 29 | 38 | #define FILENAME_RECOGNIZED_OUT "/audio/recognized.out" |
| ... | ... | @@ -110,4 +119,9 @@ private: |
| 110 | 119 | int64_t calcula_pts(double msec); |
| 111 | 120 | int64_t convert_pts(string pts); |
| 112 | 121 | |
| 122 | + void executeGoogleEngine(); | |
| 123 | + Jconf* load_config(); | |
| 124 | + | |
| 113 | 125 | }; |
| 126 | + | |
| 127 | +#endif // RECOGNIZE_H | |
| 114 | 128 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,37 @@ |
| 1 | +#ifndef RECOGNIZER_H | |
| 2 | +#define RECOGNIZER_H | |
| 3 | + | |
| 4 | +#include <julius/juliuslib.h> | |
| 5 | +#include <iostream> | |
| 6 | +#include <sstream> | |
| 7 | +#include <sys/stat.h> | |
| 8 | +#include <fstream> | |
| 9 | +#include <iostream> | |
| 10 | +#include <string.h> | |
| 11 | +#include <stdio.h> | |
| 12 | +#include <stdlib.h> | |
| 13 | +#include <string> | |
| 14 | +#include <list> | |
| 15 | +#include <stdint.h> | |
| 16 | + | |
| 17 | +using namespace std; | |
| 18 | + | |
| 19 | +class Recognizer | |
| 20 | +{ | |
| 21 | + | |
| 22 | +public: | |
| 23 | + Recognizer(); | |
| 24 | + ~Recognizer(); | |
| 25 | + int recognize(string file_in); | |
| 26 | + string getsentence(); | |
| 27 | + float getconfidence(); | |
| 28 | + | |
| 29 | + | |
| 30 | +private: | |
| 31 | + | |
| 32 | + Jconf *jconf; | |
| 33 | + Recog *recog; | |
| 34 | + | |
| 35 | +}; | |
| 36 | + | |
| 37 | +#endif // RECOGNIZER_H | ... | ... |
| ... | ... | @@ -0,0 +1,30 @@ |
| 1 | +#ifndef WAVCUT_H | |
| 2 | +#define WAVCUT_H | |
| 3 | + | |
| 4 | +#include <julius/juliuslib.h> | |
| 5 | +#include <string> | |
| 6 | +#include <algorithm> | |
| 7 | +#undef min | |
| 8 | +#undef max | |
| 9 | +#include <vector> | |
| 10 | +#include "audiofile.h" | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | +using namespace std; | |
| 15 | +class Wavcut{ | |
| 16 | + | |
| 17 | +public: | |
| 18 | + | |
| 19 | + Wavcut(char* _pathAudio, char* _outputPath, char* _id); | |
| 20 | + ~Wavcut(); | |
| 21 | + | |
| 22 | + int initialize(Jconf *jconf); | |
| 23 | + vector<Audiofile> list_audio_files(); | |
| 24 | + int count_lines; | |
| 25 | + | |
| 26 | +private: | |
| 27 | + static int adin_callback_file(SP16 *now, int len, Recog *recog); | |
| 28 | +}; | |
| 29 | + | |
| 30 | +#endif // WAVCUT_H | |
| 0 | 31 | \ No newline at end of file | ... | ... |
recognize/src/recognize.cpp
| ... | ... | @@ -68,14 +68,17 @@ void Recognize::Run(){ |
| 68 | 68 | finish = false; |
| 69 | 69 | createDir(); |
| 70 | 70 | extractAudioFromVideo(); |
| 71 | - breakVideoParts(getTimeMediaSec()); | |
| 72 | - executeJuliusEngine(); | |
| 73 | - generateConfidence(); | |
| 74 | - //filterOutputJulius(); | |
| 75 | - //cleanFiles(); | |
| 76 | - | |
| 71 | + if (RECOGNIZER_MODE == 0){ | |
| 72 | + breakVideoParts(getTimeMediaSec()); | |
| 73 | + executeJuliusEngine(); | |
| 74 | + generateConfidence(); | |
| 75 | + } else { | |
| 76 | + executeGoogleEngine(); | |
| 77 | + } | |
| 78 | + | |
| 77 | 79 | finish = true; |
| 78 | - //notifyEndExtraction(count_lines); | |
| 80 | + notifyEndExtraction(count_lines); | |
| 81 | + cleanFiles(); | |
| 79 | 82 | } |
| 80 | 83 | |
| 81 | 84 | void Recognize::setFrequency(int freq) { |
| ... | ... | @@ -209,7 +212,7 @@ void Recognize::breakVideoParts(int timeTotal) { |
| 209 | 212 | void Recognize::executeJuliusEngine() { |
| 210 | 213 | |
| 211 | 214 | string type, freqStr; |
| 212 | - string command = "julius -C "; | |
| 215 | + string command = "julius -quiet -C "; | |
| 213 | 216 | char cfreq[10]; |
| 214 | 217 | |
| 215 | 218 | char* jPath; |
| ... | ... | @@ -292,14 +295,12 @@ void Recognize::generateConfidence() { |
| 292 | 295 | scores.push_back(avgScores/sizeAvgScores); |
| 293 | 296 | |
| 294 | 297 | }else if(pass==0){ |
| 295 | - notifyListeners((char*) "SENTENCA COM BAIXA QUALIDADE", 0); | |
| 296 | - notifyEndExtraction(count_lines); | |
| 298 | + notifyListeners((char*) "SENTENCA_COM_BAIXA_QUALIDADE", 0); | |
| 297 | 299 | return; |
| 298 | 300 | } |
| 299 | 301 | } while (!in.eof()); |
| 300 | 302 | in.close(); |
| 301 | 303 | filterOutputJulius(); |
| 302 | - notifyEndExtraction(count_lines); | |
| 303 | 304 | } |
| 304 | 305 | } |
| 305 | 306 | |
| ... | ... | @@ -420,3 +421,100 @@ void Recognize::createDir(){ |
| 420 | 421 | .append(" && mkdir -p ").append(path_contents).append("/").append(id).append("/audio/origin"); |
| 421 | 422 | system(command.c_str()); |
| 422 | 423 | } |
| 424 | + | |
| 425 | +void Recognize::executeGoogleEngine() { | |
| 426 | + jlog_set_output(NULL); | |
| 427 | + | |
| 428 | + Wavcut* wavcut; | |
| 429 | + Recognizer* recog; | |
| 430 | + | |
| 431 | + vector<Audiofile> audioList; | |
| 432 | + string file_in = ""; | |
| 433 | + file_in.append(path_contents).append("/").append(id).append(PATH_AUDIO_ORIGIN); | |
| 434 | + string path_out= ""; | |
| 435 | + path_out.append(path_contents).append("/").append(id).append("/"); | |
| 436 | + char* pathAudio = new char[file_in.size()+1]; | |
| 437 | + char* outputPath = new char[path_out.size()+1]; | |
| 438 | + char* _id = new char[id.size()+1]; | |
| 439 | + strcpy(pathAudio, file_in.c_str()); | |
| 440 | + strcpy(outputPath, path_out.c_str()); | |
| 441 | + strcpy(_id, id.c_str()); | |
| 442 | + | |
| 443 | + | |
| 444 | + wavcut = new Wavcut(pathAudio,outputPath,_id); | |
| 445 | + Jconf *jconf; | |
| 446 | + jconf = j_config_load_file_new(PATH_WCONFIG); | |
| 447 | + | |
| 448 | + if(wavcut->initialize(jconf)<2){ | |
| 449 | + | |
| 450 | + wavcut->initialize(load_config()); | |
| 451 | + } | |
| 452 | + | |
| 453 | + audioList = wavcut->list_audio_files(); | |
| 454 | + | |
| 455 | + | |
| 456 | + delete wavcut; | |
| 457 | + recog = new Recognizer(); | |
| 458 | + | |
| 459 | + int ii; | |
| 460 | + count_lines = 0; | |
| 461 | + for(ii=0; ii < audioList.size(); ii++) | |
| 462 | + { | |
| 463 | + | |
| 464 | + /*chama o reconhecedor passando cada arquivo de audio*/ | |
| 465 | + recog->recognize(audioList[ii].file_path); | |
| 466 | + | |
| 467 | + /*remove o audio ja reconhecido*/ | |
| 468 | + remove(audioList[ii].file_path); | |
| 469 | + | |
| 470 | + /*segundos do inicio do audio reconhecido*/ | |
| 471 | + //cout<< calcula_pts(audioList[ii].start_seg) << endl; | |
| 472 | + | |
| 473 | + /* texto do audio reconhecido*/ | |
| 474 | + //cout<< recog->getsentence() << endl; | |
| 475 | + | |
| 476 | + /* porcentagem de confiança do reconhecimento (de 0 a 1) */ | |
| 477 | + //cout<< recog->getconfidence() << endl; | |
| 478 | + | |
| 479 | + if(recog->getconfidence() >= confidenceRate) | |
| 480 | + notifyListeners((char*)recog->getsentence().c_str(), (int64_t)(audioList[ii].start_seg*1000)); | |
| 481 | + else | |
| 482 | + notifyListeners((char*) "SENTENCA_COM_BAIXA_QUALIDADE", (int64_t)(audioList[ii].start_seg*1000)); | |
| 483 | + if(recog->getconfidence()> 0) | |
| 484 | + count_lines++; | |
| 485 | + } | |
| 486 | + delete recog; | |
| 487 | + | |
| 488 | +} | |
| 489 | + | |
| 490 | +Jconf* Recognize::load_config(){ | |
| 491 | + | |
| 492 | + Jconf* jconf; | |
| 493 | + jconf = j_jconf_new(); | |
| 494 | + | |
| 495 | + char *parametros[12]; | |
| 496 | + | |
| 497 | + parametros[1]="-lv"; | |
| 498 | + parametros[2]="3000"; | |
| 499 | + parametros[3]="-zc"; | |
| 500 | + parametros[4]="150"; | |
| 501 | + parametros[5]="-headmargin"; | |
| 502 | + parametros[6]="200"; | |
| 503 | + parametros[7]="-tailmargin"; | |
| 504 | + parametros[8]="150"; | |
| 505 | + parametros[9]="-rejectshort"; | |
| 506 | + parametros[10]="1500"; | |
| 507 | + //cout << "load_config" << endl; | |
| 508 | + /* read arguments and set parameters */ | |
| 509 | + if (j_config_load_args(jconf, 11, parametros) == -1) { | |
| 510 | + fprintf(stderr, "Error reading arguments\n"); | |
| 511 | + | |
| 512 | + } | |
| 513 | + | |
| 514 | + jconf->input.type = INPUT_WAVEFORM; | |
| 515 | + jconf->input.speech_input = SP_RAWFILE; | |
| 516 | + jconf->detect.silence_cut = 1; | |
| 517 | + | |
| 518 | + | |
| 519 | +return jconf; | |
| 520 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,101 @@ |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | +#include "recognizer.h" | |
| 5 | +#include <json/json.h> | |
| 6 | + | |
| 7 | + | |
| 8 | +static boolean reconhecendo ; | |
| 9 | +static string sentence; | |
| 10 | +static float confidence; | |
| 11 | +string lenguage = "pt-BR"; | |
| 12 | + | |
| 13 | +using namespace std; | |
| 14 | + | |
| 15 | + | |
| 16 | +void resultado(Recog *recog, void *dummy); | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | +Recognizer::Recognizer(){ | |
| 21 | + | |
| 22 | +} | |
| 23 | + | |
| 24 | + | |
| 25 | +Recognizer::~Recognizer(){ | |
| 26 | + | |
| 27 | +} | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | +int Recognizer::recognize(string file_in) | |
| 32 | +{ | |
| 33 | + FILE *file; | |
| 34 | + string cmFinal; | |
| 35 | + char message[100]; | |
| 36 | + message[0] = '\0'; | |
| 37 | + string jsonResult =""; | |
| 38 | + string vozReconhecida = ""; | |
| 39 | + int indexLineSrt =0; | |
| 40 | + stringstream comand; | |
| 41 | + stringstream index; | |
| 42 | + | |
| 43 | + | |
| 44 | + string fileName = file_in; | |
| 45 | + | |
| 46 | + // inicio preparação requisição | |
| 47 | + | |
| 48 | + comand << " curl -ss -X POST --data-binary @"; | |
| 49 | + comand << fileName; | |
| 50 | + | |
| 51 | + //requisição para o google speech | |
| 52 | + comand<< " --user-agent 'Mozilla/5.0' --header 'Content-Type: audio/l16; rate=22050;' 'https://www.google.com/speech-api/v2/recognize?client=chromium&lang="<<lenguage<<"&maxresults=1&key=AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw'"; | |
| 53 | + //AIzaSyBeeYW4l2OuCwiUfzBaUXXeWAO6Uy-u0F8'"; | |
| 54 | + //public key Ezequiel project 1 | |
| 55 | + //AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw'"; | |
| 56 | + //fim | |
| 57 | + cmFinal = comand.str(); | |
| 58 | + file = popen(cmFinal.c_str(),"r"); | |
| 59 | + if(file == NULL) | |
| 60 | + printf("ERROR\n"); | |
| 61 | + int vez =0; | |
| 62 | + while (fgets(message, sizeof (message), file)) | |
| 63 | + { | |
| 64 | + vez++; | |
| 65 | + | |
| 66 | + if(vez>1){ | |
| 67 | + jsonResult+= message; | |
| 68 | + | |
| 69 | + } | |
| 70 | + } | |
| 71 | + //cout<< jsonResult <<endl<<endl; | |
| 72 | + Json::Value root; | |
| 73 | + Json::Reader reader; | |
| 74 | + bool parsingSuccessful = reader.parse(jsonResult, root); | |
| 75 | + // cout << root["result"]<<endl; | |
| 76 | + confidence = 0.0; | |
| 77 | + sentence = ""; | |
| 78 | + if (parsingSuccessful) | |
| 79 | + { | |
| 80 | + sentence = root["result"][0]["alternative"][0]["transcript"].asString(); | |
| 81 | + confidence = root["result"][0]["alternative"][0]["confidence"].asFloat(); | |
| 82 | + } | |
| 83 | + | |
| 84 | + | |
| 85 | + fclose(file); | |
| 86 | + | |
| 87 | + jsonResult = ""; | |
| 88 | + comand.str(""); | |
| 89 | + | |
| 90 | + return 1; | |
| 91 | +} | |
| 92 | + | |
| 93 | + | |
| 94 | +float Recognizer::getconfidence(){ | |
| 95 | + return confidence; | |
| 96 | +} | |
| 97 | +string Recognizer::getsentence(){ | |
| 98 | + // printf("palavra %s\n",sentence.c_str() ); | |
| 99 | + return sentence; | |
| 100 | +} | |
| 101 | + | ... | ... |
| ... | ... | @@ -0,0 +1,187 @@ |
| 1 | +#include "wavcut.h" | |
| 2 | + | |
| 3 | +#include <vector> | |
| 4 | +// #include <iostream> | |
| 5 | + | |
| 6 | + | |
| 7 | +int sfreq = 22050; ///< Temporal storage of sample rate | |
| 8 | +int speechlen; ///< samples of one recorded segments | |
| 9 | +FILE *fp = NULL; ///< File pointer for WAV output | |
| 10 | +int sid = 0; ///< current file ID (for SPOUT_FILE) | |
| 11 | +char *outpath = NULL; ///< work space for output file name formatting | |
| 12 | +boolean writing_file = FALSE; ///< TRUE if writing to a file | |
| 13 | +int trigger_sample; | |
| 14 | +char *pathAudio; | |
| 15 | +char* outputPath; | |
| 16 | +char* id_file; | |
| 17 | +static vector<Audiofile> audioList; | |
| 18 | + | |
| 19 | + | |
| 20 | +Wavcut::Wavcut(char* _pathAudio, char* _outputPath, char* _id){ | |
| 21 | + | |
| 22 | + pathAudio = _pathAudio; | |
| 23 | + outputPath = _outputPath; | |
| 24 | + id_file = _id; | |
| 25 | + //printf("%s\n","Entrou aquiiiii" ) | |
| 26 | +} | |
| 27 | + | |
| 28 | +Wavcut::~Wavcut(){ | |
| 29 | + //printf("%s\n","Wavcut finalizado" ); | |
| 30 | +} | |
| 31 | + | |
| 32 | + | |
| 33 | +int Wavcut::adin_callback_file(SP16 *now, int len, Recog *recog) | |
| 34 | + { | |
| 35 | + /* cria novo arquivo wav para salvar o audio sem silencio*/ | |
| 36 | + if (speechlen == 0) { | |
| 37 | + | |
| 38 | + sprintf(outpath, "%s%d.wav",outputPath, sid); | |
| 39 | + | |
| 40 | + if (access(outpath, F_OK) == 0) { | |
| 41 | + if (access(outpath, W_OK) != 0) { | |
| 42 | + return(-1); | |
| 43 | + } | |
| 44 | + | |
| 45 | + } | |
| 46 | + | |
| 47 | + if ((fp = wrwav_open(outpath, sfreq)) != NULL) { | |
| 48 | + //fprintf(stderr, "novo arquivo\n"); | |
| 49 | + }else{ | |
| 50 | + return -1; | |
| 51 | + } | |
| 52 | + writing_file = TRUE; | |
| 53 | + } | |
| 54 | + | |
| 55 | + /* write recorded sample to file */ | |
| 56 | + if (wrwav_data(fp, &(now[0]), len) == FALSE) { | |
| 57 | + return -1; | |
| 58 | + } | |
| 59 | + | |
| 60 | + /* accumulate sample num of this segment */ | |
| 61 | +speechlen += len; | |
| 62 | + | |
| 63 | +return(0); | |
| 64 | +} | |
| 65 | + | |
| 66 | +//acumula o tempo de cada segmento | |
| 67 | +void registra_tempo(Recog *recog, void *data) | |
| 68 | +{ | |
| 69 | + trigger_sample = recog->adin->last_trigger_sample; | |
| 70 | +} | |
| 71 | + | |
| 72 | +boolean close_files() | |
| 73 | +{ | |
| 74 | + if (writing_file) { | |
| 75 | + | |
| 76 | + if (wrwav_close(fp) == FALSE) { | |
| 77 | + fprintf(stderr, "adinrec: failed to close file\n"); | |
| 78 | + return FALSE; | |
| 79 | + } | |
| 80 | + char* fileout=(char *)mymalloc(100);; | |
| 81 | + // sprintf(fileout,*outpath); | |
| 82 | + sprintf(fileout, outpath); | |
| 83 | + audioList.push_back(Audiofile(fileout,(float)trigger_sample / (float)sfreq, | |
| 84 | + (float)(trigger_sample + speechlen) / (float)sfreq)); | |
| 85 | + | |
| 86 | + writing_file = FALSE; | |
| 87 | +} | |
| 88 | + | |
| 89 | +return TRUE; | |
| 90 | +} | |
| 91 | + | |
| 92 | + | |
| 93 | + int Wavcut::initialize(Jconf *jconf) { | |
| 94 | + | |
| 95 | + sid = 0; | |
| 96 | + audioList.clear(); | |
| 97 | + //Jconf *jconf; | |
| 98 | + Recog *recog; | |
| 99 | + | |
| 100 | + int ret; | |
| 101 | + boolean is_continues; | |
| 102 | + | |
| 103 | + /* cria instancia do reconhecedor */ | |
| 104 | + recog = j_recog_new(); | |
| 105 | + /* carrega as configurações contidas no jconfig */ | |
| 106 | + // jconf = j_config_load_file_new("/home/ezequiel/speech-recognizer/wavcut.jconf"); | |
| 107 | + | |
| 108 | + jconf->input.sfreq = sfreq; | |
| 109 | + /*adciona a configuração ao reconhecedor*/ | |
| 110 | + recog->jconf = jconf; | |
| 111 | + | |
| 112 | + outpath = (char *)mymalloc(256); | |
| 113 | + | |
| 114 | +/*registra calback do contador de tempo*/ | |
| 115 | + callback_add(recog, CALLBACK_EVENT_SPEECH_START, registra_tempo, NULL); | |
| 116 | + | |
| 117 | + /*Inicializa o reconhecedor*/ | |
| 118 | + if (j_adin_init(recog) == FALSE) { | |
| 119 | + fprintf(stderr, "Error in initializing adin device\n"); | |
| 120 | + return 0; | |
| 121 | + } | |
| 122 | + | |
| 123 | + /*Abre o quivo de áudio para ser cortado*/ | |
| 124 | + if(j_open_stream(recog,pathAudio) == -2) | |
| 125 | + return sid; | |
| 126 | + | |
| 127 | + /* loop de detecção de voz*/ | |
| 128 | + | |
| 129 | + do { | |
| 130 | + | |
| 131 | + speechlen = 0; | |
| 132 | + | |
| 133 | + ret = adin_go(adin_callback_file, NULL, recog); | |
| 134 | + | |
| 135 | + | |
| 136 | + switch(ret) { | |
| 137 | + case -1: /* device read error or callback error */ | |
| 138 | + //fprintf(stderr, "[error]\n"); | |
| 139 | + break; | |
| 140 | + case 0: /* reached to end of input */ | |
| 141 | + //fprintf(stderr, "[eof]\n"); | |
| 142 | + return sid; | |
| 143 | + break; | |
| 144 | + default: | |
| 145 | + break; | |
| 146 | + } | |
| 147 | + | |
| 148 | + if (ret == -1) { | |
| 149 | + /* error in input device or callback function, so terminate program here */ | |
| 150 | + return sid; | |
| 151 | + } | |
| 152 | + /* um intervalo de silencio detectado */ | |
| 153 | + | |
| 154 | + if (close_files() == FALSE) | |
| 155 | + return sid; | |
| 156 | + | |
| 157 | + /* incremento do contador de partes cortadas */ | |
| 158 | + | |
| 159 | + | |
| 160 | + sid++; | |
| 161 | + | |
| 162 | + is_continues = FALSE; | |
| 163 | + if (ret > 0 || ret == -2) { | |
| 164 | + is_continues = TRUE; | |
| 165 | + } | |
| 166 | + | |
| 167 | + } while (is_continues); | |
| 168 | + | |
| 169 | + /*Quando termina de ler todo áudio finaliza*/ | |
| 170 | + adin_end(recog->adin); | |
| 171 | + | |
| 172 | + return sid; | |
| 173 | + | |
| 174 | +} | |
| 175 | + | |
| 176 | +vector<Audiofile> Wavcut::list_audio_files(){ | |
| 177 | + | |
| 178 | + | |
| 179 | + return audioList; | |
| 180 | +} | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | ... | ... |
| ... | ... | @@ -0,0 +1,24 @@ |
| 1 | +-smpFreq 22050 | |
| 2 | +-lv 1000 | |
| 3 | +-zc 60 | |
| 4 | +-headmargin 200 | |
| 5 | +-tailmargin 150 | |
| 6 | +-rejectshort 1500 | |
| 7 | +-input rawfile | |
| 8 | +-cutsilence | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | +#-smpFreq 22050 | |
| 13 | +#-lv 3000 | |
| 14 | +#-zc 150 | |
| 15 | +#-headmargin 200 | |
| 16 | +#-tailmargin 150 | |
| 17 | +#-rejectshort 1500 | |
| 18 | +#-input rawfile | |
| 19 | +#-cutsilence | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | ... | ... |
servico/src/include/serviceWindowGeneration.h
| ... | ... | @@ -15,7 +15,7 @@ |
| 15 | 15 | #include "listenerTradutor.h" |
| 16 | 16 | #include "tradutorPortGlosa.h" |
| 17 | 17 | #include "serviceException.h" |
| 18 | -#include <json/json.h> | |
| 18 | +#include <json/json.h> | |
| 19 | 19 | #include <lavidlib/base/RuntimeException.h> |
| 20 | 20 | |
| 21 | 21 | #define DEVELOPER "devel" |
| ... | ... | @@ -26,7 +26,6 @@ |
| 26 | 26 | #define PATH_CONF_FILE "vlibras_user/.vlibras-config/params.json" |
| 27 | 27 | #define MAX_SIZE_PATH 256 |
| 28 | 28 | |
| 29 | -using namespace Json; | |
| 30 | 29 | using namespace Tradutor; |
| 31 | 30 | using namespace jthread; |
| 32 | 31 | using namespace std; |
| ... | ... | @@ -39,8 +38,8 @@ protected: |
| 39 | 38 | Renderer* renderer; |
| 40 | 39 | Mixer* mixer; |
| 41 | 40 | |
| 42 | - Value root; | |
| 43 | - Reader reader; | |
| 41 | + Json::Value root; | |
| 42 | + Json::Reader reader; | |
| 44 | 43 | vector<int64_t>* vetor_pts; |
| 45 | 44 | |
| 46 | 45 | bool finish; | ... | ... |