From 6ae37008c90606cb0dbc9ee22c2e8c55383d5bfb Mon Sep 17 00:00:00 2001 From: Rodgger Date: Sat, 11 Feb 2023 19:00:07 -0500 Subject: [PATCH] =?UTF-8?q?coment=C3=A1rios=20e=20redu=C3=A7=C3=A3o=20de?= =?UTF-8?q?=20arryas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 19 +++++++++---------- agi.c | 5 +++++ agi_c.h | 5 +++++ speech.c | 25 ++++++++++++++++++------- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 1891446..6d0985c 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,7 @@ -## Compilar speech simplesip -## -## -## -## - +############################### +## Compilar speech simplesip ## +## copyright Simples Ip ## +############################### CC=gcc CFLAGS=-Wall -W @@ -15,13 +13,14 @@ agi.o\ base64.o speech-recog.agi_c: $(OBJ) - $(CC) -o $@ $^ $(LIBS) - @echo "\nBinário: speech-recog.agi_c" + @$(CC) -o $@ $^ $(LIBS) + @echo "make -> compila\nmake clean -> limpa objetos\n\nPrograma gerado: speech-recog.agi_c" $(DIR_OBJ)%.o: $(DIR_SRC)%.c - $(CC) -c -o $@ $< $(CFLAGS) + @$(CC) -c -Werror -o $@ $< $(CFLAGS) clean: - rm *.o + @rm -f *.o + @echo "objetos apagados" diff --git a/agi.c b/agi.c index 3765319..2e0a67f 100755 --- a/agi.c +++ b/agi.c @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2022 Simples Ip, All rights reserved. + * Author: Ródgger Bruno + */ + #include #include #include diff --git a/agi_c.h b/agi_c.h index 849a4c0..9743194 100755 --- a/agi_c.h +++ b/agi_c.h @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2022 Simples Ip, All rights reserved. + * Author: Ródgger Bruno + */ + #ifndef AGI_H #define AGI_H 1 diff --git a/speech.c b/speech.c index 5d95939..5c46de0 100755 --- a/speech.c +++ b/speech.c @@ -1,5 +1,10 @@ +/* + * Copyright (c) 2022 Simples Ip, All rights reserved. + * Author: Ródgger Bruno + */ + #define _POSIX_C_SOURCE 199309 -#include +//#include #include "agi_c.h" #include #include @@ -11,6 +16,8 @@ #include #include #include +#include + #define GOOGLE_KEY "AIzaSyBxwBNxj9qKoG_U9bH9eLouzfhRtr6AdWc" @@ -37,10 +44,11 @@ char beep[10]; char uniqueid[30]; char samplerate[ 32 ]; // samplerate do audio char pro_filter[ 10 ]; // esconder os palavrões no texto, exemplo: f***** -char flac[4096]; +char flac[128]; char name_audio[100]; int fd_tmpaudio; + //prototype int define_variable( char *variable, char *value ); int bin_flac( ); @@ -52,8 +60,10 @@ struct response_google *send_network( s_agi_parameter *param_agi, struct b_audi int copy_to_struct( struct b_audio *b_flac, char *str, size_t p ); char *http_content(CURL *curl, struct b_audio *b_flac); size_t response_curl(void *contents, size_t size, size_t nmemb, void *userp); +static void sigHandler(int sig); int main(){ + s_agi_parameter *param_agi = NULL; s_agi_return *response = NULL; @@ -79,6 +89,7 @@ int main(){ response = agi_command( "ANSWER \n" ); if( response->result != 0 ){ AGI_NORESPONSE( "VERBOSE \"Falha resposta do canal. script terminado\" \n" ); + exit(-1); } } @@ -347,9 +358,9 @@ int covert_flac( ){ struct b_audio * get_audio_bytes(){ - char command_base64[4096]; + char command_base64[256]; /* converter flac em base64 */ - snprintf(command_base64, 4096, "base64 %s.flac -w 0 > %s.base64", name_audio, name_audio); + snprintf(command_base64, 256, "base64 %s.flac -w 0 > %s.base64", name_audio, name_audio); /* verfica se tem erros na conversão */ if(system( command_base64 ) != 0){ @@ -358,8 +369,8 @@ struct b_audio * get_audio_bytes(){ } FILE *fd_base64; - char full_path_name_base64[ 4096 ]; - snprintf(full_path_name_base64, 4096, "%s.base64", name_audio); + char full_path_name_base64[ 256 ]; + snprintf(full_path_name_base64, 256, "%s.base64", name_audio); fd_base64 = fopen( full_path_name_base64, "r"); if(fd_base64 == NULL){ AGI_NORESPONSE("VERBOSE \"Não pode abrir o arquivo %s.base64\"\n", name_audio); @@ -490,6 +501,7 @@ size_t response_curl(void *contents, size_t size, size_t nmemb, void *userp){ memcpy(&(mem->response[mem->size]), contents, realsize); mem->size += realsize; mem->response[mem->size] = 0; + return realsize; } @@ -539,4 +551,3 @@ char *http_content(CURL *curl, struct b_audio *b_flac){ return content; } -