This commit is contained in:
Reece Dunn
2011-12-31 15:56:27 +00:00
parent 4e0dccc4b9
commit 812bd35f73
17 changed files with 271 additions and 76 deletions
+28 -28
View File
@@ -524,27 +524,33 @@ unsigned short ipa1[96] = {
};
static void WritePhMnemonic(char **buf, PHONEME_TAB *ph, PHONEME_LIST *plist)
{//=======================================================================================
char *WritePhMnemonic(char *phon_out, PHONEME_TAB *ph, PHONEME_LIST *plist, int use_ipa)
{//=====================================================================================
int c;
int mnem;
int len;
int first;
int ix = 0;
char *phon_out;
char *p;
unsigned int ipa_control=0; // first byte of ipa string may control the phoneme name interpretation. 0x20 = ignore this phoneme
PHONEME_DATA phdata;
phon_out = *buf;
if(ph->code == phonEND_WORD)
{
// ignore
phon_out[0] = 0;
return;
return(phon_out);
}
if(option_phonemes == 3)
if(ph->code == phonSWITCH)
{
// the tone_ph field contains a phoneme table number
p = phoneme_tab_list[plist->tone_ph].name;
sprintf(phon_out, "(%s)", p);
return(phon_out + strlen(phon_out));
}
if(use_ipa)
{
// has an ipa name been defined for this phoneme ?
phdata.ipa_string[0] = 0;
@@ -568,8 +574,9 @@ static void WritePhMnemonic(char **buf, PHONEME_TAB *ph, PHONEME_LIST *plist)
}
if(ipa_control >= 0x20)
{
*buf += ix;
return; // 0x20 = ignore phoneme
phon_out = &phon_out[ix];
*phon_out = 0;
return(phon_out); // 0x20 = ignore phoneme
}
}
}
@@ -580,7 +587,7 @@ static void WritePhMnemonic(char **buf, PHONEME_TAB *ph, PHONEME_LIST *plist)
if((c == '/') && (option_phoneme_variants==0))
break; // discard phoneme variant indicator
if(option_phonemes == 3)
if(use_ipa)
{
// convert from ascii to ipa
if(first && (c == '_'))
@@ -605,13 +612,15 @@ static void WritePhMnemonic(char **buf, PHONEME_TAB *ph, PHONEME_LIST *plist)
first = 0;
}
*buf += ix;
phon_out = &phon_out[ix];
*phon_out = 0;
return(phon_out);
} // end of WritePhMnemonic
void GetTranslatedPhonemeString(char *phon_out, int n_phon_out)
{//============================================================
void GetTranslatedPhonemeString(char *phon_out, int n_phon_out, int use_ipa)
{//=========================================================================
/* Can be called after a clause has been translated into phonemes, in order
to display the clause in phoneme mnemonic form.
*/
@@ -622,7 +631,6 @@ void GetTranslatedPhonemeString(char *phon_out, int n_phon_out)
int phon_out_ix=0;
int stress;
unsigned int c;
char *p;
char *buf;
char phon_buf[30];
PHONEME_LIST *plist;
@@ -646,7 +654,7 @@ void GetTranslatedPhonemeString(char *phon_out, int n_phon_out)
c = 0;
if(stress > 5) stress = 5;
if(option_phonemes == 3)
if(use_ipa)
{
c = 0x2cc; // ipa, secondary stress
if(stress > 3)
@@ -664,30 +672,22 @@ void GetTranslatedPhonemeString(char *phon_out, int n_phon_out)
}
}
if(plist->ph->code == phonSWITCH)
{
// the tone_ph field contains a phoneme table number
p = phoneme_tab_list[plist->tone_ph].name;
buf = WritePhMnemonic(buf, plist->ph, plist, use_ipa);
sprintf(buf, "(%s)", p);
buf += (strlen(p) + 2);
}
else
if(plist->ph->code != phonSWITCH)
{
WritePhMnemonic(&buf, plist->ph, plist);
if(plist->synthflags & SFLAG_LENGTHEN)
{
WritePhMnemonic(&buf, phoneme_tab[phonLENGTHEN], NULL);
buf = WritePhMnemonic(buf, phoneme_tab[phonLENGTHEN], NULL, use_ipa);
}
if((plist->synthflags & SFLAG_SYLLABLE) && (plist->type != phVOWEL))
{
// syllablic consonant
WritePhMnemonic(&buf, phoneme_tab[phonSYLLABIC], NULL);
buf = WritePhMnemonic(buf, phoneme_tab[phonSYLLABIC], NULL, use_ipa);
}
if(plist->tone_ph > 0)
{
WritePhMnemonic(&buf, phoneme_tab[plist->tone_ph], NULL);
buf = WritePhMnemonic(buf, phoneme_tab[plist->tone_ph], NULL, use_ipa);
}
}
+8 -2
View File
@@ -134,7 +134,13 @@ int TestSynthCallback(short *wav, int numsamples, espeak_EVENT *events)
fprintf(f_events,"'%s'\n",events->id.name);
else
if(type==espeakEVENT_PHONEME)
fprintf(f_events,"[%s]\n",WordToString(events->id.number));
{
char buf[10];
// fprintf(f_events,"[%s]\n",WordToString(events->id.number)); //old version, only 4 characters bytes
memcpy(buf, events->id.string, 8);
buf[8] = 0;
fprintf(f_events,"[%s]\n", buf);
}
else
fprintf(f_events,"%d\n",events->id.number);
@@ -2309,7 +2315,7 @@ if(control==2)
fprintf(f_events,"Type Audio Text Length Id\n");
fclose(f_events);
espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL,1000,NULL,1);
espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 1000, NULL, espeakINITIALIZE_PHONEME_IPA);
espeak_SetSynthCallback(TestSynthCallback);
espeak_SetUriCallback(TestUriCallback);
+1 -1
View File
@@ -282,7 +282,7 @@ static void CloseWaveFile()
void MarkerEvent(int type, unsigned int char_position, int value, unsigned char *out_ptr)
void MarkerEvent(int type, unsigned int char_position, int value, int value2, unsigned char *out_ptr)
{//======================================================================================
// Do nothing in the command-line version.
if(type == 2)
+15 -4
View File
@@ -543,12 +543,13 @@ static const char* label[] = {
#endif
void MarkerEvent(int type, unsigned int char_position, int value, unsigned char *out_ptr)
{//======================================================================================
// type: 1=word, 2=sentence, 3=named mark, 4=play audio, 5=end
void MarkerEvent(int type, unsigned int char_position, int value, int value2, unsigned char *out_ptr)
{//==================================================================================================
// type: 1=word, 2=sentence, 3=named mark, 4=play audio, 5=end, 7=phoneme
ENTER("MarkerEvent");
espeak_EVENT *ep;
double time;
PHONEME_TAB *ph;
if((event_list == NULL) || (event_list_ix >= (n_event_list-2)))
return;
@@ -574,7 +575,17 @@ void MarkerEvent(int type, unsigned int char_position, int value, unsigned char
if((type == espeakEVENT_MARK) || (type == espeakEVENT_PLAY))
ep->id.name = &namedata[value];
else
if(type == espeakEVENT_PHONEME)
{
int *p;
p = (int *)(ep->id.string);
p[0] = value;
p[1] = value2;
}
else
{
ep->id.number = value;
}
} // end of MarkerEvent
@@ -769,7 +780,7 @@ ENTER("espeak_Initialize");
option_phonemes = 0;
option_mbrola_phonemes = 0;
option_phoneme_events = (options & 1);
option_phoneme_events = (options & (espeakINITIALIZE_PHONEME_EVENTS | espeakINITIALIZE_PHONEME_IPA));
VoiceReset(0);
// SetVoiceByName("default");
+10 -2
View File
@@ -34,7 +34,7 @@
#define ESPEAK_API
#endif
#define ESPEAK_API_REVISION 6
#define ESPEAK_API_REVISION 7
/*
Revision 2
Added parameter "options" to eSpeakInitialize()
@@ -50,6 +50,11 @@ Revision 5
Revision 6
Added macros: espeakRATE_MINIMUM, espeakRATE_MAXIMUM, espeakRATE_NORMAL
Revision 7 24.Dec.2011
Changed espeak_EVENT structure to add id.string[] for phoneme mnemonics.
Added espeakINITIALIZE_PHONEME_IPA option for espeak_Initialize() to report phonemes as IPA names.
*/
/********************/
/* Initialization */
@@ -84,8 +89,9 @@ typedef struct {
int sample; // sample id (internal use)
void* user_data; // pointer supplied by the calling program
union {
int number; // used for WORD and SENTENCE events. For PHONEME events this is the phoneme mnemonic.
int number; // used for WORD and SENTENCE events.
const char *name; // used for MARK and PLAY events. UTF8 string
char string[8]; // used for phoneme names (UTF8). Terminated by a zero byte unless the name needs the full 8 bytes.
} id;
} espeak_EVENT;
/*
@@ -164,6 +170,7 @@ typedef enum {
} espeak_ERROR;
#define espeakINITIALIZE_PHONEME_EVENTS 0x0001
#define espeakINITIALIZE_PHONEME_IPA 0x0002
#define espeakINITIALIZE_DONT_EXIT 0x8000
#ifdef __cplusplus
@@ -178,6 +185,7 @@ ESPEAK_API int espeak_Initialize(espeak_AUDIO_OUTPUT output, int buflength, cons
path: The directory which contains the espeak-data directory, or NULL for the default location.
options: bit 0: 1=allow espeakEVENT_PHONEME events.
bit 1: 1= espeakEVENT_PHONEME events give IPA phoneme names, not eSpeak phoneme names
bit 15: 1=don't exit if espeak_data is not found (used for --help)
Returns: sample rate in Hz, or -1 (EE_INTERNAL_ERROR).
+5 -1
View File
@@ -488,7 +488,11 @@ int MbrolaTranslate(PHONEME_LIST *plist, int n_phonemes, int resume, FILE *f_mbr
len = (80 * speed.wav_factor)/256;
if(ph->code != phonEND_WORD)
DoMarker(espeakEVENT_PHONEME, (p->sourceix & 0x7ff) + clause_start_char, 0, ph->mnemonic);
{
char phoneme_name[16];
WritePhMnemonic(phoneme_name, p->ph, p, option_phoneme_events & espeakINITIALIZE_PHONEME_IPA);
DoPhonemeMarker(espeakEVENT_PHONEME, (p->sourceix & 0x7ff) + clause_start_char, 0, phoneme_name);
}
ptr += sprintf(ptr,"%s\t",WordToString(name));
+2 -2
View File
@@ -35,7 +35,7 @@
#include "translate.h"
#include "wave.h"
const char *version_string = "1.46.10 21.Dec.11";
const char *version_string = "1.46.11 24.Dec.11";
const int version_phdata = 0x014600;
int option_device_number = -1;
@@ -675,7 +675,7 @@ static bool InterpretCondition(Translator *tr, int control, PHONEME_LIST *plist,
if(control & 0x100)
{
// change phonemes pass
// "change phonemes" pass
plist->ph = phoneme_tab[plist->phcode];
}
ph = plist->ph;
+35 -7
View File
@@ -1211,10 +1211,27 @@ void DoMarker(int type, int char_posn, int length, int value)
// Type 1=word, 2=sentence, 3=named marker, 4=play audio, 5=end
if(WcmdqFree() > 5)
{
wcmdq[wcmdq_tail][0] = WCMD_MARKER;
wcmdq[wcmdq_tail][1] = type;
wcmdq[wcmdq_tail][2] = (char_posn & 0xffffff) | (length << 24);
wcmdq[wcmdq_tail][3] = value;
wcmdq[wcmdq_tail][0] = WCMD_MARKER + (type << 8);
wcmdq[wcmdq_tail][1] = (char_posn & 0xffffff) | (length << 24);
wcmdq[wcmdq_tail][2] = value;
WcmdqInc();
}
} // end of DoMarker
void DoPhonemeMarker(int type, int char_posn, int length, char *name)
{//==================================================================
// This could be used to return an index to the word currently being spoken
// Type 7=phoneme
int *p;
if(WcmdqFree() > 5)
{
wcmdq[wcmdq_tail][0] = WCMD_MARKER + (type << 8);
wcmdq[wcmdq_tail][1] = (char_posn & 0xffffff) | (length << 24);
p = (int *)name;
wcmdq[wcmdq_tail][2] = p[0]; // up to 8 bytes of UTF8 characters
wcmdq[wcmdq_tail][3] = p[1];
WcmdqInc();
}
} // end of DoMarker
@@ -1319,6 +1336,8 @@ int Generate(PHONEME_LIST *phoneme_list, int *n_ph, int resume)
unsigned char *pitch_env=NULL;
unsigned char *amp_env;
PHONEME_TAB *ph;
int use_ipa=0;
char phoneme_name[16];
static int sourceix=0;
PHONEME_DATA phdata;
@@ -1330,6 +1349,9 @@ int Generate(PHONEME_LIST *phoneme_list, int *n_ph, int resume)
if(option_quiet)
return(0);
if(option_phoneme_events & espeakINITIALIZE_PHONEME_IPA)
use_ipa = 1;
if(mbrola_name[0] != 0)
return(MbrolaGenerate(phoneme_list,n_ph,resume));
@@ -1405,7 +1427,8 @@ int Generate(PHONEME_LIST *phoneme_list, int *n_ph, int resume)
if(option_phoneme_events && (p->type != phVOWEL) && (p->ph->code != phonEND_WORD))
{
// Note, for vowels, do the phoneme event after the vowel-start
DoMarker(espeakEVENT_PHONEME, sourceix, 0, p->ph->mnemonic);
WritePhMnemonic(phoneme_name, p->ph, p, use_ipa);
DoPhonemeMarker(espeakEVENT_PHONEME, sourceix, 0, phoneme_name);
}
switch(p->type)
@@ -1712,7 +1735,8 @@ int Generate(PHONEME_LIST *phoneme_list, int *n_ph, int resume)
if(option_phoneme_events)
{
DoMarker(espeakEVENT_PHONEME, sourceix, 0, p->ph->mnemonic);
WritePhMnemonic(phoneme_name, p->ph, p, use_ipa);
DoPhonemeMarker(espeakEVENT_PHONEME, sourceix, 0, phoneme_name);
}
fmtp.fmt_addr = phdata.sound_addr[pd_FMT];
@@ -1896,7 +1920,11 @@ int SpeakNextClause(FILE *f_in, const void *text_in, int control)
if((option_phonemes > 0) || (phoneme_callback != NULL))
{
GetTranslatedPhonemeString(translator->phon_out,sizeof(translator->phon_out));
int use_ipa = 0;
if(option_phonemes == 3)
use_ipa = 1;
GetTranslatedPhonemeString(translator->phon_out, sizeof(translator->phon_out), use_ipa);
if(option_phonemes > 0)
{
fprintf(f_trans,"%s\n",translator->phon_out);
+2 -2
View File
@@ -475,7 +475,7 @@ int WavegenInitSound();
void WavegenInit(int rate, int wavemult_fact);
float polint(float xa[],float ya[],int n,float x);
int WavegenFill(int fill_zeros);
void MarkerEvent(int type, unsigned int char_position, int value, unsigned char *out_ptr);
void MarkerEvent(int type, unsigned int char_position, int value, int value2, unsigned char *out_ptr);
extern unsigned char *wavefile_data;
@@ -559,7 +559,7 @@ int MbrolaFill(int length, int resume, int amplitude);
void MbrolaReset(void);
void DoEmbedded(int *embix, int sourceix);
void DoMarker(int type, int char_posn, int length, int value);
//int DoSample(PHONEME_TAB *ph1, PHONEME_TAB *ph2, int which, int length_mod, int amp);
void DoPhonemeMarker(int type, int char_posn, int length, char *name);
int DoSample3(PHONEME_DATA *phdata, int length_mod, int amp);
int DoSpect2(PHONEME_TAB *this_ph, int which, FMT_PARAMS *fmt_params, PHONEME_LIST *plist, int modulation);
int PauseLength(int pause, int control);
+2 -1
View File
@@ -639,7 +639,7 @@ int IsDigit(unsigned int c);
int IsAlpha(unsigned int c);
int isspace2(unsigned int c);
int towlower2(unsigned int c);
void GetTranslatedPhonemeString(char *phon_out, int n_phon_out);
void GetTranslatedPhonemeString(char *phon_out, int n_phon_out, int use_ipa);
Translator *SelectTranslator(const char *name);
int SetTranslator2(const char *name);
@@ -679,6 +679,7 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix
void SetVoiceStack(espeak_VOICE *v, const char *variant_name);
void InterpretPhoneme(Translator *tr, int control, PHONEME_LIST *plist, PHONEME_DATA *phdata);
void InterpretPhoneme2(int phcode, PHONEME_DATA *phdata);
char *WritePhMnemonic(char *phon_out, PHONEME_TAB *ph, PHONEME_LIST *plist, int use_ipa);
extern FILE *f_trans; // for logging
extern FILE *f_logespeak;
+4 -2
View File
@@ -408,6 +408,7 @@ void TranslDlg::OnCommand(wxCommandEvent& event)
char phon_out[N_PH_LIST*2];
int clause_tone;
int clause_count;
int use_ipa = 0;
FILE *f;
int fd_temp;
char fname_temp[100];
@@ -459,6 +460,7 @@ void TranslDlg::OnCommand(wxCommandEvent& event)
t_phonetic->SetDefaultStyle(style_phonetic_large);
translate_text = 3;
use_ipa = 1;
break;
case T_PROCESS:
@@ -468,7 +470,7 @@ void TranslDlg::OnCommand(wxCommandEvent& event)
myframe->OnProsody(event);
}
prosodycanvas->LayoutData(ph_list,n_ph_list);
option_phoneme_events = 1;
option_phoneme_events = espeakINITIALIZE_PHONEME_EVENTS;
option_log_frames = 1;
MakeWave2(ph_list,n_ph_list);
option_log_frames = 0;
@@ -495,7 +497,7 @@ void TranslDlg::OnCommand(wxCommandEvent& event)
CalcPitches(translator,clause_tone);
CalcLengths(translator);
GetTranslatedPhonemeString(translator->phon_out,sizeof(translator->phon_out));
GetTranslatedPhonemeString(translator->phon_out, sizeof(translator->phon_out), use_ipa);
if(clause_count++ > 0)
strcat(phon_out," ||");
strcat(phon_out,translator->phon_out);
+20 -9
View File
@@ -261,8 +261,11 @@ unsigned char pitch_adjust_tab[MAX_PITCH_VALUE+1] = {
#ifdef LOG_FRAMES
static void LogMarker(int type, int value)
{//=======================================
static void LogMarker(int type, int value, int value2)
{//===================================================
char buf[20];
int *p;
if(option_log_frames == 0)
return;
@@ -272,7 +275,13 @@ static void LogMarker(int type, int value)
if(f_log)
{
if(type == espeakEVENT_PHONEME)
fprintf(f_log,"Phoneme [%s]\n",WordToString(value));
{
p = (int *)buf;
p[0] = value;
p[1] = value2;
buf[8] = 0;
fprintf(f_log,"Phoneme [%s]\n", buf);
}
else
fprintf(f_log,"\n");
fclose(f_log);
@@ -1630,7 +1639,7 @@ void WavegenSetVoice(voice_t *v)
}
WavegenSetEcho();
SetPitchFormants();
MarkerEvent(espeakEVENT_SAMPLERATE,0,wvoice->samplerate,out_ptr);
MarkerEvent(espeakEVENT_SAMPLERATE, 0, wvoice->samplerate, 0, out_ptr);
// WVoiceChanged(wvoice);
}
@@ -1862,6 +1871,7 @@ int WavegenFill2(int fill_zeros)
long *q;
int length;
int result;
int marker_type;
static int resume=0;
static int echo_complete=0;
@@ -1889,7 +1899,7 @@ int WavegenFill2(int fill_zeros)
q = wcmdq[wcmdq_head];
length = q[1];
switch(q[0])
switch(q[0] & 0xff)
{
case WCMD_PITCH:
SetPitch(length,(unsigned char *)q[2],q[3] >> 16,q[3] & 0xffff);
@@ -1946,13 +1956,14 @@ int WavegenFill2(int fill_zeros)
#endif
case WCMD_MARKER:
MarkerEvent(q[1],q[2],q[3],out_ptr);
marker_type = q[0] >> 8;
MarkerEvent(marker_type, q[1],q[2],q[3],out_ptr);
#ifdef LOG_FRAMES
LogMarker(q[1],q[3]);
LogMarker(marker_type, q[2], q[3]);
#endif
if(q[1] == 1)
if(marker_type == 1) // word marker
{
current_source_index = q[2] & 0xffffff;
current_source_index = q[1] & 0xffffff;
}
break;