如何在 vbscript 中暂停说话命令?我必须从同一个暂停位置播放它


  1. 如何在 vbscript 中暂停说话命令?我必须从同一个暂停位置播放它。
  2. 代码块:

    Dim Speak, Path
    Path = "string"
    Path = "C:UserssonyDesktopTheReunion.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 在注释中提到的pauseresume方法之前,您需要异步调用speak方法。

法典:

Dim Speak, Path
Path = "string"
Path = "C:UserssonyDesktopTheReunion.txt"
const ForReading = 1
Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile(Path,ForReading)
strFileText = objFileToRead.ReadAll()
Set Speak=CreateObject("sapi.spvoice")
Speak.Speak strFileText,1                          '1=Asynchronous. Click the link below for other possible values "SpeechVoiceSpeakFlags"
'Due to async call to speak method, we can proceed with the code execution while the voice is being played in the background. Now we can call pause and resume methods
wscript.sleep 5000                 'voice played for 5000ms
Speak.pause                        'paused
wscript.sleep 4000                 'remains paused for 4000ms 
Speak.resume                       'resumes 
objFileToRead.Close
Set objFileToRead = Nothing

演讲语音说话标志

对此的阴谋使我从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

最新更新