[1.44.13]

Speed increase.  Added the "sonic" routines by Bill Cox to reduce the length of eSpeak's sound output data, so as to make the speaking speed faster.

Ordinal numbers: Some languages (el,es) use the ordinal form of hundreds and tens part of a number, as well as the units part.  Added language option NUM2_MULTIPLE_ORDINAL.


git-svn-id: https://espeak.svn.sourceforge.net/svnroot/espeak/trunk@254 d46cf337-b52f-0410-862d-fd96e6ae7743
This commit is contained in:
jonsd
2010-11-17 14:31:24 +00:00
parent 14e212f3a1
commit 1649824b33
44 changed files with 3659 additions and 1124 deletions
+5 -4
View File
@@ -6,7 +6,7 @@ INCDIR=$(PREFIX)/include/espeak
LIBDIR=$(PREFIX)/lib
DATADIR=$(PREFIX)/share/espeak-data
RELEASE = 1.43
RELEASE = 1.44
BIN_NAME = speak
BIN2_NAME = espeak
LIB_NAME = libespeak.so
@@ -80,10 +80,10 @@ all: $(BIN_NAME) $(LIB_NAME) $(STATIC_LIB_NAME) $(BIN2_NAME)
$(CXX) $(CXXFLAGS) $(USE_AUDIO) -D PATH_ESPEAK_DATA=\"$(DATADIR)\" -Wall -pedantic -I. -c -fno-exceptions $<
$(BIN_NAME): $(OBJS1)
$(CXX) -o $@ $(OBJS1) $(LIBS1)
$(CXX) $(LDFLAGS) -o $@ $(OBJS1) $(LIBS1)
$(BIN2_NAME): $(OBJS3) $(LIB_NAME)
$(CXX) -o $@ $(OBJS3) $(LIBS3)
$(CXX) $(LDFLAGS) -o $@ $(OBJS3) $(LIBS3)
@@ -92,7 +92,8 @@ x_%.o: %.cpp
-I. -D LIBRARY -c -fno-exceptions $< -o x_$*.o
$(LIB_NAME): $(OBJS2)
$(CXX) -shared $(SONAME_OPT)$(LIB_NAME).$(LIB_VERSION) -o $@ $(OBJS2) $(LIBS2)
$(CXX) $(LDFLAGS) -shared $(SONAME_OPT)$(LIB_NAME).$(LIB_VERSION) -o $@ \
$(OBJS2) $(LIBS2)
$(STATIC_LIB_NAME): $(OBJS2)
$(AR) cqs $(STATIC_LIB_NAME) $(OBJS2)
+2 -1
View File
@@ -140,6 +140,7 @@ static keywtab_t k_properties[] = {
{"isNotVowel", 0, i_isNotVowel},
{"isFinalVowel", 0, i_isFinalVowel},
{"isVoiced", 0, i_isVoiced}, // voiced consonant, or vowel
{"isFirstVowel", 0, i_isFirstVowel},
{NULL, 0, 0}
};
@@ -3259,7 +3260,7 @@ static void CompileEquivalents()
}
*p_equivalence++ = 0;
p_equivalence = (char *)((int)(p_equivalence + 3) & ~0x3); // align to word boundary
p_equivalence = (char *)((long int)(p_equivalence + 3) & ~0x3); // align to word boundary
n_bytes = p_equivalence - p_start;
p_start[1] = remove_stress;
n_bytes = n_bytes / 4;
+34 -13
View File
@@ -1111,6 +1111,7 @@ static int LookupNum2(Translator *tr, int value, int control, char *ph_out)
char ph_tens[50];
char ph_digits[50];
char ph_and[12];
char ph_ord_suffix[20];
units = value % 10;
tens = value / 10;
@@ -1202,12 +1203,20 @@ static int LookupNum2(Translator *tr, int value, int control, char *ph_out)
else
{
if((control & 1) && ((units == 0) || (tr->langopts.numbers & NUM_SWAP_TENS)))
if((control & 1) &&
((units == 0) || (tr->langopts.numbers & NUM_SWAP_TENS) || (tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL)))
{
sprintf(string,"_%dX%c", tens, ord_type);
if(Lookup(tr, string, ph_tens) != 0)
{
found_ordinal = 1;
if((units != 0) && (tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL))
{
// Use the ordinal form of tens as well as units. Add the ordinal ending
Lookup(tr, "_ord", ph_ord_suffix);
strcat(ph_tens, ph_ord_suffix);
}
}
}
if(found_ordinal == 0)
@@ -1290,6 +1299,10 @@ static int LookupNum2(Translator *tr, int value, int control, char *ph_out)
if((tr->langopts.numbers & (NUM_SWAP_TENS | NUM_AND_UNITS)) && (ph_tens[0] != 0) && (ph_digits[0] != 0))
{
Lookup(tr, "_0and", ph_and);
if(tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL)
ph_and[0] = 0;
if(tr->langopts.numbers & NUM_SWAP_TENS)
sprintf(ph_out,"%s%s%s%s",ph_digits, ph_and, ph_tens, ph_ordinal);
else
@@ -1355,7 +1368,8 @@ static int LookupNum3(Translator *tr, int value, char *ph_out, int suppress_null
char ph_thousands[50];
char ph_hundred_and[12];
char ph_thousand_and[12];
char ph_ord_suffix[20];
ordinal = control & 0x22;
hundreds = value / 100;
tensunits = value % 100;
@@ -1422,22 +1436,29 @@ static int LookupNum3(Translator *tr, int value, char *ph_out, int suppress_null
suppress_null = 1;
found = 0;
if(tensunits == 0)
if((ordinal)
&& ((tensunits == 0) || (tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL)))
{
// is there a special pronunciation for exactly n00 ?
// ordinal number
sprintf(string, "_%dCo", hundreds);
found = Lookup(tr, string, ph_digits);
if(ordinal)
if((tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL) && (tensunits > 0))
{
// ordinal number
sprintf(string, "_%dCo", hundreds);
found = Lookup(tr, string, ph_digits);
}
if(!found)
{
sprintf(string,"_%dC0",hundreds);
found = Lookup(tr, string, ph_digits);
// Use ordinal form of hundreds, as well as for tens and units
// Add ordinal suffix to the hundreds
Lookup(tr, "_ord", ph_ord_suffix);
strcat(ph_digits, ph_ord_suffix);
}
}
if((!found) && (tensunits == 0))
{
// is there a special pronunciation for exactly n00 ?
sprintf(string,"_%dC0",hundreds);
found = Lookup(tr, string, ph_digits);
}
if(!found)
{
sprintf(string,"_%dC",hundreds);
+16 -12
View File
@@ -140,6 +140,7 @@ void SetSpeed(int control)
int s1;
int wpm;
int wpm2;
double wpm_inc;
speed.loud_consonants = 0;
speed.min_sample_len = 450;
@@ -150,6 +151,21 @@ void SetSpeed(int control)
if(control == 2)
wpm = embedded_value[EMBED_S2];
// fast_settings[0] wpm where speedup starts
// fast_settings[1] wpm for maximum espeak speed
// fast_settings[2] maximum espeak speed
sonicSpeed = 1.0;
if(wpm > speed.fast_settings[0])
{
wpm2 = wpm;
wpm_inc = (double)(speed.fast_settings[2] - speed.fast_settings[0]) / (double)(speed.fast_settings[1] - speed.fast_settings[0]);
wpm_inc = (wpm2 - speed.fast_settings[0]) * wpm_inc;
wpm = speed.fast_settings[0] + (int)wpm_inc;
sonicSpeed = ((double)wpm2)/wpm;
}
#ifdef TEST_SPEED
if(wpm > 1000)
{
@@ -262,18 +278,6 @@ void SetSpeed(int control)
if((speed.clause_pause_factor = speed.pause_factor) < 16)
speed.clause_pause_factor = 16;
}
if(wpm >= 370)
{
// TESTING
// use experimental fast settings if they have been specified in the Voice
if(speed.fast_settings[0] > 0)
speed.pause_factor = speed.fast_settings[0];
if(speed.fast_settings[1] > 0)
speed.wav_factor = speed.fast_settings[1];
if(speed.fast_settings[2] > 0)
speed.lenmod_factor = speed.lenmod2_factor = speed.fast_settings[2];
}
}
#ifdef TEST_SPEED
+1 -1
View File
@@ -289,7 +289,7 @@ void MarkerEvent(int type, unsigned int char_position, int value, unsigned char
static int WavegenFile(void)
{//=========================
int finished;
unsigned char wav_outbuf[512];
unsigned char wav_outbuf[1024];
char fname[210];
out_ptr = out_start = wav_outbuf;
+14 -1
View File
@@ -35,7 +35,7 @@
#include "translate.h"
#include "wave.h"
const char *version_string = "1.44.04 14.Sep.10";
const char *version_string = "1.44.13 17.Nov.10";
const int version_phdata = 0x014404;
int option_device_number = -1;
@@ -593,6 +593,7 @@ static bool InterpretCondition(Translator *tr, int control, PHONEME_LIST *plist,
int which;
unsigned int data;
int instn2;
int count;
PHONEME_TAB *ph;
PHONEME_LIST *plist_this;
static int ph_position[8] = {0, 1, 2, 3, 2, 0, 1, 3}; // prevPh, thisPh, nextPh, next2Ph, nextPhW, prevPhW, nextVowel, next2PhW
@@ -737,6 +738,18 @@ static bool InterpretCondition(Translator *tr, int control, PHONEME_LIST *plist,
case 12: // isVoiced
return((ph->type == phVOWEL) || (ph->type == phLIQUID) || (ph->phflags & phVOICED));
}
case 13: // isFirstVowel
count = 0;
for(;;)
{
if(plist->ph->type == phVOWEL)
count++;
if(plist->sourceix != 0)
break;
plist--;
}
return(count==1);
break;
}
+2
View File
@@ -326,6 +326,7 @@ typedef struct {
#define i_isNotVowel 0x8a
#define i_isFinalVowel 0x8b
#define i_isVoiced 0x8c
#define i_isFirstVowel 0x8d
// place of articulation
#define i_isVel 0x28
@@ -535,6 +536,7 @@ extern t_espeak_callback* synth_callback;
extern int option_log_frames;
extern const char *version_string;
extern const int version_phdata;
extern double sonicSpeed;
#define N_SOUNDICON_TAB 80 // total entries in soundicon_tab
#define N_SOUNDICON_SLOTS 4 // number of slots reserved for dynamic loading of audio files
+16 -6
View File
@@ -328,6 +328,9 @@ Translator *SelectTranslator(const char *name)
int name2 = 0;
Translator *tr;
static const short stress_lengths_fr[8] = {190, 170, 190, 200, 0, 0, 190, 240};
static const unsigned char stress_amps_fr[8] = {18,16, 18,18, 18,18, 18,18 };
static const unsigned char stress_amps_sk[8] = {17,17, 20,20, 20,22, 22,21 };
static const short stress_lengths_sk[8] = {190,190, 210,210, 0,0, 210,210};
@@ -355,6 +358,17 @@ Translator *SelectTranslator(const char *name)
}
break;
case L('a','m'): // Amharic, Ethiopia
{
SetupTranslator(tr,stress_lengths_fr,stress_amps_fr);
tr->langopts.stress_rule = STRESSPOSN_1L;
tr->langopts.stress_flags = 0x0024; // don't use secondary stress
tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1; // disable check for unpronouncable words
}
break;
case L('a','r'): // Arabic
tr->letter_bits_offset = OFFSET_ARABIC;
tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1; // disable check for unpronouncable words
@@ -496,7 +510,7 @@ Translator *SelectTranslator(const char *name)
tr->langopts.param[LOPT_SONORANT_MIN] = 130; // limit the shortening of sonorants before short vowels
tr->langopts.numbers = NUM_SINGLE_STRESS | NUM_DECIMAL_COMMA;
tr->langopts.numbers2 = 0x2; // variant form of numbers before thousands
tr->langopts.numbers2 = 0x2 | NUM2_MULTIPLE_ORDINAL; // variant form of numbers before thousands
if(name2 == L_grc)
{
@@ -550,6 +564,7 @@ Translator *SelectTranslator(const char *name)
tr->langopts.param[LOPT_SONORANT_MIN] = 120; // limit the shortening of sonorants before short vowels
tr->langopts.numbers = NUM_SINGLE_STRESS | NUM_DECIMAL_COMMA | NUM_AND_UNITS | NUM_OMIT_1_HUNDRED | NUM_OMIT_1_THOUSAND | NUM_ROMAN | NUM_ROMAN_AFTER;
tr->langopts.numbers2 = NUM2_MULTIPLE_ORDINAL;
if(name2 == L('c','a'))
{
@@ -611,16 +626,12 @@ Translator *SelectTranslator(const char *name)
case L('f','r'): // french
{
static const short stress_lengths_fr[8] = {190, 170, 190, 200, 0, 0, 190, 240};
static const unsigned char stress_amps_fr[8] = {18,16, 20,20, 20,22, 18,18 };
SetupTranslator(tr,stress_lengths_fr,stress_amps_fr);
tr->langopts.stress_rule = STRESSPOSN_1R; // stress on final syllable
tr->langopts.stress_flags = 0x0024; // don't use secondary stress
tr->langopts.param[LOPT_IT_LENGTHEN] = 1; // remove lengthen indicator from unstressed syllables
tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
tr->langopts.accents = 2; // Say "Capital" after the letter.
tr->langopts.vowel_pause = 0;
tr->langopts.numbers = NUM_SINGLE_STRESS | NUM_DECIMAL_COMMA | NUM_ALLOW_SPACE | NUM_OMIT_1_HUNDRED | NUM_NOPAUSE | NUM_ROMAN | NUM_ROMAN_CAPITALS | NUM_ROMAN_AFTER | NUM_VIGESIMAL | NUM_DFRACTION_4;
SetLetterVowel(tr,'y');
@@ -685,7 +696,6 @@ Translator *SelectTranslator(const char *name)
case L('h','t'): // Haitian Creole
// static const short stress_lengths_fr[8] = {190, 170, 190, 200, 0, 0, 235, 240};
// memcpy(tr->stress_lengths,stress_lengths_fr,sizeof(tr->stress_lengths));
tr->langopts.stress_rule = STRESSPOSN_1R; // stress on final syllable
tr->langopts.stress_flags = 0x0024; // don't use secondary stress
+2
View File
@@ -427,11 +427,13 @@ typedef struct {
// bit27= Roman numbers are ordinal numbers
int numbers;
#define NUM2_MULTIPLE_ORDINAL 0x1000
// bits 1-4 use variant form of numbers before thousands,millions,etc.
// bit6=(LANG=pl) two forms of plural, M or MA
// bit7=(LANG-ru) use MB for 1 thousand, million, etc
// bit8=(LANG=cs,sk) two forms of plural, M or MA
// bit9=(LANG=rw) say "thousand" and "million" before its number, not after
// bit12=(LANG=el,es) use ordinal form of hundreds and tens as well as units
int numbers2;
#define BREAK_THOUSANDS 0x49249248
+5 -2
View File
@@ -152,7 +152,7 @@ static MNEM_TAB keyword_tab[] = {
{"mbrola", V_MBROLA},
{"consonants", V_CONSONANTS},
{"klatt", V_KLATT},
{"fast_test", V_FAST},
{"fast_test2", V_FAST},
{"speed", V_SPEED},
// these just set a value in langopts.param[]
@@ -410,7 +410,10 @@ void VoiceReset(int tone_only)
voice->consonant_ampv = 100;
voice->samplerate = 22050;
memset(voice->klattv,0,sizeof(voice->klattv));
memset(speed.fast_settings,0,sizeof(speed.fast_settings));
speed.fast_settings[0] = 250;
speed.fast_settings[1] = 600;
speed.fast_settings[2] = 300;
#ifdef PLATFORM_RISCOS
voice->roughness = 1;
+101 -21
View File
@@ -28,11 +28,13 @@
#include <math.h>
#include "speak_lib.h"
#include "speech.h"
#include "phoneme.h"
#include "synthesize.h"
#include "voice.h"
#include "sonic.h"
//#undef INCLUDE_KLATT
@@ -134,7 +136,7 @@ int wcmdq_tail=0;
// pitch,speed,
int embedded_default[N_EMBEDDED_VALUES] = {0, 50,175,100,50, 0, 0, 0,175,0,0,0,0,0,0};
static int embedded_max[N_EMBEDDED_VALUES] = {0,0x7fff,600,300,99,99,99, 0,600,0,0,0,0,4,0};
static int embedded_max[N_EMBEDDED_VALUES] = {0,0x7fff,750,300,99,99,99, 0,750,0,0,0,0,4,0};
#define N_CALLBACK_IX N_WAV_BUF-2 // adjust this delay to match display with the currently spoken word
int current_source_index=0;
@@ -148,7 +150,8 @@ static PortAudioStream *pa_stream=NULL;
static PaStream *pa_stream=NULL;
#endif
static sonicStream sonicSpeedupStream = NULL;
double sonicSpeed = 1.0;
// 1st index=roughness
// 2nd index=modulation_type
@@ -256,8 +259,6 @@ unsigned char pitch_adjust_tab[MAX_PITCH_VALUE+1] = {
217,220,223,226,229,232,236,239,
242,246,249,252, 254,255 };
int WavegenFill(int fill_zeros);
#ifdef LOG_FRAMES
static void LogMarker(int type, int value)
@@ -413,6 +414,10 @@ static int userdata[4];
static PaError pa_init_err=0;
static int out_channels=1;
unsigned char *outbuffer = NULL;
int outbuffer_size = 0;
#if USE_PORTAUDIO == 18
static int WaveCallback(void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer, PaTimestamp outTime, void *userData )
@@ -425,9 +430,26 @@ static int WaveCallback(const void *inputBuffer, void *outputBuffer,
int ix;
int result;
unsigned char *p;
unsigned char *out_buf;
unsigned char *out_end2;
int pa_size;
out_ptr = out_start = (unsigned char *)outputBuffer;
out_end = out_ptr + framesPerBuffer*2;
pa_size = framesPerBuffer*2;
// make a buffer 3x size of the portaudio output
ix = pa_size*3;
if(ix > outbuffer_size)
{
outbuffer = (unsigned char *)realloc(outbuffer, ix);
if(outbuffer == NULL)
{
fprintf(stderr, "espeak: out of memory\n");
}
outbuffer_size = ix;
out_ptr = out_start = outbuffer;
out_end = out_start + outbuffer_size;
}
out_end2 = &outbuffer[pa_size]; // top of data needed for the portaudio buffer
#ifdef LIBRARY
event_list_ix = 0;
@@ -435,6 +457,24 @@ static int WaveCallback(const void *inputBuffer, void *outputBuffer,
result = WavegenFill(1);
// copy from the outbut buffer into the portaudio buffer
if(result && (out_ptr > out_end2))
{
result = 0; // don't end yet, there is more data in the buffer than can fit in portaudio
}
while(out_ptr < out_end2)
*out_ptr++ = 0; // fill with zeros up to the size of the portaudio buffer
memcpy(outputBuffer, outbuffer, pa_size);
// move the remaining contents of the start of the output buffer
for(p = out_end2; p < out_end; p++)
{
p[-pa_size] = p[0];
}
out_ptr -= pa_size;
#ifdef LIBRARY
count_samples += framesPerBuffer;
if(synth_callback)
@@ -455,14 +495,15 @@ static int WaveCallback(const void *inputBuffer, void *outputBuffer,
{
// swap the order of bytes in each sound sample in the portaudio buffer
int c;
out_ptr = (unsigned char *)outputBuffer;
out_end = out_ptr + framesPerBuffer*2;
while(out_ptr < out_end)
unsigned char *buf_end;
out_buf = (unsigned char *)outputBuffer;
buf_end = out_buf + framesPerBuffer*2;
while(out_buf < buf_end)
{
c = out_ptr[0];
out_ptr[0] = out_ptr[1];
out_ptr[1] = c;
out_ptr += 2;
c = out_buf[0];
out_buf[0] = out_buf[1];
out_buf[1] = c;
out_buf += 2;
}
}
#endif
@@ -471,12 +512,12 @@ static int WaveCallback(const void *inputBuffer, void *outputBuffer,
{
// sound output can only do stereo, not mono. Duplicate each sound sample to
// produce 2 channels.
out_ptr = (unsigned char *)outputBuffer;
out_buf = (unsigned char *)outputBuffer;
for(ix=framesPerBuffer-1; ix>=0; ix--)
{
p = &out_ptr[ix*4];
p[3] = p[1] = out_ptr[ix*2 + 1];
p[2] = p[0] = out_ptr[ix*2];
p = &out_buf[ix*4];
p[3] = p[1] = out_buf[ix*2 + 1];
p[2] = p[0] = out_buf[ix*2];
}
}
@@ -1791,8 +1832,7 @@ void Write4Bytes(FILE *f, int value)
int WavegenFill(int fill_zeros)
int WavegenFill2(int fill_zeros)
{//============================
// Pick up next wavegen commands from the queue
// return: 0 output buffer has been filled
@@ -1930,6 +1970,46 @@ int WavegenFill(int fill_zeros)
}
return(0);
} // end of WavegenFill2
/* Speed up the audio samples with libsonic. */
static int SpeedUp(short *outbuf, int length, int end_of_text)
{//===========================================================
if(sonicSpeedupStream != NULL && sonicGetSpeed(sonicSpeedupStream) != sonicSpeed)
{
sonicDestroyStream(sonicSpeedupStream);
sonicSpeedupStream = NULL;
}
if(sonicSpeedupStream == NULL)
{
sonicSpeedupStream = sonicCreateStream(sonicSpeed, 22050);
}
sonicWriteShortToStream(sonicSpeedupStream, outbuf, length);
if(end_of_text)
{
sonicFlushStream(sonicSpeedupStream);
}
return sonicReadShortFromStream(sonicSpeedupStream, outbuf, length);
} // end of SpeedUp
/* Call WavegenFill2, and then speed up the output samples. */
int WavegenFill(int fill_zeros)
{//============================
int finished;
unsigned char *p_start;
p_start = out_ptr;
// fill_zeros is ignored. It is now done in the portaudio cakkback
finished = WavegenFill2(0);
if(sonicSpeed > 1.0 && out_ptr > p_start)
{
out_ptr = p_start + 2*SpeedUp((short *)p_start, (out_ptr-p_start)/2, finished);
}
return finished;
} // end of WavegenFill