Skip to content

Commit 4a28902

Browse files
committed
code cleanup: new file langopts.c for handling language options.
The switch case in LoadVoice() currently mixes voice and language options. This change will start separating them into two functions. CheckTranslator will be moved to langopts.c. In the future there should be no need to use it in voices.c. There will be other temporary solutions also.
1 parent e23f68f commit 4a28902

7 files changed

Lines changed: 132 additions & 11 deletions

File tree

Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ src_libespeak_ng_la_SOURCES = \
165165
src/libespeak-ng/espeak_api.c \
166166
src/libespeak-ng/ieee80.c \
167167
src/libespeak-ng/intonation.c \
168+
src/libespeak-ng/langopts.c \
168169
src/libespeak-ng/mnemonics.c \
169170
src/libespeak-ng/numbers.c \
170171
src/libespeak-ng/readclause.c \
@@ -195,6 +196,7 @@ noinst_HEADERS = \
195196
src/libespeak-ng/ieee80.h \
196197
src/libespeak-ng/intonation.h \
197198
src/libespeak-ng/klatt.h \
199+
src/libespeak-ng/langopts.h \
198200
src/libespeak-ng/mbrola.h \
199201
src/libespeak-ng/mbrowrap.h \
200202
src/libespeak-ng/mnemonics.h \

android/jni/Android.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ ESPEAK_SOURCES := \
3030
src/libespeak-ng/ieee80.c \
3131
src/libespeak-ng/intonation.c \
3232
src/libespeak-ng/klatt.c \
33+
src/libespeak-ng/langopts.c \
3334
src/libespeak-ng/mnemonics.c \
3435
src/libespeak-ng/numbers.c \
3536
src/libespeak-ng/phoneme.c \

src/libespeak-ng/langopts.c

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright (C) 2005 to 2015 by Jonathan Duddington
3+
* email: jonsd@users.sourceforge.net
4+
* Copyright (C) 2015-2017 Reece H. Dunn
5+
* Copyright (C) 2022 Juho Hiltunen
6+
*
7+
* This program is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, see: <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
#include "config.h"
22+
23+
#include <errno.h>
24+
#include <stdint.h>
25+
#include <stdio.h>
26+
#include <stdlib.h>
27+
28+
#include <espeak-ng/espeak_ng.h>
29+
#include <espeak-ng/speak_lib.h>
30+
#include <espeak-ng/encoding.h>
31+
32+
#include "langopts.h"
33+
#include "mnemonics.h" // for MNEM_TAB
34+
#include "translate.h" // for Translator
35+
#include "voice.h" // for CheckTranslator()
36+
37+
enum {
38+
V_NAME = 1,
39+
V_LANGUAGE,
40+
V_GENDER,
41+
V_PHONEMES,
42+
V_DICTIONARY,
43+
V_VARIANTS,
44+
45+
V_MAINTAINER,
46+
V_STATUS,
47+
48+
// these affect voice quality, are independent of language
49+
V_FORMANT,
50+
V_PITCH,
51+
V_ECHO,
52+
V_FLUTTER,
53+
V_ROUGHNESS,
54+
V_CLARITY,
55+
V_TONE,
56+
V_VOICING,
57+
V_BREATH,
58+
V_BREATHW,
59+
60+
// these override defaults set by the translator
61+
V_LOWERCASE_SENTENCE,
62+
V_WORDGAP,
63+
V_INTONATION,
64+
V_TUNES,
65+
V_STRESSLENGTH,
66+
V_STRESSAMP,
67+
V_STRESSADD,
68+
V_DICTRULES,
69+
V_STRESSRULE,
70+
V_STRESSOPT,
71+
V_NUMBERS,
72+
73+
V_MBROLA,
74+
V_KLATT,
75+
V_FAST,
76+
V_SPEED,
77+
V_DICTMIN,
78+
79+
// these need a phoneme table to have been specified
80+
V_REPLACE,
81+
V_CONSONANTS
82+
};
83+
84+
static const MNEM_TAB langopts_tab[] = {
85+
{ "maintainer", V_MAINTAINER },
86+
{ "status", V_STATUS },
87+
{ "lowercaseSentence", V_LOWERCASE_SENTENCE },
88+
89+
{ NULL, 0 }
90+
};
91+
92+
extern int CheckTranslator(Translator *tr, const MNEM_TAB *keyword_tab, int key);
93+
94+
void LoadLanguageOptions(Translator *translator, int key ) {
95+
switch (key)
96+
{
97+
case V_LOWERCASE_SENTENCE: {
98+
if (CheckTranslator(translator, langopts_tab, key) != 0)
99+
break;
100+
101+
translator->langopts.lowercase_sentence = true;
102+
break;
103+
}
104+
105+
break;
106+
case V_MAINTAINER:
107+
case V_STATUS:
108+
break;
109+
}
110+
}

src/libespeak-ng/voice.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
#include <espeak-ng/espeak_ng.h>
2424

