Add support for indexing

This commit is contained in:
Samuel Thibault 2020-11-09 20:37:46 +01:00 committed by Alexander Epaneshnikov
commit ee05f278f2
3 changed files with 28 additions and 9 deletions

View file

@ -47,7 +47,7 @@ const int volumeMultiplier = 22;
volatile int stop_requested = 0; volatile int stop_requested = 0;
int paused_espeak = 1; int paused_espeak = 1;
static int acsint_callback(short *wav, int numsamples, espeak_EVENT * events) static int callback(short *wav, int numsamples, espeak_EVENT * events)
{ {
int i; int i;
for (i = 0; events[i].type != espeakEVENT_LIST_TERMINATED; i++) { for (i = 0; events[i].type != espeakEVENT_LIST_TERMINATED; i++) {
@ -55,8 +55,7 @@ static int acsint_callback(short *wav, int numsamples, espeak_EVENT * events)
int mark = atoi(events[i].id.name); int mark = atoi(events[i].id.name);
if ((mark < 0) || (mark > 255)) if ((mark < 0) || (mark > 255))
continue; continue;
putchar(mark); softsynth_reportindex(mark);
fflush(stdout);
} }
} }
return 0; return 0;
@ -327,9 +326,7 @@ static void reinitialize_espeak(struct synth_t *s)
return; return;
} }
/* We need a callback in acsint mode, but not in speakup mode. */ espeak_SetSynthCallback(callback);
if (espeakup_mode == ESPEAKUP_MODE_ACSINT)
espeak_SetSynthCallback(acsint_callback);
/* Set parameters again */ /* Set parameters again */
espeak_SetVoiceByName(s->voice); espeak_SetVoiceByName(s->voice);
@ -345,6 +342,7 @@ static void reinitialize_espeak(struct synth_t *s)
static void queue_process_entry(struct synth_t *s) static void queue_process_entry(struct synth_t *s)
{ {
espeak_ERROR error; espeak_ERROR error;
char markbuff[50];
static struct espeak_entry_t *current = NULL; static struct espeak_entry_t *current = NULL;
if (current != queue_peek(synth_queue)) { if (current != queue_peek(synth_queue)) {
@ -362,6 +360,11 @@ static void queue_process_entry(struct synth_t *s)
case CMD_SET_FREQUENCY: case CMD_SET_FREQUENCY:
error = set_frequency(s, current->value, current->adjust); error = set_frequency(s, current->value, current->adjust);
break; break;
case CMD_SET_MARK:
snprintf(markbuff, sizeof(markbuff), "<mark name=\"%d\"/>", current->value);
error = espeak_Synth(markbuff, strlen(markbuff)+1, 0, POS_CHARACTER,
0, espeakSSML, NULL, NULL);
break;
case CMD_SET_PITCH: case CMD_SET_PITCH:
error = set_pitch(s, current->value, current->adjust); error = set_pitch(s, current->value, current->adjust);
break; break;
@ -413,9 +416,7 @@ int initialize_espeak(struct synth_t *s)
return -1; return -1;
} }
/* We need a callback in acsint mode, but not in speakup mode. */ espeak_SetSynthCallback(callback);
if (espeakup_mode == ESPEAKUP_MODE_ACSINT)
espeak_SetSynthCallback(acsint_callback);
/* Setup initial voice parameters */ /* Setup initial voice parameters */
if (defaultVoice && defaultVoice[0]) { if (defaultVoice && defaultVoice[0]) {

View file

@ -38,6 +38,7 @@ enum espeakup_mode_t {
enum command_t { enum command_t {
CMD_SET_FREQUENCY, CMD_SET_FREQUENCY,
CMD_SET_MARK,
CMD_SET_PITCH, CMD_SET_PITCH,
CMD_SET_RANGE, CMD_SET_RANGE,
CMD_SET_PUNCTUATION, CMD_SET_PUNCTUATION,
@ -87,6 +88,7 @@ extern void *espeak_thread(void *arg);
extern int open_softsynth(void); extern int open_softsynth(void);
extern void close_softsynth(void); extern void close_softsynth(void);
extern void *softsynth_thread(void *arg); extern void *softsynth_thread(void *arg);
extern void softsynth_reportindex(int index);
extern volatile int should_run; extern volatile int should_run;
extern volatile int stop_requested; extern volatile int stop_requested;
extern int paused_espeak; extern int paused_espeak;

View file

@ -124,6 +124,9 @@ static int process_command(struct synth_t *s, char *buf, int start)
case 'f': case 'f':
cmd = CMD_SET_FREQUENCY; cmd = CMD_SET_FREQUENCY;
break; break;
case 'i':
cmd = CMD_SET_MARK;
break;
case 'p': case 'p':
cmd = CMD_SET_PITCH; cmd = CMD_SET_PITCH;
break; break;
@ -328,3 +331,16 @@ void *softsynth_thread(void *arg)
pthread_mutex_unlock(&queue_guard); pthread_mutex_unlock(&queue_guard);
return NULL; return NULL;
} }
void softsynth_reportindex(int index)
{
if (espeakup_mode == ESPEAKUP_MODE_ACSINT) {
putchar(index);
fflush(stdout);
} else {
char buf[16];
snprintf(buf, sizeof(buf), "%d", index);
if (write(softFD, buf, strlen(buf)) < 0)
perror("Writing index failed");
}
}