Package: espeak-ng / 1.49.2+dfsg-8

audio_reopen Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
https://github.com/espeak-ng/espeak-ng/pull/479
---
 src/libespeak-ng/speech.c |   17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

--- a/src/libespeak-ng/speech.c
+++ b/src/libespeak-ng/speech.c
@@ -97,6 +97,7 @@ void close_audio(void)
 #ifdef HAVE_PCAUDIOLIB_AUDIO_H
 	if ((my_mode & ENOUTPUT_MODE_SPEAK_AUDIO) == ENOUTPUT_MODE_SPEAK_AUDIO) {
 		audio_object_close(my_audio);
+		out_samplerate = 0;
 	}
 #endif
 }
@@ -109,11 +110,23 @@ void open_audio(void)
 		if (error != 0) {
 			fprintf(stderr, "error: %s\n", audio_object_strerror(my_audio, error));
 			err = ENS_AUDIO_ERROR;
+		} else {
+			out_samplerate = voice_samplerate;
 		}
 	}
 #endif
 }
 
+void check_audio(void)
+{
+#ifdef HAVE_PCAUDIOLIB_AUDIO_H
+	if (out_samplerate == 0) {
+		/* Try to reopen audio */
+		open_audio();
+	}
+#endif
+}
+
 static int dispatch_audio(short *outbuf, int length, espeak_EVENT *event)
 {
 	int a_wave_can_be_played = 1;
@@ -139,12 +152,12 @@ static int dispatch_audio(short *outbuf,
 				if (out_samplerate != 0) {
 					// sound was previously open with a different sample rate
 					audio_object_close(my_audio);
+					out_samplerate = 0;
 #ifdef HAVE_SLEEP
 					sleep(1);
 #endif
 				}
 #endif
-				out_samplerate = voice_samplerate;
 #ifdef HAVE_PCAUDIOLIB_AUDIO_H
 				int error = audio_object_open(my_audio, AUDIO_OBJECT_FORMAT_S16LE, voice_samplerate, 1);
 				if (error != 0) {
@@ -153,12 +166,14 @@ static int dispatch_audio(short *outbuf,
 					return -1;
 				}
 #endif
+				out_samplerate = voice_samplerate;
 #ifdef USE_ASYNC
 				if ((my_mode & ENOUTPUT_MODE_SYNCHRONOUS) == 0)
 					event_init();
 #endif
 			}
 		}
+		check_audio();
 
 #ifdef HAVE_PCAUDIOLIB_AUDIO_H
 		if (outbuf && length && a_wave_can_be_played) {