1 #include <stdio.h>
2 #include <stdint.h>
3 #include <stdlib.h>
4 #include <stdint.h>
5 #include <string.h>
6
7 #include "uvoice_init.h"
8 #include "uvoice_event.h"
9
10
11 extern void uvoice_play_test(int argc, char **argv);
12 extern void uvoice_record_test(int argc, char **argv);
13 extern void test_tts_handle(int argc, char **argv);
14
handle_input(char * buffer)15 static void handle_input(char *buffer)
16 {
17 char *ptr = buffer;
18 char *begin;
19 char *end;
20 char *temp;
21 int len;
22 int argc = 0;
23 int i;
24 char *argv[10];
25
26 if (!ptr)
27 return -1;
28
29 memset(argv, 0, sizeof(argv));
30 end = ptr + strlen(ptr) - 1;
31
32 while (*end == ' ' || *end == '\n') {
33 *end = '\0';
34 end--;
35 }
36
37 while (*ptr == ' ')
38 ptr++;
39
40 while (1) {
41 begin = ptr;
42 ptr = strchr(ptr, ' ');
43 if (!ptr) {
44 ptr = begin;
45 if (strlen(ptr) <= 0)
46 break;
47 if (strlen(ptr) > 0)
48 ptr += strlen(ptr);
49 }
50 end = ptr;
51 len = end - begin;
52 if (len <= 0)
53 break;
54 temp = malloc(len + 1);
55 if (!temp) {
56 printf("%s: alloc argv buffer failed !\n", __func__);
57 break;
58 }
59 memcpy(temp, begin, len);
60 temp[len] = '\0';
61 //printf("%s: argv[%d] %s\n", __func__, argc, temp);
62 argv[argc++] = temp;
63
64 while (*ptr == ' ')
65 ptr++;
66 }
67
68 if (argc <= 0)
69 return;
70
71 if (!strcmp(argv[0], "play"))
72 uvoice_play_test(argc, argv);
73 else if (!strcmp(argv[0], "record"))
74 uvoice_record_test(argc, argv);
75 else if (!strcmp(argv[0], "tts"))
76 test_tts_handle(argc, argv);
77
78 for (i = 0; i < argc; i++) {
79 if (argv[i]) {
80 //printf("%s: free argv[%d]\n", __func__, i);
81 free(argv[i]);
82 }
83 }
84 }
85
86
player_state_cb(uvoice_event_t * event,void * data)87 static void player_state_cb(uvoice_event_t *event, void *data)
88 {
89 //printf("%s: type %u code %u value %d\n", __func__, event->type, event->code, event->value);
90 }
91
main(int argc,char ** argv)92 int main(int argc, char **argv)
93 {
94 char buffer[2048];
95
96 uvoice_init();
97
98 uvoice_event_register(UVOICE_EV_PLAYER,
99 player_state_cb, NULL);
100
101 printf("\r>>> ");
102 memset(buffer, 0, sizeof(buffer));
103 while (fgets(buffer, sizeof(buffer), stdin)) {
104 if (!strncmp(buffer, "exit", strlen("exit")))
105 break;
106 handle_input(buffer);
107 printf("\r>>> ");
108 memset(buffer, 0, sizeof(buffer));
109 }
110 return 0;
111 }
112
113