-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoice_recorder_c.c
628 lines (528 loc) · 20.8 KB
/
voice_recorder_c.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
// PROJECT VANI
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include <unistd.h>
#include <Mmsystem.h>
#include<conio.h>
#include <string.h>
#include <ctype.h>
#include <curl/curl.h>
//for linking gcc -o voice_recoder_c voice_recorder_c.c -lcurl -lwinmm
#define ALIAS "random_str"
#define MAX_WORD_LENGTH 100
#define FILENAME "C:\\Users\\kaushik\\OneDrive\\Desktop\\c program project\\out.wav.txt"
//int main(int argc,char *argv[])
void calling_mic()
{
char mci_command[100];
char ReturnString[300];
int mci_error;
FILE *fp;
sprintf(mci_command, "open new type waveaudio alias %s", ALIAS);
mci_error = mciSendString(mci_command, ReturnString, sizeof(ReturnString), NULL);
// set the time format
sprintf(mci_command,"set %s time format ms", ALIAS); // just set time format
mci_error = mciSendString(mci_command, ReturnString, sizeof(ReturnString), NULL);
// start recording
sprintf(mci_command, "record %s notify", ALIAS);
mci_error = mciSendString(mci_command, ReturnString, sizeof(ReturnString), NULL);
printf("Now on air, press a key too stop...\n");
Sleep(5000);
//stop recording
sprintf(mci_command,"stop %s", ALIAS);
mci_error = mciSendString(mci_command, ReturnString, sizeof(ReturnString), NULL);
// save the file
sprintf(mci_command, "save %s %s", ALIAS, "random1.wav");
mci_error = mciSendString(mci_command, ReturnString, sizeof(ReturnString), NULL);
// close the device
sprintf(mci_command,"close %s", ALIAS);
mci_error = mciSendString(mci_command, ReturnString, sizeof(ReturnString), NULL);
freopen("NUL", "w", stdout); //Redirect stdout to the null device
freopen("NUL", "w", stderr); // Redirect stderr to the null device
system("wsl ffmpeg -i random1.wav -acodec pcm_s16le -ac 1 -ar 16000 out.wav -y ");
//system("main.exe -otxt out.wav");
fp = popen("wsl curl --location --request POST \"https://centralindia.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=en-US&format=detailed\""
" --header \"Ocp-Apim-Subscription-Key: e650cf7f3f8e4b4f9721a05039ca6091\""
" --header \"Content-Type: audio/wav\""
" --data-binary \"@/mnt/c/Users/kaushik/OneDrive/Desktop/c program project/out.wav\""
" --output response.json"
" && wsl jq -r '.NBest[0].Display' response.json > output.txt","w");
if (fp == NULL) {
// Error occurred while executing the command
}
pclose(fp);
freopen("CON", "w", stdout);
freopen("CON", "w", stderr);
}
char *NthWord(int n) {
FILE *file = fopen("C:\\Users\\kaushik\\OneDrive\\Desktop\\c program project\\output.txt", "r");
if (file == NULL) {
printf("Error opening the file.\n");
calling_mic();
}
char* word = (char*)malloc(100 * sizeof(char));
int count = 0;
// Loop through each word in the file
while (fscanf(file, "%s", word) ==1) {
printf("yeah 12 \n");
count++;
if (count == n) {
fclose(file);
return word;
}
}
fclose(file);
return word;
}
void removeSpecialChars(char *sentence) {
int i, j;
int length = strlen(sentence);
for (i = 0, j = 0; i < length; i++) {
// Check if the current character is alphanumeric or space
if (isalnum(sentence[i]) || isspace(sentence[i])) {
sentence[j] = sentence[i];
j++;
}
}
sentence[j] = '\0';
}
void tts(const char* text){
char command[5000];
snprintf(command, sizeof(command), "curl --location --request POST \"https://centralindia.tts.speech.microsoft.com/cognitiveservices/v1\" --header \"Ocp-Apim-Subscription-Key: YOUR KEY\" --header \"Content-Type: application/ssml+xml\" --header \"X-Microsoft-OutputFormat: audio-16khz-128kbitrate-mono-mp3\" --header \"User-Agent: curl\" --data-raw \"<speak version='1.0' xml:lang='en-US'><voice xml:lang='en-US' xml:gender='female' name='en-IN-NeerjaNeural'>%s </voice></speak>\" --output output123.mp3", text);
system(command);
// Specify the path to the MP3 file
const char* filePath = "C:\\Users\\kaushik\\OneDrive\\Desktop\\c program project\\output123.mp3";
// Open the MP3 file
MCI_OPEN_PARMS openParams = { 0 };
openParams.lpstrDeviceType = "mpegvideo";
openParams.lpstrElementName = filePath;
if (mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD_PTR)&openParams) != 0) {
printf("Failed to open the MP3 file.\n");
//return 1;
}
// Play the MP3 file
MCI_PLAY_PARMS playParams = { 0 };
playParams.dwCallback = (DWORD_PTR)GetConsoleWindow();
if (mciSendCommand(openParams.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD_PTR)&playParams) != 0) {
printf("Failed to play the MP3 file.\n");
//return 1;
}
// Get the length of the audio file
MCI_STATUS_PARMS statusParams = { 0 };
statusParams.dwItem = MCI_STATUS_LENGTH;
if (mciSendCommand(openParams.wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&statusParams) != 0) {
printf("Failed to get the audio file length.\n");
//return 1;
}
// Convert the length to milliseconds
DWORD audioLength = statusParams.dwReturn;
DWORD audioDuration = audioLength / 1000;
//printf("Audio file duration: %u seconds\n", audioDuration);
audioDuration*=1000;
// Wait until the playback is finished
Sleep(audioDuration); // Adjust the duration as needed
// Close the MP3 file
MCI_GENERIC_PARMS closeParams = { 0 };
if (mciSendCommand(openParams.wDeviceID, MCI_CLOSE, 0, (DWORD_PTR)&closeParams) != 0) {
printf("Failed to close the MP3 file.\n");
//return 1;
}
}
void mousepointer(int x, int y){
SetCursorPos(x, y); // Move the mouse cursor to the specified position
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
// Simulate a left mouse button release
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
void ts(const char* sentence) {
// Simulate pressing the Alt key
keybd_event(VK_MENU, 0, 0, 0); // Press Alt key
keybd_event(VK_SPACE, 0, 0, 0); // Press space bar
keybd_event(VK_SPACE, 0, KEYEVENTF_KEYUP, 0); // Release space bar
keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0); // Release Alt key
//INPUT inputs[strlen(sentence)];
size_t sentenceLength = strlen(sentence);
INPUT* inputs = malloc(sentenceLength * sizeof(INPUT));
// Set up the inputs for each character in the sentence
for (int i = 0; i<strlen(sentence); i++) {
inputs[i].type = INPUT_KEYBOARD;
inputs[i].ki.wVk = 0;
inputs[i].ki.wScan = sentence[i];
inputs[i].ki.dwFlags = KEYEVENTF_UNICODE;
inputs[i].ki.time = 0;
inputs[i].ki.dwExtraInfo = 0;
}
// Send the key events to type the sentence
SendInput(strlen(sentence), inputs, sizeof(INPUT));
keybd_event(VK_RETURN, 0, 0, 0); // Press Enter key
keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0); // Release Enter key
free(inputs);
}
char* getTextAfterWord(const char* word) {
FILE* file = fopen("output.txt", "r");
if (file == NULL) {
printf("Failed to open the file: %s\n", "output.txt");
return NULL;
}
char buffer[256];
while (fgets(buffer, sizeof(buffer), file) != NULL) {
char* wordPosition = strstr(buffer, word);
if (wordPosition != NULL) {
// Calculate the length of the text after the word
size_t textLength = strlen(wordPosition);
// Allocate memory for the result
char* result = (char*)malloc((textLength + 1) * sizeof(char));
if (result == NULL) {
printf("Memory allocation failed.\n");
fclose(file);
return NULL;
}
// Copy the text after the word into the result
strcpy(result, wordPosition);
fclose(file);
return result;
}
}
fclose(file);
return NULL;
}
void run_python(const char* sentence) {
char command[200];
sprintf(command, "C:/Users/kaushik/AppData/Local/Microsoft/WindowsApps/python3.10.exe \"c:/Users/kaushik/OneDrive/Desktop/c program project/gptgo.py\" \"%s\" > outputgptgo.txt", sentence);
system(command);
}
void whatsapp(){
FILE *file;
char filename[] = "C:\\Users\\kaushik\\OneDrive\\Desktop\\c program project\\output.txt"; // Replace with your input file name
char line[100];
char *word;
char output1[100] = "";
char lastWord[100] = "";
// Open the file
file = fopen(filename, "r");
if (file == NULL) {
printf("Failed to open the file.\n");
}
// Read the first (and only) line
if (fgets(line, sizeof(line), file) != NULL) {
printf("l25");
// Find the position of "sent" and "to"
char *sentPos = strstr(line, "sent");
char *sendPos = strstr(line, "send");
char *toPos = strstr(line, "to");
// Extract the desired portion between "sent" and "to"
if ((sentPos != NULL && toPos != NULL && sentPos < toPos) || (sendPos != NULL && toPos != NULL && sendPos < toPos)) {
char *start;
if (sentPos != NULL && sentPos < toPos)
start = sentPos + strlen("sent");
else if (sendPos != NULL && sendPos < toPos)
start = sendPos + strlen("send");
else {
printf("Error: Invalid input format.\n");
}
strncpy(output1, start, toPos - start);
output1[toPos - start] = '\0';
}
else {
printf("Error: Keywords not found in input.\n");
}
// Split the line into words to get the last word
word = strtok(line, " ");
while (word != NULL) {
strcpy(lastWord, word);
word = strtok(NULL, " ");
}
}
// Print the desired portion
printf("Output 1: %s\n", output1);
// Print the last word
printf("Last word: %s\n", lastWord);
// Close the file
fclose(file);
char number[20]="DEFAULT NUMBER";
/*if(strcmp("Avinash",lastWord)==0 || strcmp("avinash",lastWord)==0 ){
strcpy(number, "ADD NUMBER1");
}
else if (strcmp("khadar",lastWord)==0 || strcmp("Khadar",lastWord)==0){
strcpy(number, "ADD NUMBER 2");
}
else if (strcmp("theva",lastWord)==0 || strcmp("Theva",lastWord)==0){
strcpy(number, "ADD NUMBER 3");
}*/
printf("%s \n",number);
const char talk[] = "sending message to avinash ";
//strcat(talk, lastWord);
printf("talk %s \n ",talk);
tts(talk);
printf("316 \n");
CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "https://api.ultramsg.com/instance50192/messages/chat");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "content-type: application/x-www-form-urlencoded");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
char requestParams[200];
snprintf(requestParams, sizeof(requestParams), "token=6qlr4eoslfkmik57&to=%s&body=%s", number, output1);
// Set the updated request parameters
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, requestParams);
curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L);
CURLcode ret = curl_easy_perform(hnd);
if (ret == CURLE_OK) {
printf("Request sent successfully.\n");
} else {
printf("Failed to send request. Error: %s\n", curl_easy_strerror(ret));
}
curl_easy_cleanup(hnd);
curl_slist_free_all(headers);
tts("message send successfully");
}
void step2(){
int r;
char word[100];
char *s21=NthWord(2);
char *s3=NthWord(3);
char *s4=NthWord(4);
char start[100]="start ";
removeSpecialChars(s4);
if (strcmp("exit",s3)==0 || strcmp("Exit",s3)==0 ){
int z=0;
printf("hi");
}
else if (strcmp("open",s3)==0 || strcmp("Open",s3)==0 || strcmp("opens",s3)==0 || strcmp("Opens",s3)==0 || strcmp("open",s21)==0 || strcmp("Open",s21)==0 || strcmp("opens",s21)==0 || strcmp("Opens",s21)==0 ){
if (strcmp("camera",s4)==0 || strcmp("camera",s3)==0){
const char talk[] = "opening camera";
tts(talk);
system("start microsoft.windows.camera:");
}else if (strcmp("store",s4)==0 || strcmp("store",s3)==0){
const char talk[] = "opening microsoft store";
tts(talk);
system("start ms-windows-store://home");
}else if (strcmp("whatsapp",s4)==0 || strcmp("WhatsApp",s4)==0 || strcmp("whatsapp",s3)==0 || strcmp("WhatsApp",s3)==0){
const char talk[] = "opening whatsapp";
tts(talk);
system("\"start\" https://web.whatsapp.com");
//const char talk[] = "entering password ";
Sleep(15000);
tts("entering password ");
//Sleep(15000);
int numberKeys[] = {0x32, 0x32, 0x30, 0x32, 0x39}; // ASCII codes for '2', '2', '0', '2', '9'
int numKeys = sizeof(numberKeys) / sizeof(numberKeys[0]);
for (int i = 0; i < numKeys; i++) {
keybd_event(numberKeys[i], 0, 0, 0);
keybd_event(numberKeys[i], 0, KEYEVENTF_KEYUP, 0);
}
keybd_event(VK_RETURN, 0, 0, 0); // Press Enter key
keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0); // Release Enter key
// const char talk[] = "password entered successfully... welcome MASTER";
tts("password entered successfully... welcome MASTER");
}else if (strcmp("calendar",s4)==0 || strcmp("calendar",s3)==0){
const char talk[] = "opening calender";
tts(talk);
system("start outlookcal:");
}else if (strcmp("mail",s4)==0 || strcmp("mail",s3)==0){
const char talk[] = "opening mail";
tts(talk);
system("start mailto:");
}else if (strcmp("vs code",s4)==0 || strcmp("vs code",s3)==0){
const char talk[] = "opening vs code";
tts(talk);
system("start code");
}else if (strcmp("powerpoint",s4)==0 || strcmp("powerpoint",s3)==0){
const char talk[] = "opening powerpoint";
tts(talk);
system("powerpnt");
}else if (strcmp("words",s4)==0|| strcmp("words",s3)==0){
const char talk[] = "opening microsoft word";
tts(talk);
system("start winword");
}else if (strcmp("recycle bin",s4)==0 || strcmp("recycle bin",s3)==0){
const char talk[] = "opening recycling bin";
tts(talk);
system("start explorer.exe shell:RecycleBinFolder");
}else if (strcmp("shut down",s4)==0 || strcmp("shut down",s3)==0){
const char talk[] = "shutting down... bye";
tts(talk);
system("shutdown -s");
}else if (strcmp("restart",s4)==0 ||strcmp("restart",s3)==0){
const char talk[] = "restarting";
tts(talk);
system("shutdown /r /t 0");
}else if (strcmp("Calculator",s4)==0 || strcmp("calculator",s4)==0){
const char talk[] = "opening calculator";
tts(talk);
system("calc.exe ");
}else if (strcmp("gallary",s4)==0 || strcmp("photos",s4)==0){
const char talk[] = "opening photos or gallary";
tts(talk);
system("start ms-photos:");
}else if (strcmp("clock",s4)==0 || strcmp("clock",s3)==0){
const char talk[] = "opening clock";
tts(talk);
system("start ms-clock:");
}else if (strcmp("lock",s4)==0 || strcmp("lock",s3)==0){
const char talk[] = "locking the screen";
tts(talk);
system("rundll32.exe user32.dll,LockWorkStation");
}else if (strcmp("wheather",s4)==0 || strcmp("wheather",s3)==0){
const char talk[] = "opening wheather";
tts(talk);
system("ms-weather:");
}else if (strcmp("notepad",s4)==0 || strcmp("notepad",s3)==0){
const char talk[] = "opening notepad";
tts(talk);
system("start notepad");
// const char talk[] = "start talking ";
tts("start talking");
keybd_event(VK_LWIN, 0, 0, 0);
keybd_event('H', 0, 0, 0);
// Release the keys
keybd_event('H', 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
}else{
//strcat(start,s4);
//removeSpecialChars(start);
char talk[] = "opening";
strcat(talk, s4);
tts(talk);
ts(s4);
}
}
else if (strcmp("close",s3)==0 || strcmp("Close",s3)==0){
mousepointer(1155,20);
}else if (strcmp("end",s3)==0 || strcmp("End",s3)==0 || strcmp("and",s3)==0){
mousepointer(1255,20);
}else if (strcmp("sent",s3)==0 || strcmp("Sent",s3)==0 || strcmp("send",s3)==0){
whatsapp();
}else if (strcmp("increase",s3)==0 || strcmp("increase",s21)==0){
//if (strcmp("volume",s4)==0 || strcmp("volume",s3)==0){
const char talk[] = " increasing volume ";
tts(talk);
keybd_event(VK_VOLUME_UP, 0, 0, 0); // Press volume up key
keybd_event(VK_VOLUME_UP, 0, KEYEVENTF_KEYUP, 0); // Release volume up key
//}
//else{
}else if (strcmp("decrease",s3)==0 || strcmp("decrease",s21)==0){
const char talk[] = " decreasing volume ";
tts(talk);
keybd_event(VK_VOLUME_DOWN, 0, 0, 0); // Press volume down key
keybd_event(VK_VOLUME_DOWN, 0, KEYEVENTF_KEYUP, 0); // Release volume down key
}else if (strcmp("select",s3)==0 || strcmp("Select",s3)==0){
const char talk[] = "selecting all ";
tts(talk);
keybd_event(VK_CONTROL, 0, 0, 0); // Press Ctrl key
keybd_event('A', 0, 0, 0); // Press "A" key
keybd_event('A', 0, KEYEVENTF_KEYUP, 0); // Release "A" key
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); // Release Ctrl key
}else if (strcmp("copy",s3)==0 || strcmp("Copy",s3)==0){
const char talk[] = "copying all ";
tts(talk);
keybd_event(VK_CONTROL, 0, 0, 0); // Press Ctrl key
keybd_event('c', 0, 0, 0); // Press "c" key
keybd_event('c', 0, KEYEVENTF_KEYUP, 0); // Release "c" key
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); // Release Ctrl key
}else if (strcmp("paste",s3)==0 || strcmp("Paste",s3)==0){
const char talk[] = "pasting all ";
tts(talk);
keybd_event(VK_CONTROL, 0, 0, 0); // Press Ctrl key
keybd_event('v', 0, 0, 0); // Press "v" key
keybd_event('v', 0, KEYEVENTF_KEYUP, 0); // Release "v" key
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); // Release Ctrl key
}else if (strcmp("extract",s3)==0 || strcmp("Extract",s3)==0){
const char talk[] = "start extracting ";
tts(talk);
keybd_event(VK_LWIN, 0, 0, 0); // Press left Windows key
keybd_event(VK_SHIFT, 0, 0, 0); // Press Shift key
keybd_event('t', 0, 0, 0); // Press "t" key
keybd_event('t', 0, KEYEVENTF_KEYUP, 0); // Release "t" key
keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0); // Release Shift key
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0); // Release left Windows key
}else if (strcmp("cursor",s3)==0 || strcmp("Cursor",s3)==0){
const char talk[] = "cursor is here ";
tts(talk);
for(int j=0;j<=1;j++){
keybd_event(VK_CONTROL, 0, 0, 0); // Press Ctrl key
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); // Release Ctrl key
}
Sleep(3);
keybd_event(VK_CONTROL, 0, 0, 0); // Press Ctrl key
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); // Release Ctrl key
}else{
const char* word = s3;
char* result = getTextAfterWord(word);
//const char* input_sentence = "Hello, world!";
run_python(result);
if (result != NULL) {
free(result);
}
// Read the result from the output file
FILE *file;
char *content;
long file_size;
// Open the file
file = fopen("outputgptgo.txt", "r");
if (file == NULL) {
printf("Failed to open the file.\n");
//return 1;
}
// Determine the file size
fseek(file, 0, SEEK_END);
file_size = ftell(file);
fseek(file, 0, SEEK_SET);
// Allocate memory to store the content
content = (char *) malloc(file_size + 1);
if (content == NULL) {
printf("Failed to allocate memory.\n");
fclose(file);
//return 1;
}
// Read the content of the file
fread(content, file_size, 1, file);
content[file_size] = '\0'; // Add a null terminator at the end
// Close the file
fclose(file);
// remove all new line characters
char cleanedText[5000];
int j = 0;
for (int i = 0; content[i] != '\0'; i++) {
if (content[i] != '\n' && content[i] != '\r') {
cleanedText[j++] = content[i];
}
}
cleanedText[j] = '\0';
free(content);
tts(cleanedText);
}
free(s3);
free(s4);
}
int main(int argc,char *argv[]){
int i=0,result;
char word[100],s1[100],s2[100][100]= {"Hey Vani","hevani","herevani","heyvani","evani","A vani","Hevani"," Himani","Hey Bonnie","Here Wani"," Here Vani","vani","Vani","Hey Wani"};
char *end_w=NthWord(3);
char *word2=NthWord(1);
char *word31=NthWord(2);
while(strcmp("exit.",end_w)!=0){
printf("recognising");
calling_mic();
printf("484 \n");
word2=NthWord(1);
word31=NthWord(2);
strcpy(s1, word2);
strcat(s1," ");
strcat(s1, word31);
removeSpecialChars(s1);
printf("%s \n \n",s1); //output as "HeyVani"
for (i=0;i<=13;i++){
result=strcmp(s1,s2[i]);
if (result==0 || strcmp(word2,s2[i])==0){
printf("101 /t %d",i); // true and move forward
step2();
}
}
}
free(word31);
free(word2);
//calling_mic();
return 0;
}