Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在vbscript中暂停speak命令?我必须从相同的暂停位置弹奏 如何在vbscript中暂停speak命令?我必须从相同的暂停位置弹奏_Vbscript - Fatal编程技术网

如何在vbscript中暂停speak命令?我必须从相同的暂停位置弹奏 如何在vbscript中暂停speak命令?我必须从相同的暂停位置弹奏

如何在vbscript中暂停speak命令?我必须从相同的暂停位置弹奏 如何在vbscript中暂停speak命令?我必须从相同的暂停位置弹奏,vbscript,Vbscript,代码块: Dim Speak, Path Path = "string" Path = "C:\Users\sony\Desktop\TheReunion.txt" const ForReading = 1 Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile(Path,ForReading) strFileText = objFileToRead.ReadAll() Set Speak=Creat

代码块:

Dim Speak, Path
Path = "string"
Path = "C:\Users\sony\Desktop\TheReunion.txt"
const ForReading = 1
Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile(Path,ForReading)
strFileText = objFileToRead.ReadAll()
Set Speak=CreateObject("sapi.spvoice")
Speak.Speak strFileText
objFileToRead.Close
Set objFileToRead = Nothing

在使用注释中LotPings提到的
pause
resume
方法之前,需要异步调用
speak
方法

代码:


这方面的兴趣使我从Kira的答案中获得灵感,并对其进行了一些改进(以一种不好的新手方式),以交互方式实现暂停/恢复目标,下面的代码对我很有用,希望能对您有所帮助

option explicit
dim strpath, fso, strfile, strtxt, user, voice, flag

flag = 2

call init
sub init
do while len(strpath) = 0
strpath = inputbox ("Please enter the full path of txt file", "Txt to Speech")
if isempty(strpath) then
wscript.quit()
end if
loop
'strpath = "C:\Users\???\Desktop\???.txt"

set fso = createobject("scripting.filesystemobject")
on error resume next
set strfile = fso.opentextfile(strpath,1)
if err.number = 0 then
strtxt = strfile.readall()
strfile.close
call ctrl
else
wscript.echo "Error: " & err.number & vbcrlf & "Source: " & err.source & vbcrlf &_
"Description: " & err.description
err.clear
call init
end if
end sub

sub ctrl
user = msgbox("Press ""OK"" to Play / Pause", vbokcancel + vbexclamation, "Txt to Speech")
select case user
case vbok
    if flag = 0 then
        voice.pause
        flag = 1
        call ctrl
    elseif flag = 1 then
        voice.resume
        flag = 0
        call ctrl
    else
        call spk
    end if
case vbcancel
    wscript.quit
end select
end sub 

sub spk
'wscript.echo strtxt
set voice = createobject("sapi.spvoice")
voice.speak strtxt,1
flag = 0
call ctrl
end sub

如果要在VBScript中执行某些操作,请将其标记为仅VBScript。不要试图用不相关的语言来诱使别人看你的问题。关于语言和方法呢?谢谢@LotPingsThanks alot@Albert Fitzwilliam Digby
option explicit
dim strpath, fso, strfile, strtxt, user, voice, flag

flag = 2

call init
sub init
do while len(strpath) = 0
strpath = inputbox ("Please enter the full path of txt file", "Txt to Speech")
if isempty(strpath) then
wscript.quit()
end if
loop
'strpath = "C:\Users\???\Desktop\???.txt"

set fso = createobject("scripting.filesystemobject")
on error resume next
set strfile = fso.opentextfile(strpath,1)
if err.number = 0 then
strtxt = strfile.readall()
strfile.close
call ctrl
else
wscript.echo "Error: " & err.number & vbcrlf & "Source: " & err.source & vbcrlf &_
"Description: " & err.description
err.clear
call init
end if
end sub

sub ctrl
user = msgbox("Press ""OK"" to Play / Pause", vbokcancel + vbexclamation, "Txt to Speech")
select case user
case vbok
    if flag = 0 then
        voice.pause
        flag = 1
        call ctrl
    elseif flag = 1 then
        voice.resume
        flag = 0
        call ctrl
    else
        call spk
    end if
case vbcancel
    wscript.quit
end select
end sub 

sub spk
'wscript.echo strtxt
set voice = createobject("sapi.spvoice")
voice.speak strtxt,1
flag = 0
call ctrl
end sub