With such a simple command, Windows can "talk". You can't hear the sound in the screen capture, but I hope you try it in the Windows PowerShell at hand
When writing a script, you sometimes want to get the user's attention. For example, when doing a slightly time-consuming process, you want to notify that it is over, and so on. Or, sometimes you want to attract attention when an error is notified after a period of time after execution.
In this case, if it is a previous computer, it usually emits a ringtone and beep. When I use my computer from a terminal device, when I output Ctrl+G, the bell rings. Microprocessors began to be used, and when the prototype of the computer was completed, it had a function called BEEP. It turns the bit on and off through the program and makes sound by connecting it to the speaker. There should also be a small speaker on the motherboard for this purpose. But with the popularity of Windows, the sound function on PC has become the standard, which can simply make sound.
On the sounds tab of the sounds dialog box that opens in the sound properties of the control panel, there is a pre-owned definition of event sound by Windows. By using PlaySound API, etc., such a system-defined sound can be made. However, the sound of "something" is surprisingly difficult to distinguish. However, in order to make your own voice, it is necessary to make sound source files. That's too much trouble.
At this point, when using the speech synthesis function of Windows, the appropriate "voice message" can be sent without the sound source.
Speech API prepared in Windows
Windows has Speach API (SAPI), which can be used for speech synthesis. When it comes to speech synthesis, it's always troublesome, but try opening PowerShell on your PC (assume that Windows PowerShell,PowerShell Core is also confirmed) and run the following two lines of commands.
$x=New-Object-ComObject SAPI.SpVoice$x.Speak ("hope to be human soon")
If you set the voice, you should be able to hear the female voice. This is the speech synthesis function of Speach API. The text that allows you to speak, as long as it is ordinary text. Moreover, in the case of Japanese pronunciation, English words can also be mixed.
$x.Speak (type File Name here and press Enter key ")
With punctuation, you can take a breath there.
$x.Speak ("come on, I want to be a person, I want to be a person as soon as possible")
If we repeat the Speak method, we will keep talking about it. By default, the Speak method does not return until the sound ends because it is called synchronously. If this interferes with the execution of the script, as an asynchronous call, you can also return control before the sound ends. Add another parameter later and add 1 (SVSFlagsAsync).
$x.Speak (type File Name here and press Enter key ", 1)
Note that there is information on the following page of Microsoft about this Speak method:
SpVoice Speak method (SAPI5.4) https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ee125647 (v=vs.85) SpeechVoiceSpeakFlags (SAPI5.4) specifies the second parameter https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ee125223 (v=vs.85)
The volume and the role of the sound, change it a little bit.
First, try to change the volume.
$x.Speak ("are you going out") $x.Volume=50$ x.Speak ("are you going out") $x.Volume=100
The Volume property is specified in the range of 0 to 100. This is because the output on the Speech API side is set to 0 sound 100%, so it is relative to other sounds. The final volume is determined by the setting of Windows. If you lower this value, it can make a relatively quiet sound than other applications.
Next is the reading speed. This is set by the rate property. Values range from-10 to 10,-10 is the slowest, and the default value is 0.
$x.rate=-10$ x.Speak ("hope to be human as soon as possible", 1) $x.rate=0
Next, try to change the voice. In the Japanese version of Windows
Haruka (Japanese, female): 0Zira (English, female): 1David (English, male): 2
All three sounds can be used. When you want to speak English, choose Zira or David. If it's David,
$x.Voice=$x.GetVoices () .item (2) $x.Speak ("all works and no play makes jack a dull boy.", 1)
In that case. If "item (2)" is "item (1)", you can select Zira, and if it is "item (0)", you can select Haruka. For example,
$x.Voice=$x.GetVoices () .item (0); $x.Speak ("I heard there's a fence behind", 1); $x.Voice=$x.GetVoices () .item (2); $x.Speak ("Hey", 1)
In that case.