【问题标题】:Microsoft Speech API (SAPI) UserTraining syntaxMicrosoft Speech API (SAPI) UserTraining 语法
【发布时间】:2015-05-04 20:02:49
【问题描述】:

我有一个可以工作的自动热键脚本,它可以打开带有自定义文本输入的 Windows 语音识别训练界面。 如果您曾经接受过 Windows 语音识别的培训,您就会知道它让您说出一小行文本,然后一旦它识别出该行,就会进入一个带有另一短行文本的新屏幕。

我不知道如何将我的两句话文本“分解”成两个单独的培训屏幕,这样用户就不必一口气阅读数千行培训文本而不会出错。

如果有人知道这一点,我会永远爱你

【问题讨论】:

    标签: sapi


    【解决方案1】:

    未经测试

    hwnd:=WinExist("A")
    Title:="My App's Training"
    RC := ComObjCreate("SAPI.SpSharedRecoContext")
    MyTrainingText := new TrainingText("Some custom text", Title)
    MyTrainingText.get_MyMethod()
    MyTrainingText := new TrainingText("Some more training text", Title)
    MyTrainingText.get_MyMethod()
    
    
    Class TrainingText 
    {
        __New(x, y)
        {
            this.Text := x
            this.Title := y
        }
    
        get_MyMethod()
        {
            Title := this.Title
            trainingText := this.Text
            if RC.Recognizer.IsUISupported("UserTraining")
            {
            RC.Recognizer.DisplayUI(ComObj(3,hwnd), Title, "UserTraining", traningText)
            }
            else MsgBox, Not supported
        }
    }
    

    【讨论】:

    • 似乎不起作用,else msgbox, not supported 被触发并且没有其他任何反应(将错字 traningText 更正为 trainingText 并且仍然不起作用)
    • 我写得很快,注意未经测试的。我是在 AHK 中使用 Class 的新手,我可能搞砸了。我会在一两分钟内发布一个修订版。
    【解决方案2】:

    用户训练文本需要是double-null terminated string,也称为多字符串。每个以 null 结尾的子字符串将是一个单独的话语。我对 AutoHotKey 不够熟悉,不知道如何用该语言构建一个。

    在 C# 中,将字符串数组转换为多字符串的函数如下所示:

    static string StringArrayToMultiString(params string[] values)
    {
        if (values == null) throw new ArgumentNullException("values");
        StringBuilder multiString = new StringBuilder();
    
        foreach (string s in values)
        {
            multiString.Append(s);
            multiString.Append('\0');
        }
        return multiString.ToString();
    }
    

    【讨论】:

    • 感谢 eric 的提示,您可以用任何语言构建一个吗?我可以把它翻译成ahk
    • 在 C# 中添加了一个。希望对您有所帮助。
    猜你喜欢
    • 2014-04-09
    • 2012-04-30
    • 1970-01-01
    • 2019-08-15
    • 1970-01-01
    • 1970-01-01
    • 2014-12-19
    • 1970-01-01
    • 2011-05-18
    相关资源
    最近更新 更多