Нужна помощь со сценарием распознавания речи Windows для составления строки

Приведенная ниже команда для распознавания речи Windows заставляет механизм распознавания речи использовать буквальный текст («все семьдесят шесть человек заплатили пять долларов») вместо значения по умолчанию («все 76 человек заплатили пять долларов»).

Я пытаюсь адаптировать эту команду, чтобы удалить пробелы между словами, чтобы я мог программировать, используя речь, говоря такие вещи, как:

"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")

Я думаю, что потребуется использовать какой-то другой шаблон регулярного выражения, который извлекает пробелы между словами и объединяет слова в новом выводе.

Я не уверен, как это сделать. Был бы признателен, если у кого-то есть предложение.


person i_like_monkeys    schedule 04.10.2009    source источник
comment
Я боюсь, что вам больше повезет с этим вопросом на Stackoverflow, но не беспокойтесь, он, вероятно, скоро будет перенесен.   -  person Ivo Flipse    schedule 05.10.2009


Ответы (1)


Поскольку вы уже используете команду 'literal', вы также можете использовать команду 'nospace' для подавления пробелов между словами. См. примеры в моем блоге. .

person Eric Brown    schedule 06.10.2009