how to invoke powershell from wsl to use speech synthesizer

Viewed 133

I need to use wsl to invoke powershell to use "text to speech" in my bash script. I tried this and it run only in PS but not in wsl :

$sp = New-Object -ComObject SAPI.SpVoice
$sp.Speak("Hello...")

I tried also this in wsl but it doesn't work either:

powershell.exe $sp = New-Object -ComObject SAPI.SpVoice
powershell.exe $sp.Speak("Hello...")
1 Answers

As $sp is considered as variable expansion, you need to use single quote :

powershell.exe '$sp = New-Object -ComObject SAPI.SpVoice; $sp.Speak("Hello...")'
Related