Browse Source

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.
master
Juho Hiltunen 2 years ago
parent
commit
4a2890250b

+ 2
- 0
Makefile.am View File

src/libespeak-ng/espeak_api.c \ src/libespeak-ng/espeak_api.c \
src/libespeak-ng/ieee80.c \ src/libespeak-ng/ieee80.c \
src/libespeak-ng/intonation.c \ src/libespeak-ng/intonation.c \
src/libespeak-ng/langopts.c \
src/libespeak-ng/mnemonics.c \ src/libespeak-ng/mnemonics.c \
src/libespeak-ng/numbers.c \ src/libespeak-ng/numbers.c \
src/libespeak-ng/readclause.c \ src/libespeak-ng/readclause.c \
src/libespeak-ng/ieee80.h \ src/libespeak-ng/ieee80.h \
src/libespeak-ng/intonation.h \ src/libespeak-ng/intonation.h \
src/libespeak-ng/klatt.h \ src/libespeak-ng/klatt.h \
src/libespeak-ng/langopts.h \
src/libespeak-ng/mbrola.h \ src/libespeak-ng/mbrola.h \
src/libespeak-ng/mbrowrap.h \ src/libespeak-ng/mbrowrap.h \
src/libespeak-ng/mnemonics.h \ src/libespeak-ng/mnemonics.h \

+ 1
- 0
android/jni/Android.mk View File

src/libespeak-ng/ieee80.c \ src/libespeak-ng/ieee80.c \
src/libespeak-ng/intonation.c \ src/libespeak-ng/intonation.c \
src/libespeak-ng/klatt.c \ src/libespeak-ng/klatt.c \
src/libespeak-ng/langopts.c \
src/libespeak-ng/mnemonics.c \ src/libespeak-ng/mnemonics.c \
src/libespeak-ng/numbers.c \ src/libespeak-ng/numbers.c \
src/libespeak-ng/phoneme.c \ src/libespeak-ng/phoneme.c \

+ 110
- 0
src/libespeak-ng/langopts.c View File

