/native/external/espeak/src/mbrolib.h

http://eyes-free.googlecode.com/ · C Header · 205 lines · 54 code · 46 blank · 105 comment · 0 complexity · c866bdb19ef20b2f8dc8b3d859f5f145 MD5 · raw file

  1. #ifndef MBROLIB_H
  2. #define MBROLIB_H
  3. /*
  4. * mbrolib: mbrola wrapper.
  5. *
  6. * Copyright (C) 2007 Gilles Casse <gcasse@oralux.org>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. */
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /* < types */
  27. /** Parameters */
  28. typedef struct {
  29. int ignore_error; /* 1=Ignore any fatal error or unknown diphone */
  30. char comment_char; /* Comment character */
  31. float volume_ratio; /* Volume ratio */
  32. float frequency_ratio; /* Applied to pitch points */
  33. float time_ratio; /* Applied to phone durations */
  34. } mbrolib_parameter;
  35. /** Returned errors */
  36. typedef enum {
  37. MBROLIB_OK=0,
  38. MBROLIB_DATABASE_NOT_INSTALLED,
  39. MBROLIB_INVAL,
  40. MBROLIB_OUT_OF_MEMORY,
  41. MBROLIB_OUT_OF_RANGE,
  42. MBROLIB_READ_ERROR,
  43. MBROLIB_WRITE_ERROR
  44. } MBROLIB_ERROR;
  45. /** Gender */
  46. typedef enum {
  47. MBROLIB_FEMALE,
  48. MBROLIB_MALE
  49. } MBROLIB_GENDER;
  50. /** Voice descriptor */
  51. typedef struct {
  52. char *name; /* name (for example: "en1") */
  53. char *filename; /* database pathname (for example: "/usr/share/mbrola/voices/en1) */
  54. int rate; /* database sample rate */
  55. MBROLIB_GENDER gender;
  56. const char *language; /* Language and optional dialect qualifier in ascii (e.g. en, fr_ca). */
  57. } mbrolib_voice;
  58. /* > */
  59. /** Initialization, returns a new handle.
  60. First function.
  61. @param the_sample_rate: output rate in Hz (for example 22050). If 0, keep the original database rate.
  62. @return handle (or NULL if error).
  63. */
  64. void* mbrolib_init( int sample_rate);
  65. typedef void* (t_mbrolib_init)(int);
  66. /** Returns the list of the installed mbrola databases.
  67. The databases are searched according to the MBROLA_PATH environment variable if set,
  68. or under a default path otherwise (see MBROLA_PATH in mbrolib.c).
  69. An array of voices is returned. The last item is set to NULL.
  70. The caller must not free the returned items or the array.
  71. @param the_handle previously given by mbrolib_init.
  72. @return An array of voices.
  73. */
  74. const mbrolib_voice ** mbrolib_list_voices( void* the_handle);
  75. typedef const mbrolib_voice ** (t_mbrolib_list_voices)(void*);
  76. /** Set voice
  77. @param the_handle.
  78. @param the_database (for example, "en1").
  79. @return error code (MBROLIB_OK, MBROLIB_DATABASE_NOT_INSTALLED, MBROLIB_INVAL).
  80. */
  81. MBROLIB_ERROR mbrolib_set_voice( void* the_handle, const char* the_name);
  82. typedef MBROLIB_ERROR (t_mbrolib_set_voice)( void*, const char*);
  83. /** Get the current database parameters.
  84. The caller supplies a pointer to an already allocated structure.
  85. @param the_handle previously given by mbrolib_init.
  86. @param the_parameters: pointer to the structure.
  87. @return error code (MBROLIB_OK, MBROLIB_INVAL).
  88. */
  89. MBROLIB_ERROR mbrolib_get_parameter(void* the_handle, mbrolib_parameter* the_parameter);
  90. typedef MBROLIB_ERROR (t_mbrolib_get_parameter)(void*, mbrolib_parameter*);
  91. /** Set the database parameters using the supplied data.
  92. @param the_handle previously given by mbrolib_init.
  93. @param the_parameters: pointer to the wished parameters.
  94. @return error code (MBROLIB_OK, MBROLIB_INVAL).
  95. */
  96. MBROLIB_ERROR mbrolib_set_parameter(void* the_handle, const mbrolib_parameter* the_parameter);
  97. typedef MBROLIB_ERROR (t_mbrolib_set_parameter)(void*, const mbrolib_parameter*);
  98. /** Write the mbrola phonemes in the internal buffer.
  99. @param the_handle.
  100. @param the_mbrola_phonemes.
  101. @param the_size in bytes.
  102. @return error code (MBROLIB_OK, MBROLIB_INVAL, MBROLIB_WRITE_ERROR, MBROLIB_READ_ERROR).
  103. */
  104. MBROLIB_ERROR mbrolib_write(void* the_handle, const char* the_mbrola_phonemes, size_t the_size);
  105. typedef MBROLIB_ERROR (t_mbrolib_write)(void*, const char*, size_t);
  106. /** Read n bytes of the output samples.
  107. @param the_handle.
  108. @param the_samples (raw audio data, 16bits, mono).
  109. @param the_size max number of int16 to read.
  110. @param the_size number of int16 read.
  111. @return error code (MBROLIB_OK, MBROLIB_INVAL, MBROLIB_READ_ERROR).
  112. */
  113. MBROLIB_ERROR mbrolib_read(void* the_handle, short* the_samples, int the_max_size, int* the_read_size);
  114. typedef MBROLIB_ERROR (t_mbrolib_read)(void*, short*, int, int*);
  115. /** Flush
  116. @param the_handle.
  117. */
  118. void mbrolib_flush(void* the_handle);
  119. typedef void (t_mbrolib_flush)(void*);
  120. /** Release the handle
  121. @param the_handle.
  122. @return error code (MBROLIB_OK, MBROLIB_INVAL).
  123. */
  124. MBROLIB_ERROR mbrolib_terminate(void* the_handle);
  125. typedef MBROLIB_ERROR (t_mbrolib_terminate)(void*);
  126. #ifdef __cplusplus
  127. }
  128. #endif
  129. #endif