Skip to content

Commit

Permalink
issue #172: flush audio on cancel requests.
Browse files Browse the repository at this point in the history
This is a partial fix for an audio regression. The other part of
the fix requires a change in pcaudiolib to reopen the audio device
on flush requests for affected audio drivers/devices.
  • Loading branch information
rhdunn committed Jan 24, 2017
1 parent ae311b0 commit dee3799
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/libespeak-ng/fifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ static espeak_ng_STATUS close_stream()
status = a_status;

if (a_stop_is_required) {
// cancel the audio early, to be more responsive when using eSpeak NG
// for audio.
cancel_audio();

// acknowledge the stop request
if((a_status = pthread_mutex_lock(&my_mutex)) != ENS_OK)
return a_status;
Expand Down
9 changes: 9 additions & 0 deletions src/libespeak-ng/speech.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ int (*phoneme_callback)(const char *) = NULL;
char path_home[N_PATH_HOME]; // this is the espeak-ng-data directory
extern int saved_parameters[N_SPEECH_PARAM]; // Parameters saved on synthesis start

void cancel_audio(void)
{
#ifdef HAVE_PCAUDIOLIB_AUDIO_H
if ((my_mode & ENOUTPUT_MODE_SPEAK_AUDIO) == ENOUTPUT_MODE_SPEAK_AUDIO) {
audio_object_flush(my_audio);
}
#endif
}

static int dispatch_audio(short *outbuf, int length, espeak_EVENT *event)
{
int a_wave_can_be_played = 1;
Expand Down
2 changes: 2 additions & 0 deletions src/libespeak-ng/speech.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ typedef struct {
} MNEM_TAB;
int LookupMnem(MNEM_TAB *table, const char *string);

void cancel_audio(void);

extern char path_home[N_PATH_HOME]; // this is the espeak-ng-data directory

extern ESPEAK_NG_API void strncpy0(char *to, const char *from, int size);
Expand Down

0 comments on commit dee3799

Please sign in to comment.