diff --git a/setup/extensions.json b/setup/extensions.json index f92643e3a9..7824c01a9b 100644 --- a/setup/extensions.json +++ b/setup/extensions.json @@ -19,7 +19,7 @@ { "name": "ffmpeg", "sources": "calibre/utils/ffmpeg.c", - "libraries": "avcodec avutil swresample", + "libraries": "swresample avcodec avutil", "inc_dirs": "!ffmpeg_inc_dirs", "lib_dirs": "!ffmpeg_lib_dirs", "needs_c": "99" diff --git a/src/calibre/gui2/tts/piper.py b/src/calibre/gui2/tts/piper.py index 268e9fdfbc..46b355d73b 100644 --- a/src/calibre/gui2/tts/piper.py +++ b/src/calibre/gui2/tts/piper.py @@ -591,6 +591,9 @@ class PiperEmbedded: self.ensure_process_started() piper_done, errors_from_piper = [], [] last_output_at = monotonic() + needs_conversion = sample_rate != self._current_audio_rate + if needs_conversion: + from calibre_extensions.ffmpeg import resample_raw_audio_16bit def callback(ok, payload): nonlocal last_output_at @@ -623,10 +626,8 @@ class PiperEmbedded: buf.append(data) else: stderr_data = detect_end_of_data(stderr_data + data, callback) - needs_conversion = sample_rate != self._current_audio_rate raw_data = b''.join(buf) if needs_conversion: - from calibre_extensions.ffmpeg import resample_raw_audio_16bit raw_data = resample_raw_audio_16bit(raw_data, self._current_audio_rate, sample_rate) yield raw_data