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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /***************************************************************************
  2. * Copyright (C) 2005,2006 by Jonathan Duddington *
  3. * [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 2 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 to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #include "StdAfx.h"
  21. #include <stdio.h>
  22. #include <ctype.h>
  23. #include <wctype.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <locale.h>
  27. #include "speak_lib.h"
  28. #include "speech.h"
  29. #include "phoneme.h"
  30. #include "synthesize.h"
  31. #include "translate.h"
  32. #include "tr_languages.h"
  33. Translator_English::Translator_English() : Translator()
  34. {//===================================
  35. // static int stress_lengths2[8] = {182,140, 220,220, 220,240, 248,270};
  36. static int stress_lengths2[8] = {182,140, 220,220, 0,0, 248,275};
  37. memcpy(stress_lengths,stress_lengths2,sizeof(stress_lengths));
  38. langopts.vowel_pause = 0;
  39. langopts.stress_rule = 0;
  40. langopts.word_gap = 0;
  41. langopts.numbers = 0x41;
  42. }
  43. static unsigned char initials_bitmap[86] = {
  44. 0x00, 0x00, 0x00, 0x00, 0x22, 0x08, 0x00, 0x88, // 0
  45. 0x20, 0x24, 0x20, 0x80, 0x10, 0x00, 0x00, 0x00,
  46. 0x00, 0x28, 0x08, 0x00, 0x88, 0x22, 0x04, 0x00, // 16
  47. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  48. 0x00, 0x88, 0x22, 0x04, 0x00, 0x02, 0x00, 0x00, // 32
  49. 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  50. 0x00, 0x28, 0x8a, 0x03, 0x00, 0x00, 0x40, 0x00, // 48
  51. 0x02, 0x00, 0x41, 0xca, 0x9b, 0x06, 0x20, 0x80,
  52. 0x91, 0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x00, // 64
  53. 0x08, 0x20, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
  54. 0x00, 0x00, 0x22, 0x00, 0x01, 0x00, };
  55. int Translator_English::Unpronouncable(char *word)
  56. {//===============================================
  57. /* Determines whether a word in 'unpronouncable', i.e. whether it should
  58. be spoken as individual letters.
  59. This function is language specific.
  60. */
  61. unsigned char c;
  62. int vowel_posn=9;
  63. int index;
  64. int ix;
  65. int apostrophe=0;
  66. // words which we pass through to the dictionary, even though they look unpronouncable
  67. static const char *exceptions[] = {
  68. "'s ", "st ","nd ","rd ","th ",NULL };
  69. if((*word == ' ') || (*word == 0))
  70. return(0);
  71. for(ix=0; exceptions[ix] != NULL; ix++)
  72. {
  73. // Seemingly uncpronouncable words, but to be looked in the dictionary rules instead
  74. if(memcmp(word,exceptions[ix],3)==0)
  75. return(0);
  76. }
  77. index=0;
  78. while(((c = word[index++]) != 0) && !isspace(c))
  79. {
  80. if(IsVowel(c) || (c == 'y'))
  81. {
  82. vowel_posn = index;
  83. break;
  84. }
  85. if(c == '\'')
  86. apostrophe = 1;
  87. else
  88. if((c < 'a') || (c > 'z'))
  89. return(0); // letter (not vowel) outside a-z range or apostrophe, abort test
  90. }
  91. if((vowel_posn > 5) || ((word[0]!='s') && (vowel_posn > 4)))
  92. return(1); // no vowel, or no vowel in first four letters
  93. /* there is at least one vowel, is the initial letter combination valid ? */
  94. if(vowel_posn < 3)
  95. return(0); /* vowel in first two letters, OK */
  96. if(apostrophe)
  97. return(0); // first two letters not a-z, abort test
  98. index = (word[0]-'a') * 26 + (word[1]-'a');
  99. if(initials_bitmap[index >> 3] & (1L << (index & 7)))
  100. return(0);
  101. else
  102. return(1); /****/
  103. } /* end of Unpronounceable */