如何让 TTS 机器人说出计算机用户名?

问题描述

我正在尝试制作一个 VBS 脚本,该脚本可以使用 TTS 在您的计算机上说出您的用户名

function mutateTheArray(n,a) {
    let b = []

    for(i=0; i <= n-1; i++){
        if(i==0){
            b[0] = a[0] + a[1]
        }
        if(i == n-1){
            b[i] = a[i-1] + a[i]
        }
        else{
            b[i] = a[i-1] + a[i] + a[i+1]
        }
    }
    return b
}
console.log(mutateTheArray(5,[4,1,-2,3]));

有人可以帮助我了解如何获取用户名并将其分配为变量,以便可以从 TTS bot 中发音吗?

谢谢。

解决方法

如所问...说出用户名:

Set Sapi = WScript.CreateObject("SAPI.Spvoice")
Set oWSH = CreateObject("Wscript.Shell")
UserName = oWSH.RegRead("HKCU\Volatile Environment\UserName")
Sapi.Speak UserName

替代...说出显示名称:

Set Sapi = WScript.CreateObject("SAPI.Spvoice")
Set oWSH = CreateObject("Wscript.Shell")
LoggedOnDisplayName = oWSH.RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\SessionData\1\LoggedOnDisplayName")
Sapi.Speak LoggedOnDisplayName
,

参考此How to get username with vbs。你可以这样写:

UserName = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%USERNAME%")
createobject("SAPI.Spvoice").Speak UserName

或者也喜欢这个例子:

UserName = CreateObject("WScript.Network").UserName
createobject("SAPI.Spvoice").Speak UserName