Created
November 30, 2024 19:05
-
-
Save willwade/4f3a26bd09eb29bc2a325de5ea854c99 to your computer and use it in GitHub Desktop.
Com surrogate technique
This file contains 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 comtypes.client | |
# SAPI 4 CLSID for the voice | |
SAPI4_CLSID = "{EEE78591-FE22-11D0-8BEF-0060081841DE}" | |
def list_sapi4_voices(): | |
"""List available SAPI 4 voices.""" | |
try: | |
sapi4 = comtypes.client.CreateObject(SAPI4_CLSID) | |
voices = sapi4.GetVoices() | |
voice_list = [] | |
for i in range(voices.Count): | |
voice = voices.Item(i) | |
voice_list.append({ | |
"id": voice.Id, | |
"name": voice.GetDescription(), | |
}) | |
return voice_list | |
except Exception as e: | |
print(f"Error accessing SAPI 4: {e}") | |
return [] | |
def synthesize_with_sapi4(text): | |
"""Synthesize speech using SAPI 4.""" | |
try: | |
sapi4 = comtypes.client.CreateObject(SAPI4_CLSID) | |
sapi4.Speak(text) | |
except Exception as e: | |
print(f"Error synthesizing text with SAPI 4: {e}") | |
# Test the functions | |
if __name__ == "__main__": | |
print("Listing SAPI 4 Voices:") | |
voices = list_sapi4_voices() | |
for voice in voices: | |
print(voice) | |
print("Synthesizing speech...") | |
synthesize_with_sapi4("Hello, this is a test of SAPI 4!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment