需要 Windows 语音识别脚本的帮助来复合字符串

发布于 2024-08-06 04:12:41 字数 2680 浏览 8 评论 0原文

下面的 Windows 语音识别命令强制语音识别引擎使用文字文本(“所有 76 个人支付了 5 美元”)而不是默认值(“所有 76 个人支付了 5 美元”)。

我正在尝试调整此命令删除单词之间的空格,以便我可以通过说以下内容来使用语音进行编程:

"Security Manager"
-> "Security Manager"
"Compound That"
-> "SecurityManager"

我认为这可以工作的方式是使用正则表达式删除所选文本之间的空格所以,在下面的代码中:

  <command priority="5">
    <listenFor>literal that</listenFor>
    <emulateRecognition>select that</emulateRecognition>
    <sendKeys>{250 WAIT}{{CTRL}}c{250 WAIT}</sendKeys>
      <!-- Works by first inserting the word " literal " before each word
           example "all 76 people paid $5"
           is emulated as "literal all literal 76 literal people literal paid literal $5"
           which produces the result "all seventy six people paid five dollars"

           EmulateRecognition can fail if the text contains improper formatting or nonsense words
           (which can easily happen if only part of a word in the document is included in the text selection).
           When the failure can be handled by "On Error Resume Next", such as EmulateRecognition("literal s")
           or EmulateRecognition("multiple  spaces"), we restore the original text and show feedback message.
           Unfortunately, some failures, such as EmulateRecognition("nonsens"), cause macros to immediately
           halt. This is why "replace that with " is used. Either it succeeds, or it fails non-destructively
           (before any text is deleted). Unfortunately, this can be confusing for the user because the macro
           can fail without doing anything visible to the user (no changes to the text, and no SetTextFeedback.)
      -->
    <script language="VBScript">
      <![CDATA[
      that = Application.clipboardData.GetData("text")
      Set regEx = New RegExp
      regEx.Pattern = "[^\s\w,;:]"
      If regEx.Test(that) Then
        Application.SetTextFeedback("Try again without any punctuation selected")
      Else
        regEx.Pattern = "(\s) *(\S)"
        regEx.Global = True
        that = regEx.Replace(" " & that, "$1literal $2")
        On Error Resume Next
        Application.EmulateRecognition("replace that with" & that)
        If 0 <> Err.Number Then
          Application.SetTextFeedback("Try again with only the digits selected")
        End If
      End If
    ]]>
    </script>
  </command>

而不是写这个 。 :

        regEx.Pattern = "(\s) *(\S)"
        regEx.Global = True
        that = regEx.Replace(" " & that, "$1literal $2")

我认为需要使用其他正则表达式模式来提取单词之间的空格并将单词推到新的输出中,

如果有人有建议,我将不胜感激。

The command below for Windows Speech Recognition forces the speech recognition engine to use literal text (""all seventy six people paid five dollars") instead of the default ("all 76 people paid $5").

I'm trying to adapt this command to remove the spaces between words so that I could program using speech by saying things like:

"Security Manager"
-> "Security Manager"
"Compound That"
-> "SecurityManager"

The way I think this could work is by using a regex to remove the spaces between the selected text. So, in the following code:

  <command priority="5">
    <listenFor>literal that</listenFor>
    <emulateRecognition>select that</emulateRecognition>
    <sendKeys>{250 WAIT}{{CTRL}}c{250 WAIT}</sendKeys>
      <!-- Works by first inserting the word " literal " before each word
           example "all 76 people paid $5"
           is emulated as "literal all literal 76 literal people literal paid literal $5"
           which produces the result "all seventy six people paid five dollars"

           EmulateRecognition can fail if the text contains improper formatting or nonsense words
           (which can easily happen if only part of a word in the document is included in the text selection).
           When the failure can be handled by "On Error Resume Next", such as EmulateRecognition("literal s")
           or EmulateRecognition("multiple  spaces"), we restore the original text and show feedback message.
           Unfortunately, some failures, such as EmulateRecognition("nonsens"), cause macros to immediately
           halt. This is why "replace that with " is used. Either it succeeds, or it fails non-destructively
           (before any text is deleted). Unfortunately, this can be confusing for the user because the macro
           can fail without doing anything visible to the user (no changes to the text, and no SetTextFeedback.)
      -->
    <script language="VBScript">
      <![CDATA[
      that = Application.clipboardData.GetData("text")
      Set regEx = New RegExp
      regEx.Pattern = "[^\s\w,;:]"
      If regEx.Test(that) Then
        Application.SetTextFeedback("Try again without any punctuation selected")
      Else
        regEx.Pattern = "(\s) *(\S)"
        regEx.Global = True
        that = regEx.Replace(" " & that, "$1literal $2")
        On Error Resume Next
        Application.EmulateRecognition("replace that with" & that)
        If 0 <> Err.Number Then
          Application.SetTextFeedback("Try again with only the digits selected")
        End If
      End If
    ]]>
    </script>
  </command>

instead of writing this:

        regEx.Pattern = "(\s) *(\S)"
        regEx.Global = True
        that = regEx.Replace(" " & that, "$1literal $2")

I think it would need to use some other regex pattern that extracts whitespace between words and pushes the words together in the new output.

I'm not sure how to do that. Would appreciate if anyone has a suggestion.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

望喜 2024-08-13 04:12:41

由于您已经在使用“literal”命令,因此您还可以使用“nospace”命令来抑制单词之间的空格。请参阅我的博客上的示例

Since you're already using the 'literal' command, you could also use the 'nospace' command to suppress spaces between words. See the examples on my blog.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文