The file will be organized to have one callable function only. This should make code structure simpler. Existing code will be changed to use function parameters instead of global variables. Possible problems include too much dependencies with numbers.c.master
@@ -174,6 +174,7 @@ src_libespeak_ng_la_SOURCES = \ | |||
src/libespeak-ng/synthesize.c \ | |||
src/libespeak-ng/synth_mbrola.c \ | |||
src/libespeak-ng/translate.c \ | |||
src/libespeak-ng/translateword.c \ | |||
src/libespeak-ng/tr_languages.c \ | |||
src/libespeak-ng/voices.c \ | |||
src/libespeak-ng/wavegen.c | |||
@@ -205,6 +206,7 @@ noinst_HEADERS = \ | |||
src/libespeak-ng/synthdata.h \ | |||
src/libespeak-ng/synthesize.h \ | |||
src/libespeak-ng/translate.h \ | |||
src/libespeak-ng/translateword.h \ | |||
src/libespeak-ng/voice.h \ | |||
src/libespeak-ng/wavegen.h \ | |||
src/speechPlayer/include/speechPlayer.h \ |
@@ -44,6 +44,7 @@ ESPEAK_SOURCES := \ | |||
src/libespeak-ng/synthesize.c \ | |||
src/libespeak-ng/synth_mbrola.c \ | |||
src/libespeak-ng/translate.c \ | |||
src/libespeak-ng/translateword.c \ | |||
src/libespeak-ng/tr_languages.c \ | |||
src/libespeak-ng/voices.c \ | |||
src/libespeak-ng/wavegen.c |
@@ -43,6 +43,7 @@ | |||
#include "ucd/ucd.h" // for ucd_toupper | |||
#include "voice.h" // for voice, voice_t | |||
#include "speech.h" // for MAKE_MEM_UNDEFINED | |||
#include "translateword.h" | |||
Translator *translator = NULL; // the main translator | |||
Translator *translator2 = NULL; // secondary translator for certain words | |||
@@ -388,31 +389,6 @@ static void addPluralSuffixes(int flags, Translator *tr, char last_char, char *w | |||
} | |||
} | |||
static char *SpeakIndividualLetters(Translator *tr, char *word, char *phonemes, int spell_word) | |||
{ | |||
int posn = 0; | |||
int capitals = 0; | |||
bool non_initial = false; | |||
if (spell_word > 2) | |||
capitals = 2; // speak 'capital' | |||
if (spell_word > 1) | |||
capitals |= 4; // speak character code for unknown letters | |||
while ((*word != ' ') && (*word != 0)) { | |||
word += TranslateLetter(tr, word, phonemes, capitals | non_initial, current_alphabet); | |||
posn++; | |||
non_initial = true; | |||
if (phonemes[0] == phonSWITCH) { | |||
// change to another language in order to translate this word | |||
strcpy(word_phonemes, phonemes); | |||
return NULL; | |||
} | |||
} | |||
SetSpellingStress(tr, phonemes, spell_word, posn); | |||
return word; | |||
} | |||
static int CheckDottedAbbrev(char *word1) | |||
{ | |||
int wc; | |||
@@ -665,7 +641,7 @@ static int TranslateWord3(Translator *tr, char *word_start, WORD_TAB *wtab, char | |||
// Speak as individual letters | |||
phonemes[0] = 0; | |||
if (SpeakIndividualLetters(tr, word1, phonemes, spell_word) == NULL) { | |||
if (SpeakIndividualLetters(tr, word1, phonemes, spell_word, current_alphabet, word_phonemes) == NULL) { | |||
if (word_length > 1) | |||
return FLAG_SPELLWORD; // a mixture of languages, retranslate as individual letters, separated by spaces | |||
return 0; | |||
@@ -737,7 +713,7 @@ static int TranslateWord3(Translator *tr, char *word_start, WORD_TAB *wtab, char | |||
// ?? should we say super/sub-script numbers and letters here? | |||
utf8_in(&wc, wordx); | |||
if ((word_length == 1) && (IsAlpha(wc) || IsSuperscript(wc))) { | |||
if ((wordx = SpeakIndividualLetters(tr, wordx, phonemes, spell_word)) == NULL) | |||
if ((wordx = SpeakIndividualLetters(tr, wordx, phonemes, spell_word, current_alphabet, word_phonemes)) == NULL) | |||
return 0; | |||
strcpy(word_phonemes, phonemes); | |||
return 0; | |||
@@ -824,7 +800,7 @@ static int TranslateWord3(Translator *tr, char *word_start, WORD_TAB *wtab, char | |||
strcpy(prefix_phonemes, phonemes); | |||
if (dictionary_flags[0] & FLAG_ABBREV) { | |||
prefix_phonemes[0] = 0; | |||
SpeakIndividualLetters(tr, wordpf, prefix_phonemes, 1); | |||
SpeakIndividualLetters(tr, wordpf, prefix_phonemes, 1, current_alphabet, word_phonemes); | |||
} | |||
} else | |||
strcat(prefix_phonemes, end_phonemes); |
@@ -0,0 +1,70 @@ | |||
/* | |||
* Copyright (C) 2005 to 2014 by Jonathan Duddington | |||
* email: [email protected] | |||
* Copyright (C) 2015-2017 Reece H. Dunn | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation; either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, see: <http://www.gnu.org/licenses/>. | |||
*/ | |||
#include "config.h" | |||
#include <ctype.h> | |||
#include <stdbool.h> | |||
#include <stdint.h> | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <string.h> | |||
#include <wchar.h> | |||
#include <wctype.h> | |||
#include <espeak-ng/espeak_ng.h> | |||
#include <espeak-ng/speak_lib.h> | |||
#include <espeak-ng/encoding.h> | |||
#include "translate.h" | |||
#include "dictionary.h" // for TranslateRules, LookupDictList, Cha... | |||
#include "numbers.h" // for SetSpellingStress, TranslateLetter | |||
#include "phoneme.h" // for phonSWITCH, PHONEME_TAB, phonPAUSE_... | |||
#include "phonemelist.h" // for MakePhonemeList | |||
#include "readclause.h" // for towlower2, Eof, ReadClause, is_str_... | |||
#include "synthdata.h" // for SelectPhonemeTable, LookupPhonemeTable | |||
#include "synthesize.h" // for PHONEME_LIST2, N_PHONEME_LIST, PHON... | |||
#include "ucd/ucd.h" // for ucd_toupper | |||
#include "voice.h" // for voice, voice_t | |||
#include "speech.h" // for MAKE_MEM_UNDEFINED | |||
char *SpeakIndividualLetters(Translator *tr, char *word, char *phonemes, int spell_word, ALPHABET *current_alphabet, char word_phonemes[]) | |||
{ | |||
int posn = 0; | |||
int capitals = 0; | |||
bool non_initial = false; | |||
if (spell_word > 2) | |||
capitals = 2; // speak 'capital' | |||
if (spell_word > 1) | |||
capitals |= 4; // speak character code for unknown letters | |||
while ((*word != ' ') && (*word != 0)) { | |||
word += TranslateLetter(tr, word, phonemes, capitals | non_initial, current_alphabet); | |||
posn++; | |||
non_initial = true; | |||
if (phonemes[0] == phonSWITCH) { | |||
// change to another language in order to translate this word | |||
strcpy(word_phonemes, phonemes); | |||
return NULL; | |||
} | |||
} | |||
SetSpellingStress(tr, phonemes, spell_word, posn); | |||
return word; | |||
} |
@@ -0,0 +1,39 @@ | |||
/* | |||
* Copyright (C) 2005 to 2014 by Jonathan Duddington | |||
* email: [email protected] | |||
* Copyright (C) 2015-2017, 2020 Reece H. Dunn | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation; either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, see: <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ESPEAK_NG_TRANSLATEWORD_H | |||
#define ESPEAK_NG_TRANSLATEWORd_H | |||
#include <stdbool.h> | |||
#include <espeak-ng/espeak_ng.h> | |||
#include <espeak-ng/encoding.h> | |||
#ifdef __cplusplus | |||
extern "C" | |||
{ | |||
#endif | |||
char *SpeakIndividualLetters(Translator *tr, char *word, char *phonemes, int spell_word, ALPHABET *current_alphabet, char word_phonemes[]); | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif |