mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-11-07 23:31:26 +00:00
code cleanup: move ChangeWordStress()
This commit is contained in:
@@ -850,7 +850,7 @@ int Unpronouncable(Translator *tr, char *word, int posn)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int GetVowelStress(Translator *tr, unsigned char *phonemes, signed char *vowel_stress, int *vowel_count, int *stressed_syllable, int control)
|
||||
int GetVowelStress(Translator *tr, unsigned char *phonemes, signed char *vowel_stress, int *vowel_count, int *stressed_syllable, int control)
|
||||
{
|
||||
// control = 1, set stress to 1 for forced unstressed vowels
|
||||
unsigned char phcode;
|
||||
@@ -962,55 +962,11 @@ static int GetVowelStress(Translator *tr, unsigned char *phonemes, signed char *
|
||||
return max_stress;
|
||||
}
|
||||
|
||||
static char stress_phonemes[] = {
|
||||
const char stress_phonemes[] = {
|
||||
phonSTRESS_D, phonSTRESS_U, phonSTRESS_2, phonSTRESS_3,
|
||||
phonSTRESS_P, phonSTRESS_P2, phonSTRESS_TONIC
|
||||
};
|
||||
|
||||
void ChangeWordStress(Translator *tr, char *word, int new_stress)
|
||||
{
|
||||
int ix;
|
||||
unsigned char *p;
|
||||
int max_stress;
|
||||
int vowel_count; // num of vowels + 1
|
||||
int stressed_syllable = 0; // position of stressed syllable
|
||||
unsigned char phonetic[N_WORD_PHONEMES];
|
||||
signed char vowel_stress[N_WORD_PHONEMES/2];
|
||||
|
||||
strcpy((char *)phonetic, word);
|
||||
max_stress = GetVowelStress(tr, phonetic, vowel_stress, &vowel_count, &stressed_syllable, 0);
|
||||
|
||||
if (new_stress >= STRESS_IS_PRIMARY) {
|
||||
// promote to primary stress
|
||||
for (ix = 1; ix < vowel_count; ix++) {
|
||||
if (vowel_stress[ix] >= max_stress) {
|
||||
vowel_stress[ix] = new_stress;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// remove primary stress
|
||||
for (ix = 1; ix < vowel_count; ix++) {
|
||||
if (vowel_stress[ix] > new_stress) // >= allows for diminished stress (=1)
|
||||
vowel_stress[ix] = new_stress;
|
||||
}
|
||||
}
|
||||
|
||||
// write out phonemes
|
||||
ix = 1;
|
||||
p = phonetic;
|
||||
while (*p != 0) {
|
||||
if ((phoneme_tab[*p]->type == phVOWEL) && !(phoneme_tab[*p]->phflags & phNONSYLLABIC)) {
|
||||
if ((vowel_stress[ix] == STRESS_IS_DIMINISHED) || (vowel_stress[ix] > STRESS_IS_UNSTRESSED))
|
||||
*word++ = stress_phonemes[(unsigned char)vowel_stress[ix]];
|
||||
|
||||
ix++;
|
||||
}
|
||||
*word++ = *p++;
|
||||
}
|
||||
*word = 0;
|
||||
}
|
||||
|
||||
void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, int tonic, int control)
|
||||
{
|
||||
/* Guess stress pattern of word. This is language specific
|
||||
|
||||
@@ -31,15 +31,17 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern const char stress_phonemes[];
|
||||
|
||||
int LoadDictionary(Translator *tr, const char *name, int no_error);
|
||||
int HashDictionary(const char *string);
|
||||
const char *EncodePhonemes(const char *p, char *outptr, int *bad_phoneme);
|
||||
void DecodePhonemes(const char *inptr, char *outptr);
|
||||
char *WritePhMnemonic(char *phon_out, PHONEME_TAB *ph, PHONEME_LIST *plist, int use_ipa, int *flags);
|
||||
const char *GetTranslatedPhonemeString(int phoneme_mode);
|
||||
int GetVowelStress(Translator *tr, unsigned char *phonemes, signed char *vowel_stress, int *vowel_count, int *stressed_syllable, int control);
|
||||
int IsVowel(Translator *tr, int letter);
|
||||
int Unpronouncable(Translator *tr, char *word, int posn);
|
||||
void ChangeWordStress(Translator *tr, char *word, int new_stress);
|
||||
void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, int tonic, int control);
|
||||
void AppendPhonemes(Translator *tr, char *string, int size, const char *ph);
|
||||
int TranslateRules(Translator *tr, char *p_start, char *phonemes, int ph_size, char *end_phonemes, int word_flags, unsigned int *dict_flags);
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include "translate.h"
|
||||
#include "translateword.h"
|
||||
#include "common.h" // for strncpy0
|
||||
#include "dictionary.h" // for TranslateRules, LookupDictList, Cha...
|
||||
#include "dictionary.h" // for TranslateRules, LookupDictList
|
||||
#include "numbers.h" // for SetSpellingStress, ...
|
||||
#include "phoneme.h" // for phonSWITCH, PHONEME_TAB, phonPAUSE_...
|
||||
#include "readclause.h" // for towlower2
|
||||
@@ -46,6 +46,7 @@
|
||||
|
||||
|
||||
static void addPluralSuffixes(int flags, Translator *tr, char last_char, char *word_phonemes);
|
||||
static void ChangeWordStress(Translator *tr, char *word, int new_stress);
|
||||
static int CheckDottedAbbrev(char *word1);
|
||||
static int NonAsciiNumber(int letter);
|
||||
static char *SpeakIndividualLetters(Translator *tr, char *word, char *phonemes, int spell_word, ALPHABET *current_alphabet, char word_phonemes[]);
|
||||
@@ -667,6 +668,50 @@ int TranslateWord3(Translator *tr, char *word_start, WORD_TAB *wtab, char *word_
|
||||
}
|
||||
|
||||
|
||||
static void ChangeWordStress(Translator *tr, char *word, int new_stress)
|
||||
{
|
||||
int ix;
|
||||
unsigned char *p;
|
||||
int max_stress;
|
||||
int vowel_count; // num of vowels + 1
|
||||
int stressed_syllable = 0; // position of stressed syllable
|
||||
unsigned char phonetic[N_WORD_PHONEMES];
|
||||
signed char vowel_stress[N_WORD_PHONEMES/2];
|
||||
|
||||
strcpy((char *)phonetic, word);
|
||||
max_stress = GetVowelStress(tr, phonetic, vowel_stress, &vowel_count, &stressed_syllable, 0);
|
||||
|
||||
if (new_stress >= STRESS_IS_PRIMARY) {
|
||||
// promote to primary stress
|
||||
for (ix = 1; ix < vowel_count; ix++) {
|
||||
if (vowel_stress[ix] >= max_stress) {
|
||||
vowel_stress[ix] = new_stress;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// remove primary stress
|
||||
for (ix = 1; ix < vowel_count; ix++) {
|
||||
if (vowel_stress[ix] > new_stress) // >= allows for diminished stress (=1)
|
||||
vowel_stress[ix] = new_stress;
|
||||
}
|
||||
}
|
||||
|
||||
// write out phonemes
|
||||
ix = 1;
|
||||
p = phonetic;
|
||||
while (*p != 0) {
|
||||
if ((phoneme_tab[*p]->type == phVOWEL) && !(phoneme_tab[*p]->phflags & phNONSYLLABIC)) {
|
||||
if ((vowel_stress[ix] == STRESS_IS_DIMINISHED) || (vowel_stress[ix] > STRESS_IS_UNSTRESSED))
|
||||
*word++ = stress_phonemes[(unsigned char)vowel_stress[ix]];
|
||||
|
||||
ix++;
|
||||
}
|
||||
*word++ = *p++;
|
||||
}
|
||||
*word = 0;
|
||||
}
|
||||
|
||||
static char *SpeakIndividualLetters(Translator *tr, char *word, char *phonemes, int spell_word, ALPHABET *current_alphabet, char word_phonemes[])
|
||||
{
|
||||
int posn = 0;
|
||||
|
||||
Reference in New Issue
Block a user