Browse Source

Make it possible to restart speech even when audio open failed once

When notably the audio card is busy, we should report the issue to the
application, but still permit the application to retry submitting text
to synth, and eventually succeed to open it.

This change simply fixes the update of the out_samplerate variable to track
whether audio is open, and if not when text is submitted by the application,
try again to open it.
master
Samuel Thibault 7 years ago
parent
commit
d844a47804
1 changed files with 14 additions and 1 deletions
  1. 14
    1
      src/libespeak-ng/speech.c

+ 14
- 1
src/libespeak-ng/speech.c View File

if (out_samplerate != 0) { if (out_samplerate != 0) {
// sound was previously open with a different sample rate // sound was previously open with a different sample rate
audio_object_close(my_audio); audio_object_close(my_audio);
out_samplerate = 0;
#ifdef HAVE_SLEEP #ifdef HAVE_SLEEP
sleep(1); sleep(1);
#endif #endif
} }
#endif #endif
out_samplerate = voice_samplerate;
#ifdef HAVE_PCAUDIOLIB_AUDIO_H #ifdef HAVE_PCAUDIOLIB_AUDIO_H
int error = audio_object_open(my_audio, AUDIO_OBJECT_FORMAT_S16LE, voice_samplerate, 1); int error = audio_object_open(my_audio, AUDIO_OBJECT_FORMAT_S16LE, voice_samplerate, 1);
if (error != 0) { if (error != 0) {
return -1; return -1;
} }
#endif #endif
out_samplerate = voice_samplerate;
#ifdef USE_ASYNC #ifdef USE_ASYNC
if ((my_mode & ENOUTPUT_MODE_SYNCHRONOUS) == 0) if ((my_mode & ENOUTPUT_MODE_SYNCHRONOUS) == 0)
event_init(); event_init();
} }
} }


#ifdef HAVE_PCAUDIOLIB_AUDIO_H
if (out_samplerate == 0) {
int error = audio_object_open(my_audio, AUDIO_OBJECT_FORMAT_S16LE, voice_samplerate, 1);
if (error != 0) {
fprintf(stderr, "error: %s\n", audio_object_strerror(my_audio, error));
err = ENS_AUDIO_ERROR;
return -1;
}
out_samplerate = voice_samplerate;
}
#endif

#ifdef HAVE_PCAUDIOLIB_AUDIO_H #ifdef HAVE_PCAUDIOLIB_AUDIO_H
if (outbuf && length && a_wave_can_be_played) { if (outbuf && length && a_wave_can_be_played) {
int error = audio_object_write(my_audio, (char *)outbuf, 2*length); int error = audio_object_write(my_audio, (char *)outbuf, 2*length);

Loading…
Cancel
Save