| 1 | /* |
| 2 | * libspeechd.h - Shared library for easy access to Speech Dispatcher functions (header) |
| 3 | * |
| 4 | * Copyright (C) 2001, 2002, 2003, 2004 Brailcom, o.p.s. |
| 5 | * |
| 6 | * This is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU Lesser General Public License as published by |
| 8 | * the Free Software Foundation; either version 2.1, or (at your option) |
| 9 | * any later version. |
| 10 | * |
| 11 | * This software is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public License |
| 17 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * $Id: libspeechd.h,v 1.29 2008-07-30 09:47:00 hanke Exp $ |
| 20 | */ |
| 21 | |
| 22 | #ifndef _LIBSPEECHD_H |
| 23 | #define _LIBSPEECHD_H |
| 24 | |
| 25 | #include <stdio.h> |
| 26 | #include <stddef.h> |
| 27 | #include <pthread.h> |
| 28 | |
| 29 | #include "libspeechd_version.h" |
| 30 | #include "speechd_types.h" |
| 31 | |
| 32 | /* *INDENT-OFF* */ |
| 33 | #ifdef __cplusplus |
| 34 | extern "C" { |
| 35 | #endif |
| 36 | /* *INDENT-ON* */ |
| 37 | /* Speech Dispatcher's default port for inet communication */ |
| 38 | #define SPEECHD_DEFAULT_PORT 6560 |
| 39 | |
| 40 | /* Arguments for spd_send_data() */ |
| 41 | #define SPD_WAIT_REPLY 1 /* Wait for reply */ |
| 42 | #define SPD_NO_REPLY 0 /* No reply requested */ |
| 43 | |
| 44 | /* --------------------- Public data types ------------------------ */ |
| 45 | |
| 46 | #ifdef __GNUC__ |
| 47 | # define SPD_ATTRIBUTE_FORMAT(type, string, first) __attribute__((format(type, string, first))) |
| 48 | #else |
| 49 | # define SPD_ATTRIBUTE_FORMAT(type, string, first) |
| 50 | #endif |
| 51 | |
| 52 | typedef enum { |
| 53 | SPD_MODE_SINGLE = 0, |
| 54 | SPD_MODE_THREADED = 1 |
| 55 | } SPDConnectionMode; |
| 56 | |
| 57 | typedef enum { |
| 58 | SPD_METHOD_UNIX_SOCKET = 0, |
| 59 | SPD_METHOD_INET_SOCKET = 1, |
| 60 | } SPDConnectionMethod; |
| 61 | |
| 62 | typedef struct { |
| 63 | SPDConnectionMethod method; |
| 64 | char *unix_socket_name; |
| 65 | char *inet_socket_host; |
| 66 | int inet_socket_port; |
| 67 | char *dbus_bus; |
| 68 | } SPDConnectionAddress; |
| 69 | |
| 70 | void SPDConnectionAddress__free(SPDConnectionAddress * address); |
| 71 | |
| 72 | typedef void (*SPDCallback) (size_t msg_id, size_t client_id, |
| 73 | SPDNotificationType state); |
| 74 | typedef void (*SPDCallbackIM) (size_t msg_id, size_t client_id, |
| 75 | SPDNotificationType state, char *index_mark); |
| 76 | |
| 77 | typedef struct { |
| 78 | |
| 79 | /* PUBLIC */ |
| 80 | SPDCallback callback_begin; |
| 81 | SPDCallback callback_end; |
| 82 | SPDCallback callback_cancel; |
| 83 | SPDCallback callback_pause; |
| 84 | SPDCallback callback_resume; |
| 85 | SPDCallbackIM callback_im; |
| 86 | |
| 87 | /* PRIVATE */ |
| 88 | int socket; |
| 89 | void *stream; |
| 90 | SPDConnectionMode mode; |
| 91 | char *buf; |
| 92 | size_t buf_start; |
| 93 | size_t buf_used; |
| 94 | |
| 95 | pthread_mutex_t ssip_mutex; |
| 96 | |
| 97 | struct SPDConnection_threaddata *td; |
| 98 | |
| 99 | char *reply; |
| 100 | |
| 101 | } SPDConnection; |
| 102 | |
| 103 | /* -------------- Public functions --------------------------*/ |
| 104 | |
| 105 | /* Opening and closing Speech Dispatcher connection */ |
| 106 | SPDConnectionAddress *spd_get_default_address(char **error); |
| 107 | SPDConnection *spd_open(const char *client_name, const char *connection_name, |
| 108 | const char *user_name, SPDConnectionMode mode); |
| 109 | SPDConnection *spd_open2(const char *client_name, const char *connection_name, |
| 110 | const char *user_name, SPDConnectionMode mode, |
| 111 | const SPDConnectionAddress * address, int autospawn, |
| 112 | char **error_result); |
| 113 | |
| 114 | int spd_fd(SPDConnection * connection); |
| 115 | |
| 116 | int spd_get_client_id(SPDConnection * connection); |
| 117 | |
| 118 | void spd_close(SPDConnection * connection); |
| 119 | |
| 120 | /* Speaking */ |
| 121 | int spd_say(SPDConnection * connection, SPDPriority priority, const char *text); |
| 122 | int spd_sayf(SPDConnection * connection, SPDPriority priority, |
| 123 | const char *format, ...) |
| 124 | SPD_ATTRIBUTE_FORMAT(printf, 3, 4); |
| 125 | |
| 126 | /* Speech flow */ |
| 127 | int spd_stop(SPDConnection * connection); |
| 128 | int spd_stop_all(SPDConnection * connection); |
| 129 | int spd_stop_uid(SPDConnection * connection, int target_uid); |
| 130 | |
| 131 | int spd_cancel(SPDConnection * connection); |
| 132 | int spd_cancel_all(SPDConnection * connection); |
| 133 | int spd_cancel_uid(SPDConnection * connection, int target_uid); |
| 134 | |
| 135 | int spd_pause(SPDConnection * connection); |
| 136 | int spd_pause_all(SPDConnection * connection); |
| 137 | int spd_pause_uid(SPDConnection * connection, int target_uid); |
| 138 | |
| 139 | int spd_resume(SPDConnection * connection); |
| 140 | int spd_resume_all(SPDConnection * connection); |
| 141 | int spd_resume_uid(SPDConnection * connection, int target_uid); |
| 142 | |
| 143 | /* Characters and keys */ |
| 144 | int spd_key(SPDConnection * connection, SPDPriority priority, |
| 145 | const char *key_name); |
| 146 | int spd_char(SPDConnection * connection, SPDPriority priority, |
| 147 | const char *character); |
| 148 | int spd_wchar(SPDConnection * connection, SPDPriority priority, |
| 149 | wchar_t wcharacter); |
| 150 | |
| 151 | /* Sound icons */ |
| 152 | int spd_sound_icon(SPDConnection * connection, SPDPriority priority, |
| 153 | const char *icon_name); |
| 154 | |
| 155 | /* Setting parameters */ |
| 156 | int spd_set_voice_type(SPDConnection *, SPDVoiceType type); |
| 157 | int spd_set_voice_type_all(SPDConnection *, SPDVoiceType type); |
| 158 | int spd_set_voice_type_uid(SPDConnection *, SPDVoiceType type, |
| 159 | unsigned int uid); |
| 160 | SPDVoiceType spd_get_voice_type(SPDConnection *); |
| 161 | |
| 162 | int spd_set_synthesis_voice(SPDConnection *, const char *voice_name); |
| 163 | int spd_set_synthesis_voice_all(SPDConnection *, const char *voice_name); |
| 164 | int spd_set_synthesis_voice_uid(SPDConnection *, const char *voice_name, |
| 165 | unsigned int uid); |
| 166 | |
| 167 | int spd_set_data_mode(SPDConnection * connection, SPDDataMode mode); |
| 168 | |
| 169 | int spd_set_notification_on(SPDConnection * connection, |
| 170 | SPDNotification notification); |
| 171 | int spd_set_notification_off(SPDConnection * connection, |
| 172 | SPDNotification notification); |
| 173 | int spd_set_notification(SPDConnection * connection, |
| 174 | SPDNotification notification, const char *state); |
| 175 | |
| 176 | int spd_set_voice_rate(SPDConnection * connection, signed int rate); |
| 177 | int spd_set_voice_rate_all(SPDConnection * connection, signed int rate); |
| 178 | int spd_set_voice_rate_uid(SPDConnection * connection, signed int rate, |
| 179 | unsigned int uid); |
| 180 | int spd_get_voice_rate(SPDConnection * connection); |
| 181 | |
| 182 | int spd_set_voice_pitch(SPDConnection * connection, signed int pitch); |
| 183 | int spd_set_voice_pitch_all(SPDConnection * connection, signed int pitch); |
| 184 | int spd_set_voice_pitch_uid(SPDConnection * connection, signed int pitch, |
| 185 | unsigned int uid); |
| 186 | int spd_get_voice_pitch(SPDConnection * connection); |
| 187 | |
| 188 | int spd_set_voice_pitch_range(SPDConnection * connection, |
| 189 | signed int pitch_range); |
| 190 | int spd_set_voice_pitch_range_all(SPDConnection * connection, |
| 191 | signed int pitch_range); |
| 192 | int spd_set_voice_pitch_range_uid(SPDConnection * connection, |
| 193 | signed int pitch_range, unsigned int uid); |
| 194 | |
| 195 | int spd_set_volume(SPDConnection * connection, signed int volume); |
| 196 | int spd_set_volume_all(SPDConnection * connection, signed int volume); |
| 197 | int spd_set_volume_uid(SPDConnection * connection, signed int volume, |
| 198 | unsigned int uid); |
| 199 | int spd_get_volume(SPDConnection * connection); |
| 200 | |
| 201 | int spd_set_punctuation(SPDConnection * connection, SPDPunctuation type); |
| 202 | int spd_set_punctuation_all(SPDConnection * connection, SPDPunctuation type); |
| 203 | int spd_set_punctuation_uid(SPDConnection * connection, SPDPunctuation type, |
| 204 | unsigned int uid); |
| 205 | |
| 206 | int spd_set_capital_letters(SPDConnection * connection, SPDCapitalLetters type); |
| 207 | int spd_set_capital_letters_all(SPDConnection * connection, |
| 208 | SPDCapitalLetters type); |
| 209 | int spd_set_capital_letters_uid(SPDConnection * connection, |
| 210 | SPDCapitalLetters type, unsigned int uid); |
| 211 | |
| 212 | int spd_set_spelling(SPDConnection * connection, SPDSpelling type); |
| 213 | int spd_set_spelling_all(SPDConnection * connection, SPDSpelling type); |
| 214 | int spd_set_spelling_uid(SPDConnection * connection, SPDSpelling type, |
| 215 | unsigned int uid); |
| 216 | |
| 217 | int spd_set_language(SPDConnection * connection, const char *language); |
| 218 | int spd_set_language_all(SPDConnection * connection, const char *language); |
| 219 | int spd_set_language_uid(SPDConnection * connection, const char *language, |
| 220 | unsigned int uid); |
| 221 | char *spd_get_language(SPDConnection * connection); |
| 222 | |
| 223 | int spd_set_output_module(SPDConnection * connection, |
| 224 | const char *output_module); |
| 225 | int spd_set_output_module_all(SPDConnection * connection, |
| 226 | const char *output_module); |
| 227 | int spd_set_output_module_uid(SPDConnection * connection, |
| 228 | const char *output_module, unsigned int uid); |
| 229 | |
| 230 | int spd_get_client_list(SPDConnection * connection, char **client_names, |
| 231 | int *client_ids, int *active); |
| 232 | int spd_get_message_list_fd(SPDConnection * connection, int target, |
| 233 | int *msg_ids, char **client_names); |
| 234 | |
| 235 | char **spd_list_modules(SPDConnection * connection); |
| 236 | void free_spd_modules(char **); |
| 237 | char *spd_get_output_module(SPDConnection * connection); |
| 238 | |
| 239 | char **spd_list_voices(SPDConnection * connection); |
| 240 | void free_spd_symbolic_voices(char **voices); |
| 241 | SPDVoice **spd_list_synthesis_voices(SPDConnection * connection); |
| 242 | SPDVoice **spd_list_synthesis_voices2(SPDConnection * connection, const char *language, const char *variant); |
| 243 | void free_spd_voices(SPDVoice ** voices); |
| 244 | char **spd_execute_command_with_list_reply(SPDConnection * connection, |
| 245 | const char *command); |
| 246 | |
| 247 | /* Direct SSIP communication */ |
| 248 | int spd_execute_command(SPDConnection * connection, const char *command); |
| 249 | int spd_execute_command_with_reply(SPDConnection * connection, const char *command, |
| 250 | char **reply); |
| 251 | int spd_execute_command_wo_mutex(SPDConnection * connection, const char *command); |
| 252 | char *spd_send_data(SPDConnection * connection, const char *message, int wfr); |
| 253 | char *spd_send_data_wo_mutex(SPDConnection * connection, const char *message, |
| 254 | int wfr); |
| 255 | |
| 256 | |
| 257 | |
| 258 | /* *INDENT-OFF* */ |
| 259 | #ifdef __cplusplus |
| 260 | } |
| 261 | #endif /* __cplusplus */ |
| 262 | /* *INDENT-ON* */ |
| 263 | |
| 264 | #endif /* ifndef _LIBSPEECHD_H */ |
| 265 | |