From 495ef9185fb56b8eba3a47d87a0fd5165cfd6969 Mon Sep 17 00:00:00 2001 From: thevickypedia Date: Tue, 12 Sep 2023 20:37:13 -0500 Subject: [PATCH] Bug fix for macOS failing to save audio file --- pyttsx3/__init__.py | 2 +- pyttsx3/drivers/nsss.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pyttsx3/__init__.py b/pyttsx3/__init__.py index 9f562d1..3b05b89 100644 --- a/pyttsx3/__init__.py +++ b/pyttsx3/__init__.py @@ -2,7 +2,7 @@ from .engine import Engine -version = '3.3' +version = '3.4.0' _activeEngines = weakref.WeakValueDictionary() diff --git a/pyttsx3/drivers/nsss.py b/pyttsx3/drivers/nsss.py index c4d49e1..08a78f6 100644 --- a/pyttsx3/drivers/nsss.py +++ b/pyttsx3/drivers/nsss.py @@ -1,3 +1,5 @@ +import time + # noinspection PyUnresolvedReferences from AppKit import NSSpeechSynthesizer from Foundation import * @@ -141,6 +143,8 @@ def setProperty(self, name, value): def save_to_file(self, text, filename): url = Foundation.NSURL.fileURLWithPath_(filename) self._tts.startSpeakingString_toURL_(text, url) + # waits (for 1% of the length of text) the system to finish writing to the file system before continuing + time.sleep(max(1.0, len(text) * 0.01)) def speechSynthesizer_didFinishSpeaking_(self, tts, success): if not self._completed: