Debian Codegraph @

debian/patches/fix-cancel

raw
1 https://github.com/espeak-ng/espeak-ng/issues/172
2
3 Upstream pcaudiolib made audio_object_flush actually do the
4 close/reopen, but this is not released yet (will be in 1.1). This
5 however poses threading issues with ALSA: audio_object_flush is
6 currently called in the application thread while it must be done in
7 the say_thread for proper safety.
8
9 espeak-ng 1.49.2 added a cancel_audio() function which calls
10 audio_object_flush and is called from close_stream(). That is however
11 not enough for the stream to get interrupted on cancel (and we don't
12 want to use upstream's current fix mentioned above since it poses
13 threading issues).
14
15 ---
16 src/libespeak-ng/fifo.c | 4 ++++
17 src/libespeak-ng/speech.c | 23 +++++++++++++++++++++++
18 src/libespeak-ng/speech.h | 3 +++
19 3 files changed, 30 insertions(+)
20
21 --- a/src/libespeak-ng/fifo.c
22 +++ b/src/libespeak-ng/fifo.c
23 @@ -358,6 +358,10 @@ static void *say_thread(void *p)
24 }
25
26 if (my_stop_is_required || my_terminate_is_required) {
27 + // restart the audio early, to be more responsive when using eSpeak NG
28 + // for audio.
29 + close_audio();
30 + open_audio();
31 // no mutex required since the stop command is synchronous
32 // and waiting for my_cond_stop_is_acknowledged
33 init(1);
34 --- a/src/libespeak-ng/speech.c
35 +++ b/src/libespeak-ng/speech.c
36 @@ -97,6 +97,28 @@ void cancel_audio(void)
37 #endif
38 }
39
40 +void close_audio(void)
41 +{
42 +#ifdef HAVE_PCAUDIOLIB_AUDIO_H
43 + if ((my_mode & ENOUTPUT_MODE_SPEAK_AUDIO) == ENOUTPUT_MODE_SPEAK_AUDIO) {
44 + audio_object_close(my_audio);
45 + }
46 +#endif
47 +}
48 +
49 +void open_audio(void)
50 +{
51 +#ifdef HAVE_PCAUDIOLIB_AUDIO_H
52 + if ((my_mode & ENOUTPUT_MODE_SPEAK_AUDIO) == ENOUTPUT_MODE_SPEAK_AUDIO) {
53 + int error = audio_object_open(my_audio, AUDIO_OBJECT_FORMAT_S16LE, voice_samplerate, 1);
54 + if (error != 0) {
55 + fprintf(stderr, "error: %s\n", audio_object_strerror(my_audio, error));
56 + err = ENS_AUDIO_ERROR;
57 + }
58 + }
59 +#endif
60 +}
61 +
62 static int dispatch_audio(short *outbuf, int length, espeak_EVENT *event)
63 {
64 int a_wave_can_be_played = 1;
65 @@ -571,6 +593,7 @@ espeak_ng_STATUS sync_espeak_Synth(unsig
66 espeak_ng_STATUS aStatus = Synthesize(unique_identifier, text, flags);
67 #if USE_LIBPCAUDIO
68 if ((my_mode & ENOUTPUT_MODE_SPEAK_AUDIO) == ENOUTPUT_MODE_SPEAK_AUDIO) {
69 + /* FIXME: This drain poses cancelling problems for end of speechs */
70 int error = (aStatus == ENS_SPEECH_STOPPED)
71 ? audio_object_flush(my_audio)
72 : audio_object_drain(my_audio);
73 --- a/src/libespeak-ng/speech.h
74 +++ b/src/libespeak-ng/speech.h
75 @@ -80,6 +80,9 @@ extern "C"
76
77 void cancel_audio(void);
78
79 +void close_audio(void);
80 +void open_audio(void);
81 +
82 extern char path_home[N_PATH_HOME]; // this is the espeak-ng-data directory
83
84 #ifdef __cplusplus