|
|
|
@ -1,5 +1,10 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2022 Simples Ip, All rights reserved. |
|
|
|
|
* Author: Ródgger Bruno <rodgger.silva@simplesip.com.br> |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#define _POSIX_C_SOURCE 199309 |
|
|
|
|
#include <time.h> |
|
|
|
|
//#include <time.h>
|
|
|
|
|
#include "agi_c.h" |
|
|
|
|
#include <stdio.h> |
|
|
|
|
#include <stdlib.h> |
|
|
|
@ -11,6 +16,8 @@
|
|
|
|
|
#include <curl/curl.h> |
|
|
|
|
#include <jansson.h> |
|
|
|
|
#include <errno.h> |
|
|
|
|
#include <signal.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|