iNNOKENTIY21
Silver Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору
Код: function Say { [CmdletBinding()] param ( [Parameter(Mandatory, ValueFromPipeline)] [ValidateNotNullOrEmpty()] [string] $String, [string] $voice, [ValidateRange(-10, 10)] [Alias('Rate')] [int] $Speed = 1, [ValidateRange(0, 100)] [int] $Volume = 30, [ValidateRange(0, 5000)] [int] $Pause = 200 ) begin { Add-Type -AssemblyName System.Speech $SpeechSynthesizer = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer $Voices = $SpeechSynthesizer.GetInstalledVoices().VoiceInfo if ($Voice -and ($Voices.Name -contains $Voice)) { $SpeechSynthesizer.SelectVoice($Voice) } $SpeechSynthesizer.Rate = $Speed $SpeechSynthesizer.Volume = $Volume } process { foreach ($Str in $String) { $SpeechSynthesizer.Speak($Str) Start-Sleep -MilliSeconds $Pause } } end { $SpeechSynthesizer.Dispose() } } function Get-Voice { param ( [switch] $List ) Add-Type -AssemblyName System.Speech $SpeechSynthesizer = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer if ($List) { $SpeechSynthesizer.GetInstalledVoices().VoiceInfo } else { [PSCustomObject]@{ Name = $SpeechSynthesizer.Voice.Name Culture = $SpeechSynthesizer.Voice.Culture State = $SpeechSynthesizer.State Rate = $SpeechSynthesizer.Rate Volume = $SpeechSynthesizer.Volume } } } # Примеры #Get-Date -DisplayHint DateTime | Say -Voice "Microsoft Zira Desktop" # Дата на английском #Get-Date -Format "hh:mm" | Say -Speed 3 # Время на русском #Get-Date -Format "dddd, d MMMM, yyyy года, hh:mm" | Say -Speed 2 # День / Дата / Время на русском # Случайная цитата с forismatic.com <# $Page = Invoke-WebRequest "http://api.forismatic.com/api/1.0/?method=getQuote&format=xml&lang=ru" ([xml]$Page.Content).forismatic.quote.quoteText | Say ([xml]$Page.Content).forismatic.quote.quoteAuthor | Say #> #Get-Voice # Текущий голосовой движок #Get-Voice -list # Список установленных голосовых движков |
|