1 
2 /*
3  * clibrary2.c - Testing LIST and associated set functions in Speech Dispatcher
4  *
5  * Copyright (C) 2008 Brailcom, o.p.s.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  * $Id: clibrary2.c,v 1.1 2008-04-09 11:41:52 hanke Exp $
21  */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 
31 #include "speechd_types.h"
32 #include "libspeechd.h"
33 
main()34 int main()
35 {
36 	SPDConnection *conn;
37 	int i, j, ret;
38 	char **modules;
39 	char **voices;
40 	char *module;
41 	char *language;
42 	int value;
43 	SPDVoiceType voice_type = SPD_CHILD_MALE;
44 	SPDVoice **synth_voices;
45 
46 	printf("Start of the test.\n");
47 
48 	printf("Trying to initialize Speech Deamon...");
49 	conn = spd_open("say", NULL, NULL, SPD_MODE_SINGLE);
50 	if (conn == 0) {
51 		printf("Speech Deamon failed");
52 		exit(1);
53 	}
54 	printf("OK\n");
55 
56 	printf("Trying to get the current output module...");
57 	module = spd_get_output_module(conn);
58 	printf("Got module %s\n", module);
59 	if (module == NULL) {
60 		printf("Can't get current output module\n");
61 		exit(1);
62 	}
63 
64 	printf("Trying to get the language...");
65 	language = spd_get_language(conn);
66 	printf("Got language %s\n", language);
67 	if (language == NULL) {
68 		printf("Can't get the language\n");
69 		exit(1);
70 	}
71 
72 	printf("Trying to get the voice rate...");
73 	value = spd_get_voice_rate(conn);
74 	printf("Got rate %d\n", value);
75 
76 	printf("Trying to get the voice pitch...");
77 	value = spd_get_voice_pitch(conn);
78 	printf("Got pitch %d\n", value);
79 
80 	printf("Trying to get the current volume...");
81 	value = spd_get_volume(conn);
82 	printf("Got volume %d\n", value);
83 
84 	printf("Trying to get the current voice type...");
85 	spd_set_voice_type(conn, voice_type);
86 	voice_type = spd_get_voice_type(conn);
87 	printf("Got voice type %d\n", voice_type);
88 
89 	modules = spd_list_modules(conn);
90 	if (modules == NULL) {
91 		printf("Can't list modules\n");
92 		exit(1);
93 	}
94 
95 	printf("Available output modules:\n");
96 	for (i = 0;; i++) {
97 		if (modules[i] == NULL)
98 			break;
99 		printf("     %s\n", modules[i]);
100 	}
101 
102 	voices = spd_list_voices(conn);
103 	if (voices == NULL) {
104 		printf("Can't list voices\n");
105 		exit(1);
106 	}
107 
108 	printf("Available symbolic voices:\n");
109 	for (i = 0;; i++) {
110 		if (voices[i] == NULL)
111 			break;
112 		printf("     %s\n", voices[i]);
113 	}
114 
115 	for (j = 0;; j++) {
116 		if (modules[j] == NULL)
117 			break;
118 		ret = spd_set_output_module(conn, modules[j]);
119 		if (ret == -1) {
120 			printf("spd_set_output_module failed");
121 			exit(1);
122 		}
123 		printf("\nListing voices for %s\n", modules[j]);
124 		synth_voices = spd_list_synthesis_voices(conn);
125 		if (synth_voices == NULL) {
126 			printf("Can't list voices\n");
127 			exit(1);
128 		}
129 		printf("Available synthesis voices:\n");
130 		for (i = 0;; i++) {
131 			if (synth_voices[i] == NULL)
132 				break;
133 			printf("     name: %s language: %s variant: %s\n",
134 			       synth_voices[i]->name, synth_voices[i]->language,
135 			       synth_voices[i]->variant);
136 			ret =
137 			    spd_set_synthesis_voice(conn,
138 						    synth_voices[i]->name);
139 			if (ret == -1) {
140 				printf("spd_set_synthesis_voice failed");
141 				exit(1);
142 			}
143 
144 			ret = spd_say(conn, SPD_TEXT, "test");
145 			if (ret == -1) {
146 				printf("spd_say failed");
147 				exit(1);
148 			}
149 			sleep(1);
150 		}
151 	}
152 
153 	printf("Trying to close Speech Dispatcher connection...");
154 	spd_close(conn);
155 	printf("OK\n");
156 
157 	printf("End of the test.\n");
158 	exit(0);
159 }
160