Skip to content

Commit

Permalink
espeak-ng: Ignore samplerate change when it is not first in the event…
Browse files Browse the repository at this point in the history
… list

See espeak-ng/espeak-ng#2028

Fixes #949
  • Loading branch information
sthibaul committed Oct 28, 2024
1 parent 96f024f commit 201979f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/modules/espeak.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ static int synth_callback(short *wav, int numsamples, espeak_EVENT * events)
static int numsamples_sent_msg = 0;
/* Number of samples already sent during this call to the callback. */
int numsamples_sent = 0;
int first = 1, nextfirst;

/* Process server events in case we were told to stop in between */
module_process(STDIN_FILENO, 0);
Expand All @@ -714,6 +715,7 @@ static int synth_callback(short *wav, int numsamples, espeak_EVENT * events)

/* Process events and audio data */
while (events->type != espeakEVENT_LIST_TERMINATED) {
nextfirst = 0;
/* Enqueue audio upto event */
switch (events->type) {
case espeakEVENT_MARK:
Expand Down Expand Up @@ -767,7 +769,15 @@ static int synth_callback(short *wav, int numsamples, espeak_EVENT * events)
break;
case espeakEVENT_SAMPLERATE:
DBG(DBG_MODNAME " Got sample rate %d", events->id.number);
espeak_sample_rate = events->id.number;
if (first) {
/* espeak-ng currently seems to produce odd
* sample rate changes, so ignore them but the
* initial event for now.
* See https://github.com/espeak-ng/espeak-ng/issues/2028 */
espeak_sample_rate = events->id.number;
/* Keep looking at sample rate changes until we get something else */
nextfirst = 1;
}
break;
default:
DBG(DBG_MODNAME " Got unsupported event %d\n", events->type);
Expand All @@ -776,6 +786,7 @@ static int synth_callback(short *wav, int numsamples, espeak_EVENT * events)
if (stop_requested)
return 1;
events++;
first = nextfirst;
}
espeak_send_audio_upto(wav, &numsamples_sent, numsamples);
numsamples_sent_msg += numsamples;
Expand Down

0 comments on commit 201979f

Please sign in to comment.