- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
下面是让powershell说话的方法。
Add-Type -AssemblyName System.Speech
$synthesizer = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer
$synthesizer.Speak('Hey, I can speak!')
最佳答案
看起来你可以使用 System.Speech.Recognition
.这里甚至是用 PowerShell 编写的示例用法:
http://huddledmasses.org/control-your-pc-with-your-voice-and-powershell/
这个链接变成了 404,所以我把它从机器后面挖了出来。
用你的声音控制你的电脑……和 PowerShell
作者:Joel 'Jaykul' Bennett,2009 年 6 月 25 日
你有没有想过能够问你的电脑问题并让它大声回答你?你有没有想过你的电脑是否可以更像运行星际迷航企业版的电脑,响应语音查询和命令?您是否玩过 ZWave 或 X10 家庭自动化,并认为您的设备的语音控制将是一个明显的下一步?
好吧,好吧……我不会向你展示如何开灯或使用家庭自动化——但这是让我一直在思考语音识别的主要内容。哪个极客不想走进客厅并说“计算机:灯亮”并让它工作?
相反,作为所有这一切的第一步,让我向您展示如何使用 PowerShell 执行简单的语音命令识别脚本……它可以触发您想要编写的任何 PowerShell 脚本!下面的代码实际上是一个模块,尽管您可以将其作为脚本进行点源,并且它确实需要 PowerShell 2.0 来处理事件,尽管使用 Oisin 的 PSEventing 库重构它以在 PowerShell 1.0 上工作是微不足道的。
$null = [Reflection.Assembly]::LoadWithPartialName("System.Speech")
## Create the two main objects we need for speech recognition and synthesis
if (!$global:SpeechModuleListener) {
## For XP's sake, don't create them twice...
$global:SpeechModuleSpeaker = New-Object System.Speech.Synthesis.SpeechSynthesizer
$global:SpeechModuleListener = New-Object System.Speech.Recognition.SpeechRecognizer
}
$script:SpeechModuleMacros = @{}
## Add a way to turn it off
$script:SpeechModuleMacros.Add("Stop Listening", {$script:listen = $false; Suspend-Listening})
$script:SpeechModuleComputerName = ${env:ComputerName}
function Update-SpeechCommands {
#.Synopsis
# Recreate the speech recognition grammar
#.Description
# This parses out the speech module macros,
# and recreates the speech recognition grammar and semantic results,
# and then updates the SpeechRecognizer with the new grammar,
# and makes sure that the ObjectEvent is registered.
$choices = New-Object System.Speech.Recognition.Choices
foreach ($choice in $script:SpeechModuleMacros.GetEnumerator()) {
New-Object System.Speech.Recognition.SemanticResultValue $choice.Key, $choice.Value.ToString() |
ForEach-Object { $choices.Add($_.ToGrammarBuilder()) }
}
if ($VerbosePreference -ne "SilentlyContinue") {
$script:SpeechModuleMacros.Keys |
ForEach-Object { Write-Host"$Computer, $_" -Fore Cyan }
}
$builder = New-Object System.Speech.Recognition.GrammarBuilder"$Computer, "
$builder.Append((New-ObjectSystem.Speech.Recognition.SemanticResultKey"Commands", $choices.ToGrammarBuilder()))
$grammar = New-Object System.Speech.Recognition.Grammar $builder
$grammar.Name = "Power VoiceMacros"
## Take note of the events, but only once (make sure to remove the old one)
Unregister-Event"SpeechModuleCommandRecognized" -ErrorAction SilentlyContinue
$null = Register-ObjectEvent $grammar SpeechRecognized `
-SourceIdentifier"SpeechModuleCommandRecognized" `
-Action {iex $event.SourceEventArgs.Result.Semantics.Item("Commands").Value}
$global:SpeechModuleListener.UnloadAllGrammars()
$global:SpeechModuleListener.LoadGrammarAsync($grammar)
}
function Add-SpeechCommands {
#.Synopsis
# Add one or more commands to the speech-recognition macros, and update the recognition
#.Parameter CommandText
# The string key for the command to remove
[CmdletBinding()]
Param([hashtable]$VoiceMacros,[string]$Computer=$Script:SpeechModuleComputerName)
## Add the new macros
$script:SpeechModuleMacros += $VoiceMacros
## Update the default if they change it, so they only have to do that once.
$script:SpeechModuleComputerName = $Computer
Update-SpeechCommands
}
function Remove-SpeechCommands {
#.Synopsis
# Remove one or more command from the speech-recognition macros, and update the recognition
#.Parameter CommandText
# The string key for the command to remove
Param([string[]]$CommandText)
foreach ($command in $CommandText) {
$script:SpeechModuleMacros.Remove($Command)
}
Update-SpeechCommands
}
function Clear-SpeechCommands {
#.Synopsis
# Removes all commands from the speech-recognition macros, and update the recognition
#.Parameter CommandText
# The string key for the command to remove
$script:SpeechModuleMacros = @{}
## Default value: A way to turn it off
$script:SpeechModuleMacros.Add("Stop Listening", {Suspend-Listening})
Update-SpeechCommands
}
function Start-Listening {
#.Synopsis
# Sets the SpeechRecognizer to Enabled
$global:SpeechModuleListener.Enabled = $true
Say "Speech Macros are $($Global:SpeechModuleListener.State)"
Write-Host "Speech Macros are $($Global:SpeechModuleListener.State)"
}
function Suspend-Listening {
#.Synopsis
# Sets the SpeechRecognizer to Disabled
$global:SpeechModuleListener.Enabled = $false
Say "Speech Macros are disabled"
Write-Host "Speech Macros are disabled"
}
function Out-Speech {
#.Synopsis
# Speaks the input object
#.Description
# Uses the default SpeechSynthesizer settings to speak the string representation of the InputObject
#.Parameter InputObject
# The object to speak
# NOTE: this should almost always be a pre-formatted string,
# most objects don't render to very speakable text.
Param([Parameter(ValueFromPipeline=$true)][Alias("IO")]$InputObject)
$null = $global:SpeechModuleSpeaker.SpeakAsync(($InputObject | Out-String))
}
function Remove-SpeechXP {
#.Synopis
# Dispose of the SpeechModuleListener and SpeechModuleSpeaker
$global:SpeechModuleListener.Dispose(); $global:SpeechModuleListener = $null
$global:SpeechModuleSpeaker.Dispose(); $global:SpeechModuleSpeaker = $null
}
Set-Alias asc Add-SpeechCommands
Set-Alias rsc Remove-SpeechCommands
Set-Alias csc Clear-SpeechCommands
Set-Alias say Out-Speech
Set-Alias listen Start-Listener
Export-ModuleMember -Function * -Alias * -VariableSpeechModuleListener, SpeechModuleSpeaker
${Env:ComputerName},
如果您认为没有必要,则从 GrammarBuilder 开头的字符串开始,或者您可以将其硬编码为计算机名称以外的其他名称,例如说“Hal,拜托,我求求你......”或“计算机,请”或其他?
Add-SpeechCommands @{
"What time is it?" = { Say "It is $(Get-Date -f "h:mm tt")" }
"What day is it?" = { Say $(Get-Date -f "dddd, MMMM dd") }
"What's running?" = {
$proc = ps | sort ws -desc
Say $("$($proc.Count) processes, including $($proc[0].name), which is using " +
"$([int]($proc[0].ws/1mb)) megabytes of memory")
}
} -Computer "Laptop" -Verbose
Add-SpeechCommands @{
"Run Notepad"= { & "C:\Programs\DevTools\Notepad++\notepad++.exe"}
}
Add-SpeechCommands @{
"Check Gee Mail" = { Start-Process"https://mail.google.com" }
}
关于Powershell可以说话,但如果我说话,它可以写吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9361594/
我在 uipickerview 中有一个 uitextfield,我试图禁用任何类型的格式,我使用 UIResponderStandardEditActions 来禁用随之而来的所有操作,但我不知道如
如何让 Python 说出一些文字? 我可以将 Festival 与子进程一起使用,但我无法控制它(或者可能在交互模式下,但它不会是干净的)。 是否有 Python TTS 库?像 Festival、
在我的应用程序中,我想知道是否有任何可以阅读印地文文本的 tts 引擎。我的代码 tts.setLanguage(Locale.US); 很遗憾,Android 不支持印地语。请参阅下面支持的语言环境
@ 目录 创建页面布局 创建手势控件 创建TalkBox 创建动画 拖拽物动画
我有一个简单的 Angular 模态,是用 Angular ui.bootstrap 引发的。它打开得很好,传递值等,但不会关闭或取消。我认为这是 $scopes 的讨论问题。我知道每个模式都有自己的
scss基本上是sass功能的改进实现。我的工作区使用.scss文件。什么是正确的或通用的方式来指代scss时说?我们刚刚把这些文件称为“sass”文件。在只使用scss而不使用sass文件的环境中,
有谁知道我在哪里可以找到一个好的起点来编写一个函数,该函数接受一个字符串并将其转换为 leet speak? function stringToLeetSpeak($string) { // Lo
我目前正在实现视频通话应用程序,例如使用 Twilio Video 的 Google Hangout。我想在后台显示当时正在讲话的人的视频。 是否可以检测谁在使用 Twilio Video JS SD
所以我找到了这段代码: #!/usr/bin/python import sys #for cmd line argv import time #for delay import p
我想让我的机器人能够制作一个 webhook,由命令触发,然后 webhook 可以在一定间隔内说出消息。我想获取已创建的 webhook 的 token 和 id,然后将其放在一个持续不断的 set
我想让 Alexa 说出对意图的响应,但是通过手动调用包含 Alexa 技能代码的 Lambda 函数,而不是直接对 Echo 说出意图。 例如,您能否以某种方式(通过 AWS-SDK 或通过物联网“
我编写 Python 有一段时间了,但 DJango 和一般的 Web 编程对我来说是新的。 我在 Python View 中执行了一个很长的操作。由于我认为 local() 函数需要很长时间才能返回
我是一名优秀的程序员,十分优秀!