libspeechd.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. * libspeechd.h - Shared library for easy acces 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 General Public License as published by
  8. * the Free Software Foundation; either version 2, 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. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this package; see the file COPYING. If not, write to
  18. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19. * Boston, MA 02110-1301, USA.
  20. *
  21. * $Id: libspeechd.h,v 1.29 2008-07-30 09:47:00 hanke Exp $
  22. */
  23. #ifndef _LIBSPEECHD_H
  24. #define _LIBSPEECHD_H
  25. #include <stdio.h>
  26. #include <stddef.h>
  27. #include <pthread.h>
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /* Arguments for spd_send_data() */
  32. #define SPD_WAIT_REPLY 1 /* Wait for reply */
  33. #define SPD_NO_REPLY 0 /* No reply requested */
  34. /* --------------------- Public data types ------------------------ */
  35. typedef enum{
  36. SPD_PUNCT_ALL = 0,
  37. SPD_PUNCT_NONE = 1,
  38. SPD_PUNCT_SOME = 2
  39. }SPDPunctuation;
  40. typedef enum{
  41. SPD_CAP_NONE = 0,
  42. SPD_CAP_SPELL = 1,
  43. SPD_CAP_ICON = 2
  44. }SPDCapitalLetters;
  45. typedef enum{
  46. SPD_SPELL_OFF = 0,
  47. SPD_SPELL_ON = 1
  48. }SPDSpelling;
  49. typedef enum{
  50. SPD_DATA_TEXT = 0,
  51. SPD_DATA_SSML = 1
  52. }SPDDataMode;
  53. typedef enum{
  54. SPD_MALE1 = 1,
  55. SPD_MALE2 = 2,
  56. SPD_MALE3 = 3,
  57. SPD_FEMALE1 = 4,
  58. SPD_FEMALE2 = 5,
  59. SPD_FEMALE3 = 6,
  60. SPD_CHILD_MALE = 7,
  61. SPD_CHILD_FEMALE = 8
  62. }SPDVoiceType;
  63. typedef struct{
  64. char *name; /* Name of the voice (id) */
  65. char *language; /* 2-letter ISO language code */
  66. char *variant; /* a not-well defined string describing dialect etc. */
  67. }SPDVoice;
  68. typedef enum{
  69. SPD_BEGIN = 1,
  70. SPD_END = 2,
  71. SPD_INDEX_MARKS = 4,
  72. SPD_CANCEL = 8,
  73. SPD_PAUSE = 16,
  74. SPD_RESUME = 32
  75. }SPDNotification;
  76. typedef enum{
  77. SPD_IMPORTANT = 1,
  78. SPD_MESSAGE = 2,
  79. SPD_TEXT = 3,
  80. SPD_NOTIFICATION = 4,
  81. SPD_PROGRESS = 5
  82. }SPDPriority;
  83. typedef enum{
  84. SPD_EVENT_BEGIN,
  85. SPD_EVENT_END,
  86. SPD_EVENT_CANCEL,
  87. SPD_EVENT_PAUSE,
  88. SPD_EVENT_RESUME,
  89. SPD_EVENT_INDEX_MARK
  90. }SPDNotificationType;
  91. typedef enum{
  92. SPD_MODE_SINGLE = 0,
  93. SPD_MODE_THREADED = 1
  94. }SPDConnectionMode;
  95. typedef enum{
  96. SPD_METHOD_UNIX_SOCKET = 0,
  97. SPD_METHOD_INET_SOCKET = 1,
  98. }SPDConnectionMethod;
  99. typedef struct{
  100. SPDConnectionMethod method;
  101. char *unix_socket_name;
  102. char *inet_socket_host;
  103. int inet_socket_port;
  104. char *dbus_bus;
  105. }SPDConnectionAddress;
  106. typedef void (*SPDCallback)(size_t msg_id, size_t client_id, SPDNotificationType state);
  107. typedef void (*SPDCallbackIM)(size_t msg_id, size_t client_id, SPDNotificationType state, char *index_mark);
  108. typedef struct{
  109. /* PUBLIC */
  110. SPDCallback callback_begin;
  111. SPDCallback callback_end;
  112. SPDCallback callback_cancel;
  113. SPDCallback callback_pause;
  114. SPDCallback callback_resume;
  115. SPDCallbackIM callback_im;
  116. /* PRIVATE */
  117. int socket;
  118. FILE *stream;
  119. SPDConnectionMode mode;
  120. pthread_mutex_t *ssip_mutex;
  121. pthread_t *events_thread;
  122. pthread_mutex_t *comm_mutex;
  123. pthread_cond_t *cond_reply_ready;
  124. pthread_mutex_t *mutex_reply_ready;
  125. pthread_cond_t *cond_reply_ack;
  126. pthread_mutex_t *mutex_reply_ack;
  127. char *reply;
  128. }SPDConnection;
  129. /* -------------- Public functions --------------------------*/
  130. /* Openning and closing Speech Dispatcher connection */
  131. SPDConnectionAddress* spd_get_default_address(char** error);
  132. SPDConnection* spd_open(const char* client_name, const char* connection_name, const char* user_name,
  133. SPDConnectionMode mode);
  134. SPDConnection* spd_open2(const char* client_name, const char* connection_name, const char* user_name,
  135. SPDConnectionMode mode, SPDConnectionAddress *address, int autospawn,
  136. char **error_result);
  137. void spd_close(SPDConnection* connection);
  138. /* Speaking */
  139. int spd_say(SPDConnection* connection, SPDPriority priority, const char* text);
  140. int spd_sayf(SPDConnection* connection, SPDPriority priority, const char *format, ...);
  141. /* Speech flow */
  142. int spd_stop(SPDConnection* connection);
  143. int spd_stop_all(SPDConnection* connection);
  144. int spd_stop_uid(SPDConnection* connection, int target_uid);
  145. int spd_cancel(SPDConnection* connection);
  146. int spd_cancel_all(SPDConnection* connection);
  147. int spd_cancel_uid(SPDConnection* connection, int target_uid);
  148. int spd_pause(SPDConnection* connection);
  149. int spd_pause_all(SPDConnection* connection);
  150. int spd_pause_uid(SPDConnection* connection, int target_uid);
  151. int spd_resume(SPDConnection* connection);
  152. int spd_resume_all(SPDConnection* connection);
  153. int spd_resume_uid(SPDConnection* connection, int target_uid);
  154. /* Characters and keys */
  155. int spd_key(SPDConnection* connection, SPDPriority priority, const char *key_name);
  156. int spd_char(SPDConnection* connection, SPDPriority priority, const char *character);
  157. int spd_wchar(SPDConnection* connection, SPDPriority priority, wchar_t wcharacter);
  158. /* Sound icons */
  159. int spd_sound_icon(SPDConnection* connection, SPDPriority priority, const char *icon_name);
  160. /* Setting parameters */
  161. int spd_set_voice_type(SPDConnection*, SPDVoiceType type);
  162. int spd_set_voice_type_all(SPDConnection*, SPDVoiceType type);
  163. int spd_set_voice_type_uid(SPDConnection*, SPDVoiceType type, unsigned int uid);
  164. int spd_set_synthesis_voice(SPDConnection*, const char *voice_name);
  165. int spd_set_synthesis_voice_all(SPDConnection*, const char *voice_name);
  166. int spd_set_synthesis_voice_uid(SPDConnection*, const char *voice_name, unsigned int uid);
  167. int spd_set_data_mode(SPDConnection *connection, SPDDataMode mode);
  168. int spd_set_notification_on(SPDConnection* connection, SPDNotification notification);
  169. int spd_set_notification_off(SPDConnection* connection, SPDNotification notification);
  170. int spd_set_notification(SPDConnection* connection, SPDNotification notification, const char* state);
  171. int spd_set_voice_rate(SPDConnection* connection, signed int rate);
  172. int spd_set_voice_rate_all(SPDConnection* connection, signed int rate);
  173. int spd_set_voice_rate_uid(SPDConnection* connection, signed int rate, unsigned int uid);
  174. int spd_set_voice_pitch(SPDConnection* connection, signed int pitch);
  175. int spd_set_voice_pitch_all(SPDConnection* connection, signed int pitch);
  176. int spd_set_voice_pitch_uid(SPDConnection* connection, signed int pitch, unsigned int uid);
  177. int spd_set_volume(SPDConnection* connection, signed int volume);
  178. int spd_set_volume_all(SPDConnection* connection, signed int volume);
  179. int spd_set_volume_uid(SPDConnection* connection, signed int volume, unsigned int uid);
  180. int spd_set_punctuation(SPDConnection* connection, SPDPunctuation type);
  181. int spd_set_punctuation_all(SPDConnection* connection, SPDPunctuation type);
  182. int spd_set_punctuation_uid(SPDConnection* connection, SPDPunctuation type, unsigned int uid);
  183. int spd_set_capital_letters(SPDConnection* connection, SPDCapitalLetters type);
  184. int spd_set_capital_letters_all(SPDConnection* connection, SPDCapitalLetters type);
  185. int spd_set_capital_letters_uid(SPDConnection* connection, SPDCapitalLetters type, unsigned int uid);
  186. int spd_set_spelling(SPDConnection* connection, SPDSpelling type);
  187. int spd_set_spelling_all(SPDConnection* connection, SPDSpelling type);
  188. int spd_set_spelling_uid(SPDConnection* connection, SPDSpelling type, unsigned int uid);
  189. int spd_set_language(SPDConnection* connection, const char* language);
  190. int spd_set_language_all(SPDConnection* connection, const char* language);
  191. int spd_set_language_uid(SPDConnection* connection, const char* language, unsigned int uid);
  192. int spd_set_output_module(SPDConnection* connection, const char* output_module);
  193. int spd_set_output_module_all(SPDConnection* connection, const char* output_module);
  194. int spd_set_output_module_uid(SPDConnection* connection, const char* output_module, unsigned int uid);
  195. int spd_get_client_list(SPDConnection *connection, char **client_names, int *client_ids, int* active);
  196. int spd_get_message_list_fd(SPDConnection *connection, int target, int *msg_ids, char **client_names);
  197. char** spd_list_modules(SPDConnection *connection);
  198. char** spd_list_voices(SPDConnection *connection);
  199. SPDVoice** spd_list_synthesis_voices(SPDConnection *connection);
  200. char** spd_execute_command_with_list_reply(SPDConnection *connection, char* command);
  201. /* Direct SSIP communication */
  202. int spd_execute_command(SPDConnection* connection, char* command);
  203. int spd_execute_command_with_reply(SPDConnection *connection, char* command, char **reply);
  204. int spd_execute_command_wo_mutex(SPDConnection *connection, char* command);
  205. char* spd_send_data(SPDConnection* connection, const char *message, int wfr);
  206. char* spd_send_data_wo_mutex(SPDConnection *connection, const char *message, int wfr);
  207. #ifdef __cplusplus
  208. }
  209. #endif /* __cplusplus */
  210. #endif /* ifndef _LIBSPEECHD_H */