Browse Source

bugfix: allow both SSSML <audio> and soundicon punctuation

All sound file information goes to soundicon_tab. The contents of the files are not
loaded to memory before they are needed for synthesis.

This removes N_SOUNDICON_SLOTS that divided soundicon_tab into two
parts for unknown reasons.

TODO: LoadConfig() is currently undocumented. The logic should be
moved to LoadVoice() and documented.
master
Juho Hiltunen 4 years ago
parent
commit
0ed9c91520
3 changed files with 28 additions and 29 deletions
  1. 23
    20
      src/libespeak-ng/soundicon.c
  2. 2
    3
      src/libespeak-ng/soundicon.h
  3. 3
    6
      src/libespeak-ng/synthdata.c

+ 23
- 20
src/libespeak-ng/soundicon.c View File

@@ -41,7 +41,7 @@
#include "speech.h" // for path_home, GetFileLength, PATHSEP
#include "synthesize.h" // for samplerate

int n_soundicon_tab = N_SOUNDICON_SLOTS;
int n_soundicon_tab = 0;
SOUND_ICON soundicon_tab[N_SOUNDICON_TAB];


@@ -141,14 +141,15 @@ static espeak_ng_STATUS LoadSoundFile(const char *fname, int index, espeak_ng_ER

int LookupSoundicon(int c)
{
// Find the sound icon number for a punctuation character
// Find the sound icon number for a punctuation character and load the audio file if it's not yet loaded
int ix;

for (ix = N_SOUNDICON_SLOTS; ix < n_soundicon_tab; ix++) {
for (ix = 0; ix < n_soundicon_tab; ix++) {
if (soundicon_tab[ix].name == c) {
if (soundicon_tab[ix].length == 0) {
if (LoadSoundFile(NULL, ix, NULL) != ENS_OK)
if (soundicon_tab[ix].length == 0) { // not yet loaded, load now
if (LoadSoundFile(NULL, ix, NULL) != ENS_OK) {
return -1; // sound file is not available
}
}
return ix;
}
@@ -158,26 +159,28 @@ int LookupSoundicon(int c)

int LoadSoundFile2(const char *fname)
{
// Load a sound file into one of the reserved slots in the sound icon table
// (if it'snot already loaded)
// Load a sound file into the sound icon table and memory
// (if it's not already loaded)
// returns -1 on error or the index of loaded file on success

int ix;
static int slot = -1;

for (ix = 0; ix < n_soundicon_tab; ix++) {
if (((soundicon_tab[ix].filename != NULL) && strcmp(fname, soundicon_tab[ix].filename) == 0))
return ix; // already loaded
if (((soundicon_tab[ix].filename != NULL) && strcmp(fname, soundicon_tab[ix].filename) == 0)) {
// the file information is found. If length = 0 it needs to be loaded to memory
if (soundicon_tab[ix].length == 0) {
if (LoadSoundFile(NULL, ix, NULL) != ENS_OK)
return -1; // sound file is not available
}
return ix; // sound file already loaded to memory
}
}

// load the file into the next slot
slot++;
if (slot >= N_SOUNDICON_SLOTS)
slot = 0;

if (LoadSoundFile(fname, slot, NULL) != ENS_OK)
// load the file into the current slot and increase index
if (LoadSoundFile(fname, n_soundicon_tab, NULL) != ENS_OK)
return -1;

soundicon_tab[slot].filename = (char *)realloc(soundicon_tab[ix].filename, strlen(fname)+1);
strcpy(soundicon_tab[slot].filename, fname);
return slot;
soundicon_tab[n_soundicon_tab].filename = (char *)realloc(soundicon_tab[n_soundicon_tab].filename, strlen(fname)+1);
strcpy(soundicon_tab[n_soundicon_tab].filename, fname);
n_soundicon_tab++;
return n_soundicon_tab - 1;
}

+ 2
- 3
src/libespeak-ng/soundicon.h View File

@@ -30,14 +30,13 @@ int LookupSoundicon(int c);
int LoadSoundFile2(const char *fname);

typedef struct {
int name;
int name; // used for detecting punctuation
int length;
char *data;
char *filename;
} SOUND_ICON;

#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
#define N_SOUNDICON_TAB 80 // total entries for dynamic loading of audio files

extern int n_soundicon_tab;
extern SOUND_ICON soundicon_tab[N_SOUNDICON_TAB];

+ 3
- 6
src/libespeak-ng/synthdata.c View File

@@ -36,7 +36,7 @@
#include "phoneme.h" // for PHONEME_TAB, PHONEME_TAB_LIST
#include "speech.h" // for path_home, GetFileLength, PATHSEP
#include "mbrola.h" // for mbrola_name
#include "soundicon.h" // for N_SOUNDICON_SLOTS, soundicon_tab
#include "soundicon.h" // for soundicon_tab
#include "synthesize.h" // for PHONEME_LIST, frameref_t, PHONE...
#include "translate.h" // for Translator, LANGUAGE_OPTIONS
#include "voice.h" // for ReadTonePoints, tone_points, voice
@@ -392,11 +392,6 @@ void LoadConfig(void)
char c1;
char string[200];

for (ix = 0; ix < N_SOUNDICON_SLOTS; ix++) {
soundicon_tab[ix].filename = NULL;
soundicon_tab[ix].data = NULL;
}

sprintf(buf, "%s%c%s", path_home, PATHSEP, "config");
if ((f = fopen(buf, "r")) == NULL)
return;
@@ -409,6 +404,8 @@ void LoadConfig(void)
else if (memcmp(buf, "soundicon", 9) == 0) {
ix = sscanf(&buf[10], "_%c %s", &c1, string);
if (ix == 2) {
// add sound file information to soundicon array
// the file will be loaded to memory by LoadSoundFile2()
soundicon_tab[n_soundicon_tab].name = c1;
soundicon_tab[n_soundicon_tab].filename = strdup(string);
soundicon_tab[n_soundicon_tab++].length = 0;

Loading…
Cancel
Save