/*
* Copyright (C) 2005 to 2015 by Jonathan Duddington
* email: [email protected]
* Copyright (C) 2015-2017 Reece H. Dunn
* Copyright (C) 2022 Juho Hiltunen
*
* 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 <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#include <espeak-ng/espeak_ng.h>
#include <espeak-ng/speak_lib.h>
#include <espeak-ng/encoding.h>

#include "langopts.h"
#include "mnemonics.h" // for MNEM_TAB
#include "translate.h" // for Translator
#include "voice.h" // for CheckTranslator()

enum {
V_NAME = 1,
V_LANGUAGE,
V_GENDER,
V_PHONEMES,
V_DICTIONARY,
V_VARIANTS,

V_MAINTAINER,
V_STATUS,

// these affect voice quality, are independent of language
V_FORMANT,
V_PITCH,
V_ECHO,
V_FLUTTER,
V_ROUGHNESS,
V_CLARITY,
V_TONE,
V_VOICING,
V_BREATH,
V_BREATHW,

// these override defaults set by the translator
V_LOWERCASE_SENTENCE,
V_WORDGAP,
V_INTONATION,
V_TUNES,
V_STRESSLENGTH,
V_STRESSAMP,
V_STRESSADD,
V_DICTRULES,
V_STRESSRULE,
V_STRESSOPT,
V_NUMBERS,

V_MBROLA,
V_KLATT,
V_FAST,
V_SPEED,
V_DICTMIN,

// these need a phoneme table to have been specified
V_REPLACE,
V_CONSONANTS
};

static const MNEM_TAB langopts_tab[] = {
{ "maintainer", V_MAINTAINER },
{ "status", V_STATUS },
{ "lowercaseSentence", V_LOWERCASE_SENTENCE },

{ NULL, 0 }
};

extern int CheckTranslator(Translator *tr, const MNEM_TAB *keyword_tab, int key);

void LoadLanguageOptions(Translator *translator, int key ) {
switch (key)
{
case V_LOWERCASE_SENTENCE: {
if (CheckTranslator(translator, langopts_tab, key) != 0)
break;

translator->langopts.lowercase_sentence = true;
break;
}

break;
case V_MAINTAINER:
case V_STATUS:
break;
}
}

+ 4
- 0
src/libespeak-ng/voice.h View File



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


#include "mnemonics.h"
#include "translate.h"

#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
extern voice_t *voice; extern voice_t *voice;
extern int tone_points[12]; extern int tone_points[12];


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

+ 5
- 9
src/libespeak-ng/voices.c View File

#include "voice.h" // for voice_t, DoVoiceChange, N_PEAKS #include "voice.h" // for voice_t, DoVoiceChange, N_PEAKS
#include "common.h" // for GetFileLength, strncpy0 #include "common.h" // for GetFileLength, strncpy0
#include "dictionary.h" // for LoadDictionary #include "dictionary.h" // for LoadDictionary
#include "langopts.h" // for LoadLanguageOptions
#include "mnemonics.h" // for LookupMnemName, MNEM_TAB #include "mnemonics.h" // for LookupMnemName, MNEM_TAB
#include "phoneme.h" // for REPLACE_PHONEMES, n_replace_pho... #include "phoneme.h" // for REPLACE_PHONEMES, n_replace_pho...
#include "speech.h" // for PATHSEP #include "speech.h" // for PATHSEP
#include "translate.h" // for LANGUAGE_OPTIONS, DeleteTranslator #include "translate.h" // for LANGUAGE_OPTIONS, DeleteTranslator
#include "wavegen.h" // for InitBreath #include "wavegen.h" // for InitBreath




static const MNEM_TAB genders[] = { static const MNEM_TAB genders[] = {
{ "male", ENGENDER_MALE }, { "male", ENGENDER_MALE },
{ "female", ENGENDER_FEMALE }, { "female", ENGENDER_FEMALE },
} }
} }


static int CheckTranslator(Translator *tr, const MNEM_TAB *keyword_tab, int key)
int CheckTranslator(Translator *tr, const MNEM_TAB *keyword_tab, int key)
{ {
// Return 0 if translator is set. // Return 0 if translator is set.
// Return 1 and print an error message for specified key if not // Return 1 and print an error message for specified key if not


key = LookupMnem(keyword_tab, buf); key = LookupMnem(keyword_tab, buf);


LoadLanguageOptions(translator, key);
switch (key) switch (key)
{ {
case V_LANGUAGE: case V_LANGUAGE:
case V_FORMANT: case V_FORMANT:
VoiceFormant(p); VoiceFormant(p);
break; break;
case V_LOWERCASE_SENTENCE: {
if (CheckTranslator(translator, keyword_tab, key) != 0)
break;

translator->langopts.lowercase_sentence = true;
break;
}

case V_PITCH: case V_PITCH:
// default is pitch 82 118 // default is pitch 82 118
if (sscanf(p, "%d %d", &pitch1, &pitch2) == 2) { if (sscanf(p, "%d %d", &pitch1, &pitch2) == 2) {

+ 3
- 1
src/windows/libespeak-ng.vcxproj View File

<ClCompile Include="..\libespeak-ng\ieee80.c" /> <ClCompile Include="..\libespeak-ng\ieee80.c" />
<ClCompile Include="..\libespeak-ng\intonation.c" /> <ClCompile Include="..\libespeak-ng\intonation.c" />
<ClCompile Include="..\libespeak-ng\klatt.c" /> <ClCompile Include="..\libespeak-ng\klatt.c" />
<ClCompile Include="..\libespeak-ng\langopts.c" />
<ClCompile Include="..\libespeak-ng\mbrowrap.c" /> <ClCompile Include="..\libespeak-ng\mbrowrap.c" />
<ClCompile Include="..\libespeak-ng\mnemonics.c" /> <ClCompile Include="..\libespeak-ng\mnemonics.c" />
<ClCompile Include="..\libespeak-ng\numbers.c" /> <ClCompile Include="..\libespeak-ng\numbers.c" />
<ClInclude Include="..\libespeak-ng\common.h" /> <ClInclude Include="..\libespeak-ng\common.h" />
<ClInclude Include="..\libespeak-ng\error.h" /> <ClInclude Include="..\libespeak-ng\error.h" />
<ClInclude Include="..\libespeak-ng\klatt.h" /> <ClInclude Include="..\libespeak-ng\klatt.h" />
<ClInclude Include="..\libespeak-ng\langopts.h" />
<ClInclude Include="..\libespeak-ng\mbrowrap.h" /> <ClInclude Include="..\libespeak-ng\mbrowrap.h" />
<ClInclude Include="..\libespeak-ng\phoneme.h" /> <ClInclude Include="..\libespeak-ng\phoneme.h" />
<ClInclude Include="..\libespeak-ng\sintab.h" /> <ClInclude Include="..\libespeak-ng\sintab.h" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>
</Project>
</Project>

+ 7
- 1
src/windows/libespeak-ng.vcxproj.filters View File

<ClCompile Include="..\libespeak-ng\klatt.c"> <ClCompile Include="..\libespeak-ng\klatt.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\libespeak-ng\langopts.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\libespeak-ng\mbrowrap.c"> <ClCompile Include="..\libespeak-ng\mbrowrap.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClInclude Include="..\libespeak-ng\klatt.h"> <ClInclude Include="..\libespeak-ng\klatt.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\libespeak-ng\langopts.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\libespeak-ng\mbrowrap.h"> <ClInclude Include="..\libespeak-ng\mbrowrap.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</None> </None>
</ItemGroup> </ItemGroup>
</Project>
</Project>

Loading…
Cancel
Save