Created
December 1, 2024 08:24
-
-
Save willwade/1da1d647f04052cfaadb4fc28c6d2614 to your computer and use it in GitHub Desktop.
Seek out the clsid for sapi4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import winreg | |
def find_sapi4_clsid() -> str: | |
""" | |
Search the Windows registry for the SAPI 4 CLSID. | |
Returns: | |
str: The CLSID for SAPI 4 if found, else raises an exception. | |
""" | |
sapi4_key_path = r"SOFTWARE\WOW6432Node\Microsoft\Speech\Voices\Tokens" | |
try: | |
# Open the 32-bit registry hive | |
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, sapi4_key_path) as key: | |
# Iterate through subkeys to find potential SAPI 4 tokens | |
for i in range(winreg.QueryInfoKey(key)[0]): | |
token_name = winreg.EnumKey(key, i) | |
token_path = f"{sapi4_key_path}\\{token_name}" | |
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, token_path) as token_key: | |
# Check for a CLSID entry under the token | |
try: | |
clsid = winreg.QueryValueEx(token_key, "CLSID")[0] | |
if clsid: # Found a valid CLSID | |
return clsid | |
except FileNotFoundError: | |
continue | |
except FileNotFoundError: | |
raise Exception("SAPI 4 not found in registry.") | |
raise Exception("SAPI 4 CLSID not found in registry.") | |
# Example usage | |
try: | |
sapi4_clsid = find_sapi4_clsid() | |
print(f"Found SAPI 4 CLSID: {sapi4_clsid}") | |
except Exception as e: | |
print(f"Error: {e}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment