Make `say(blocking=True)` work for Linux (#460)

This commit is contained in:
Alexander Soare 2024-10-17 15:22:21 +01:00 committed by GitHub
parent 77478d50e5
commit cd0fc261c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 5 deletions

View File

@ -196,19 +196,19 @@ def say(text, blocking=False):
# Check if mac, linux, or windows. # Check if mac, linux, or windows.
if platform.system() == "Darwin": if platform.system() == "Darwin":
cmd = f'say "{text}"' cmd = f'say "{text}"'
if not blocking:
cmd += " &"
elif platform.system() == "Linux": elif platform.system() == "Linux":
cmd = f'spd-say "{text}"' cmd = f'spd-say "{text}"'
if blocking:
cmd += " --wait"
elif platform.system() == "Windows": elif platform.system() == "Windows":
# TODO(rcadene): Make blocking option work for Windows
cmd = ( cmd = (
'PowerShell -Command "Add-Type -AssemblyName System.Speech; ' 'PowerShell -Command "Add-Type -AssemblyName System.Speech; '
f"(New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('{text}')\"" f"(New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('{text}')\""
) )
if not blocking and platform.system() in ["Darwin", "Linux"]:
# TODO(rcadene): Make it work for Windows
# Use the ampersand to run command in the background
cmd += " &"
os.system(cmd) os.system(cmd)