From be2aca6b7f72451d712d5409da15fa9a9e22e2a1 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 19 Oct 2024 13:58:55 +0200 Subject: [PATCH] Use dict lookup of driver by sys.platform --- pyttsx3/driver.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/pyttsx3/driver.py b/pyttsx3/driver.py index e6a0564..b2d5018 100644 --- a/pyttsx3/driver.py +++ b/pyttsx3/driver.py @@ -37,17 +37,12 @@ def __init__(self, engine, driverName, debug): @param debug: Debugging output enabled or not @type debug: bool ''' - if driverName is None: - # pick default driver for common platforms - if sys.platform == 'darwin': - driverName = 'nsss' - elif sys.platform == 'win32': - driverName = 'sapi5' - else: - driverName = 'espeak' + driverName = driverName or { + 'darwin': 'nsss', + 'win32': 'sapi5', + }.get(sys.platform, 'espeak') # import driver module - name = 'pyttsx3.drivers.%s' % driverName - self._module = importlib.import_module(name) + self._module = importlib.import_module(f'pyttsx3.drivers.{driverName}') # build driver instance self._driver = self._module.buildDriver(weakref.proxy(self)) # initialize refs