eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tr_english.cpp 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /***************************************************************************
  2. * Copyright (C) 2005 to 2007 by Jonathan Duddington *
  3. * email: [email protected] *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 3 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write see: *
  17. * <http://www.gnu.org/licenses/>. *
  18. ***************************************************************************/
  19. #include "StdAfx.h"
  20. #include <stdio.h>
  21. #include <ctype.h>
  22. #include <wctype.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <locale.h>
  26. #include "speak_lib.h"
  27. #include "speech.h"
  28. #include "phoneme.h"
  29. #include "synthesize.h"
  30. #include "translate.h"
  31. #include "tr_languages.h"
  32. Translator_English::Translator_English() : Translator()
  33. {//===================================
  34. // static int stress_lengths2[8] = {182,140, 220,220, 220,240, 248,270};
  35. static const short stress_lengths2[8] = {182,140, 220,220, 0,0, 248,275};
  36. memcpy(stress_lengths,stress_lengths2,sizeof(stress_lengths));
  37. langopts.stress_rule = 0;
  38. langopts.numbers = 0x41 + NUM_ROMAN;
  39. langopts.param[LOPT_COMBINE_WORDS] = 2; // allow "mc" to cmbine with the following word
  40. }
  41. static unsigned char initials_bitmap[86] = {
  42. 0x00, 0x00, 0x00, 0x00, 0x22, 0x08, 0x00, 0x88, // 0
  43. 0x20, 0x24, 0x20, 0x80, 0x10, 0x00, 0x00, 0x00,
  44. 0x00, 0x28, 0x08, 0x00, 0x88, 0x22, 0x04, 0x00, // 16
  45. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  46. 0x00, 0x88, 0x22, 0x04, 0x00, 0x02, 0x00, 0x04, // 32
  47. 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  48. 0x00, 0x28, 0x8a, 0x03, 0x00, 0x00, 0x40, 0x00, // 48
  49. 0x02, 0x00, 0x41, 0xca, 0x9b, 0x06, 0x20, 0x80,
  50. 0x91, 0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x00, // 64
  51. 0x08, 0x20, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
  52. 0x00, 0x00, 0x22, 0x00, 0x01, 0x00, };
  53. int Translator_English::Unpronouncable(char *word)
  54. {//===============================================
  55. /* Determines whether a word in 'unpronouncable', i.e. whether it should
  56. be spoken as individual letters.
  57. This function is language specific.
  58. */
  59. unsigned char c;
  60. int vowel_posn=9;
  61. int index;
  62. int ix;
  63. int apostrophe=0;
  64. // words which we pass through to the dictionary, even though they look unpronouncable
  65. static const char *exceptions[] = {
  66. "'s ", "st ","nd ","rd ","th ",NULL };
  67. if((*word == ' ') || (*word == 0))
  68. return(0);
  69. for(ix=0; exceptions[ix] != NULL; ix++)
  70. {
  71. // Seemingly uncpronouncable words, but to be looked in the dictionary rules instead
  72. if(memcmp(word,exceptions[ix],3)==0)
  73. return(0);
  74. }
  75. index=0;
  76. while(((c = word[index++]) != 0) && !isspace(c))
  77. {
  78. if(IsVowel(c) || (c == 'y'))
  79. {
  80. vowel_posn = index;
  81. break;
  82. }
  83. if(c == '\'')
  84. apostrophe = 1;
  85. else
  86. if((c < 'a') || (c > 'z'))
  87. return(0); // letter (not vowel) outside a-z range or apostrophe, abort test
  88. }
  89. if((vowel_posn > 5) || ((word[0]!='s') && (vowel_posn > 4)))
  90. return(1); // no vowel, or no vowel in first four letters
  91. /* there is at least one vowel, is the initial letter combination valid ? */
  92. if(vowel_posn < 3)
  93. return(0); /* vowel in first two letters, OK */
  94. if(apostrophe)
  95. return(0); // first two letters not a-z, abort test
  96. index = (word[0]-'a') * 26 + (word[1]-'a');
  97. if(initials_bitmap[index >> 3] & (1L << (index & 7)))
  98. return(0);
  99. else
  100. return(1); /****/
  101. } /* end of Unpronounceable */