25+
#include "mnemonics.h"
26+
#include "translate.h"
27+
2528
#ifdef __cplusplus
2629
extern "C"
2730
{
@@ -81,6 +84,7 @@ extern espeak_VOICE current_voice_selected;
8184
extern voice_t *voice;
8285
extern int tone_points[12];
8386

87+
int CheckTranslator(Translator *tr, const MNEM_TAB *keyword_tab, int key);
8488
const char *SelectVoice(espeak_VOICE *voice_select, int *found);
8589
espeak_VOICE *SelectVoiceByName(espeak_VOICE **voices, const char *name);
8690
voice_t *LoadVoice(const char *voice_name, int control);

src/libespeak-ng/voices.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "voice.h" // for voice_t, DoVoiceChange, N_PEAKS
4242
#include "common.h" // for GetFileLength, strncpy0
4343
#include "dictionary.h" // for LoadDictionary
44+
#include "langopts.h" // for LoadLanguageOptions
4445
#include "mnemonics.h" // for LookupMnemName, MNEM_TAB
4546
#include "phoneme.h" // for REPLACE_PHONEMES, n_replace_pho...
4647
#include "speech.h" // for PATHSEP
@@ -50,6 +51,8 @@
5051
#include "translate.h" // for LANGUAGE_OPTIONS, DeleteTranslator
5152
#include "wavegen.h" // for InitBreath
5253

54+
55+
5356
static const MNEM_TAB genders[] = {
5457
{ "male", ENGENDER_MALE },
5558
{ "female", ENGENDER_FEMALE },
@@ -501,7 +504,7 @@ static void ReadNumbers(char *p, int *flags, int maxValue, const MNEM_TAB *keyw
501504
}
502505
}
503506

504-
static int CheckTranslator(Translator *tr, const MNEM_TAB *keyword_tab, int key)
507+
int CheckTranslator(Translator *tr, const MNEM_TAB *keyword_tab, int key)
505508
{
506509
// Return 0 if translator is set.
507510
// Return 1 and print an error message for specified key if not
@@ -629,6 +632,7 @@ voice_t *LoadVoice(const char *vname, int control)
629632

630633
key = LookupMnem(keyword_tab, buf);
631634

635+
LoadLanguageOptions(translator, key);
632636
switch (key)
633637
{
634638
case V_LANGUAGE:
@@ -693,14 +697,6 @@ voice_t *LoadVoice(const char *vname, int control)
693697
case V_FORMANT:
694698
VoiceFormant(p);
695699
break;
696-
case V_LOWERCASE_SENTENCE: {
697-
if (CheckTranslator(translator, keyword_tab, key) != 0)
698-
break;
699-
700-
translator->langopts.lowercase_sentence = true;
701-
break;
702-
}
703-
704700
case V_PITCH:
705701
// default is pitch 82 118
706702
if (sscanf(p, "%d %d", &pitch1, &pitch2) == 2) {

src/windows/libespeak-ng.vcxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
<ClCompile Include="..\libespeak-ng\ieee80.c" />
178178
<ClCompile Include="..\libespeak-ng\intonation.c" />
179179
<ClCompile Include="..\libespeak-ng\klatt.c" />
180+
<ClCompile Include="..\libespeak-ng\langopts.c" />
180181
<ClCompile Include="..\libespeak-ng\mbrowrap.c" />
181182
<ClCompile Include="..\libespeak-ng\mnemonics.c" />
182183
<ClCompile Include="..\libespeak-ng\numbers.c" />
@@ -210,6 +211,7 @@
210211
<ClInclude Include="..\libespeak-ng\common.h" />
211212
<ClInclude Include="..\libespeak-ng\error.h" />
212213
<ClInclude Include="..\libespeak-ng\klatt.h" />
214+
<ClInclude Include="..\libespeak-ng\langopts.h" />
213215
<ClInclude Include="..\libespeak-ng\mbrowrap.h" />
214216
<ClInclude Include="..\libespeak-ng\phoneme.h" />
215217
<ClInclude Include="..\libespeak-ng\sintab.h" />
@@ -232,4 +234,4 @@
232234
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
233235
<ImportGroup Label="ExtensionTargets">
234236
</ImportGroup>
235-
</Project>
237+
</Project>

src/windows/libespeak-ng.vcxproj.filters

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@
9090
<ClCompile Include="..\libespeak-ng\klatt.c">
9191
<Filter>Source Files</Filter>
9292
</ClCompile>
93+
<ClCompile Include="..\libespeak-ng\langopts.c">
94+
<Filter>Source Files</Filter>
95+
</ClCompile>
9396
<ClCompile Include="..\libespeak-ng\mbrowrap.c">
9497
<Filter>Source Files</Filter>
9598
</ClCompile>
@@ -197,6 +200,9 @@
197200
<ClInclude Include="..\libespeak-ng\klatt.h">
198201
<Filter>Header Files</Filter>
199202
</ClInclude>
203+
<ClInclude Include="..\libespeak-ng\langopts.h">
204+
<Filter>Header Files</Filter>
205+
</ClInclude>
200206
<ClInclude Include="..\libespeak-ng\mbrowrap.h">
201207
<Filter>Header Files</Filter>
202208
</ClInclude>
@@ -227,4 +233,4 @@
227233
<Filter>Source Files</Filter>
228234
</None>
229235
</ItemGroup>
230-
</Project>
236+
</Project>

0 commit comments

Comments
 (0)