How to use Windows System.Speech for TTS in PowerShell 7 (or is there an alternative)

hugmys0ul

I have the same profile.ps1 in both WindowsPowerShell and PowerShell. It includes commands that invoke Windows Text-To-Speech However, these commands fail when run in PowerShell 7.

The errors occur when I try to use the $PomrptTTS object I create with the following code:

Add-Type -AssemblyName System.speech
$PromptTTS = New-Object System.Speech.Synthesis.SpeechSynthesizer

In PowerShell 7, any attempt to access or use my $PormptTTS object, produces the following:

SetValueInvocationException: ....\profile.ps1:82
Line |
  82 |  $PromptTTS.Rate = 0 ; $PromptTTS.Speak("Time for the $((Get-Date).DayofWeek) shuffle")
     |  ~~~~~~~~~~~~~~~~~~~
     | Exception setting "Rate": "Object reference not set to an instance of an object."

MethodInvocationException: ....\profile.ps1:82
Line |
  82 |  … e = 0 ; $PromptTTS.Speak("Time for the $((Get-Date).DayofWeek) shuffle")
     |                                             ~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Speak" with "1" argument(s): "Object reference not set to an instance of an object."
mklement0

As of PowerShell 7.0 / .NET Core 3.1, System.Speech.Synthesis.SpeechSynthesizer is considered a .NET Framework-only API and therefore not supported in .NET Core.

  • A discussion about this is ongoing in this GitHub issue; since the underlying API is specific to Windows, the question is whether it's worth exposing via the cross-platform .NET Core framework.

The workaround is to use the SAPI.SpVoice COM object (which the .NET Framework API is ultimately based on, I presume):

$sp = New-Object -ComObject SAPI.SpVoice
$sp.Speak("Time for the $((Get-Date).DayOfWeek) shuffle")

A related question asks about changing the speaking voice, which, unfortunately doesn't seem to be supported in PowerShell Core as of PowerShell 7.0, due to limited COM support - see this answer.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

PowerShell 7에서 TTS 용 Windows System.Speech를 사용하는 방법 (또는 대안이 있음)

분류에서Dev

How to use System.Windows.Interactivity windows phone 8.1

분류에서Dev

How do I disable the windows 7 activation system in this situation?

분류에서Dev

유출 된 ServiceConnection android.speech.tts.TextToSpeech $ Connection

분류에서Dev

PowerShell의 System.Windows.Input.Icommand

분류에서Dev

Powershell System.Windows.Forms.TextBox

분류에서Dev

Siri Kit (Speech to text) TTS (Text to Speech) iOS 비활성화

분류에서Dev

Create a Windows 7 System Repair ISO?

분류에서Dev

Command prompt as SYSTEM user (Windows 7)

분류에서Dev

Windows 7 system resource as folder name

분류에서Dev

Windows 7 system tray date display not appearing

분류에서Dev

When trying to install windows 7 I got an error of "operating system not found" how could I fix it?

분류에서Dev

How can I boot Windows 7 that is already installed on a hard drive on a UEFI system

분류에서Dev

Removing or overriding Windows 7 system image in windows 8

분류에서Dev

How to use entire disk space in Windows 10 when installing from system image?

분류에서Dev

How do I use ALT codes on a Dell Windows 7 laptop with no numlock key or FN keypad?

분류에서Dev

How to use `dd` in order to restore the windows 7 backed up raw files into a new hard drive?

분류에서Dev

How to use makefiles on Windows

분류에서Dev

Windows 7 maximized windows not draggable: how to enable?

분류에서Dev

Windows 7 제품 키 Powershell 받기

분류에서Dev

Windows 7에 DISM powershell 모듈 설치

분류에서Dev

How use iOS 7 font?

분류에서Dev

Windows 7 Boot to VHD using a VHD clone of the system drive

분류에서Dev

Does Windows 7 Updates really improve your system performance?

분류에서Dev

Is it possible to restore an entire Windows 7 operating system without image backup?

분류에서Dev

How to detect each Windows OS is used with powershell

분류에서Dev

how to use regular expression replacement in PowerShell

분류에서Dev

How To Defrag Windows 8 System Reserved Partition

분류에서Dev

How to use EGit with SSH on Windows?

Related 관련 기사

  1. 1

    PowerShell 7에서 TTS 용 Windows System.Speech를 사용하는 방법 (또는 대안이 있음)

  2. 2

    How to use System.Windows.Interactivity windows phone 8.1

  3. 3

    How do I disable the windows 7 activation system in this situation?

  4. 4

    유출 된 ServiceConnection android.speech.tts.TextToSpeech $ Connection

  5. 5

    PowerShell의 System.Windows.Input.Icommand

  6. 6

    Powershell System.Windows.Forms.TextBox

  7. 7

    Siri Kit (Speech to text) TTS (Text to Speech) iOS 비활성화

  8. 8

    Create a Windows 7 System Repair ISO?

  9. 9

    Command prompt as SYSTEM user (Windows 7)

  10. 10

    Windows 7 system resource as folder name

  11. 11

    Windows 7 system tray date display not appearing

  12. 12

    When trying to install windows 7 I got an error of "operating system not found" how could I fix it?

  13. 13

    How can I boot Windows 7 that is already installed on a hard drive on a UEFI system

  14. 14

    Removing or overriding Windows 7 system image in windows 8

  15. 15

    How to use entire disk space in Windows 10 when installing from system image?

  16. 16

    How do I use ALT codes on a Dell Windows 7 laptop with no numlock key or FN keypad?

  17. 17

    How to use `dd` in order to restore the windows 7 backed up raw files into a new hard drive?

  18. 18

    How to use makefiles on Windows

  19. 19

    Windows 7 maximized windows not draggable: how to enable?

  20. 20

    Windows 7 제품 키 Powershell 받기

  21. 21

    Windows 7에 DISM powershell 모듈 설치

  22. 22

    How use iOS 7 font?

  23. 23

    Windows 7 Boot to VHD using a VHD clone of the system drive

  24. 24

    Does Windows 7 Updates really improve your system performance?

  25. 25

    Is it possible to restore an entire Windows 7 operating system without image backup?

  26. 26

    How to detect each Windows OS is used with powershell

  27. 27

    how to use regular expression replacement in PowerShell

  28. 28

    How To Defrag Windows 8 System Reserved Partition

  29. 29

    How to use EGit with SSH on Windows?

뜨겁다태그

보관