/native/external/espeak/src/tr_english.cpp

http://eyes-free.googlecode.com/ · C++ · 138 lines · 81 code · 30 blank · 27 comment · 22 complexity · 43eaedc04ad377afef903ac5ca31aa87 MD5 · raw file

  1. /***************************************************************************
  2. * Copyright (C) 2005 to 2007 by Jonathan Duddington *
  3. * email: jonsd@users.sourceforge.net *
  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 = 0x841 + 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. int c;
  60. int vowel_posn=9;
  61. int index;
  62. int count;
  63. int ix;
  64. int apostrophe=0;
  65. // words which we pass through to the dictionary, even though they look unpronouncable
  66. static const char *exceptions[] = {
  67. "'s ", "st ","nd ","rd ","th ",NULL };
  68. if((*word == ' ') || (*word == 0))
  69. return(0);
  70. for(ix=0; exceptions[ix] != NULL; ix++)
  71. {
  72. // Seemingly uncpronouncable words, but to be looked in the dictionary rules instead
  73. if(memcmp(word,exceptions[ix],3)==0)
  74. return(0);
  75. }
  76. index=0;
  77. count=0;
  78. for(;;)
  79. {
  80. index += utf8_in(&c,&word[index],0);
  81. count++;
  82. if((c==0) || (c==' '))
  83. break;
  84. if(IsVowel(c) || (c == 'y'))
  85. {
  86. vowel_posn = count;
  87. break;
  88. }
  89. if(c == '\'')
  90. apostrophe = 1;
  91. else
  92. if(!IsAlpha(c))
  93. return(0); // letter (not vowel) outside Latin character range or apostrophe, abort test
  94. }
  95. if((vowel_posn > 5) || ((word[0]!='s') && (vowel_posn > 4)))
  96. return(1); // no vowel, or no vowel in first four letters
  97. /* there is at least one vowel, is the initial letter combination valid ? */
  98. if(vowel_posn < 3)
  99. return(0); /* vowel in first two letters, OK */
  100. if(apostrophe)
  101. return(0); // first two letters not a-z, abort test
  102. index = (word[0]-'a') * 26 + (word[1]-'a');
  103. if(initials_bitmap[index >> 3] & (1L << (index & 7)))
  104. return(0);
  105. else
  106. return(1); /****/
  107. } /* end of Unpronounceable */