Hi David,

    This is the initializing of the SAPI voices in the SAPI45class file I had 
sent you.

    The setup for SAPI 4 is completely different then SAPI 5 so you problem 
starts there.
SAPI 4:
        Set tts4 = CreateObject("ActiveVoice.ActiveVoice")
        if Err.number > 0 then
            tts4Q = False
        else
            tts4.Speak("")
            voices4count = tts4.CountEngines


    Read and find the solution here:
        Bruce
    Private Sub Class_Initialize
        dim i
        Set Dict = CreateObject("Scripting.Dictionary")
        tts5Q = True
        ttsAudioFormat = 35 '44K 16 bit Stereo.
        ttsFileStreamEnabled = False
        ttsEnabled = False
        On Error Resume Next
        Err.Clear
        Set tts5 = CreateObject("sapi.spvoice")
        if Err.number > 0 then
            tts5Q = False
        else
            tts5.Speak("")
            sapiMode = 5
            ttsEnabled = True
            Set myTtsFileStream = CreateObject( "sapi.spfilestream")
            If Not myTtsFileStream Is Nothing Then
                ttsFileStreamEnabled = True
            End If
            voices5count = tts5.GetVoices.Count
            if voices5count<10 then
                ReDim voice5list(10)
            else
                if voices5count<20 then
                    ReDim voice5list(20)
                else
                    if voices5count<30 then
                        ReDim voice5list(30)
                    else
                        ReDim voice5list(40)
                    end if
                end if
            end if
            for i = 0 to voices5count-1
                voice5list( i) = tts5.GetVoices.Item( i).GetDescription
            next
        end if
        tts4Q = True
        On Error Resume Next
        Err.Clear
        Set tts4 = CreateObject("ActiveVoice.ActiveVoice")
        if Err.number > 0 then
            tts4Q = False
        else
            tts4.Speak("")
            voices4count = tts4.CountEngines
            if voices4count<=10 then
                ReDim voice4list(10)
            else
                if voices4count<=20 then
                    ReDim voice4list(20)
                else
                    if voices4count<=30 then
                        ReDim voice4list(30)
                    else
                        ReDim voice4list(40)
                    end if
                end if
            end if
            for i = 1 to voices4count
                voice4list( i) = tts4.modeName( num)
            next
        end if
        defaultspeed = 0
        pitch = 0
        defaultvolume = 100
        default_spk = 0
        sync = 0 ' Default: CONTINUOUS SPEECH!
        async = 1 ' Comes back after spoken phrase.
        purge = 2 'STOP BEFORE SPEAK only if async is used!
        isfile = 4 'OPEN TEXT AS TEXT FILE NAME AND SPEAK FILE TEXT!
        xml = 8 'USE XML TAGS!
        no_xml = 16 'IGNORE XML TAGS!
        persist = 32 'XML NEW TAGS PERSIST IN ALL SPEECH!
        punc = 64 'SAY ALL PUNCTUATIONS!
    End Sub


  Sent: Tuesday, February 11, 2014 10:22 AM
  Subject: Re: Using a SAPI voice?


  Thanks, again.

  Have one more question, if anyone could help in clarifying something. Here is 
a code snip:

  Dim SVoice: Set SVoice = CreateObject( "Sapi.SpVoice")
  Dim SItem
  For Each SItem In SVoice.GetVoices
      MsgBox SItem.GetDescription
  Next 'SItem.

  OK, the code is not very useful as it stands, it simply just lists the names 
of all the SAPI voices on your system. Or, rather, that is what I hoped it did. 
Yet, it seems from my observation, that only Sapi5 voices are being recognized. 
Is that the case? What is the correct syntax, to include Sapi4 voices? Or, 
could there be other reasons, why not all my SAPI voices are listed with the 
above code? Not a big deal, And I know I could go the more thorough way, around 
the Synthesizer objects in Window-Eyes, but I just wanted to make sure I 
understand the nature of the SAPI.SpVoice class. Sometimes, you just have 
better luck in going directly to an object or class, rather than use the WE 
objects. No critics here, simply just asking for some clarification on the 
matter. Smile.

  Thanks again, everyone.

    ----- Original Message -----
    From: LB
    To: GW Scripting
    Sent: Tuesday, February 11, 2014 6:18 AM
    Subject: Re: Using a SAPI voice?



    Hi David,

        As usual I said the opposite of what I meant, the async method is what 
you want and is the value of 1.
        Purge clears out the speech buffer and stops the existing speech.
        So the Speak method is the opposite of the default since it speaks in 
the background and the default does not since you had asked the question why 
and what.

    Correction:
          Inside my Sapi class I had changed the statements to no wait until 
done format. Where the speak statement inside the class defaults to Async mode 
which sets the wait until done to false. I did this to enable the purge 
statement to cancel speech during the talk for it requires both flags.
          For the sync mode ignores any interrruptions, thus any purge is 
ignored.

          So my Sapi class has the Speak method doing what you want with the 
default of shutting off any existing speech.
          I added another version of this by saying or calling it SpeakNext 
which does not erase the buffer but does what is says, it speaks next in queue.

          So in my Sapi class just use:
      oTTSEngine.Speak text  'If you want existing speech stopped.
      oTTSEngine.SpeakNext text 'Speaks this text after the existing stops.

      oTTSEngine.Speaking text 'speaks text and xml tags with existing speech 
stopped.
      Example:
      oTTSEngine.Speaking "To spell your name David: " & <spell> & "David" & 
"</spell>"

      oTTSEngine.SpeakAsIs text, flags 'defaults to the default, sync mode 
speech. It also allows you to pass any of the flags in just like the standard 
Sapi Speak method does.

      Or when you do not want to use my class then just do it as a standard 
format and instead of using SpeakAsIs text, flags just use the built in format: 
oTTS.Speak text, flags (where flags are or together: async, purge, xml, or punc)

              Bruce

        Sent: Monday, February 10, 2014 7:58 PM
        Subject: Re: Using a SAPI voice?


        Hi David,

            There is a flag to set asynchronous calls and in my SAPI class I 
set up the calls in public statements,
        Format:
        (Without Pitch)
        oTTS.Speak txt, async Or xml
        (With Pitch)
        oTTS.Speak "<pitch absmiddle=""" & CStr( getPitch) & """>" & txt & 
"</pitch>", flags

        Flags:
        Everything is and or or together in one line for the flags which are 
below:

        The default is sync and is 0, I don't know what your flag settings are 
but it should be the default if no flags sent.

                default_spk = 0
                sync = 0 ' Default: CONTINUOUS SPEECH!
                async = 1 ' Comes back after spoken phrase.
                purge = 2 'STOP BEFORE SPEAK only if async is used!
                isfile = 4 'OPEN TEXT AS TEXT FILE NAME AND SPEAK FILE TEXT!
                xml = 8 'USE XML TAGS!
                no_xml = 16 'IGNORE XML TAGS!
                persist = 32 'XML NEW TAGS PERSIST IN ALL SPEECH!
                punc = 64 'SAY ALL PUNCTUATIONS!

          Sent: Monday, February 10, 2014 4:33 PM
          Subject: Using a SAPI voice?


          In my app, I am using a SAPI voice, to read out a certain amount of 
text. the very basics of the code, is:

          Dim SVoice: Set SVoice = CreateObject( "SAPI.SpVoice")
          SVoice.Speak "blah-blah-blah!"

          Allright, all of this works fine. Yet, since the text is somehow 
lengthy, and I want other processes not to wait for all that text to be spoken, 
I have this one question for you experienced developers.

          Is there any instruction I can use, to send the text to the Sapi 
voice, and immediately have the next line of code carried out? That is, some 
kind of an instruction for the Sapi Object, to know that it is not supposed to 
wait for the voice to finish speaking, before the code can move on.

          Thanks for any response, and hope the above somehow made sense.




------------------------------------------------------------------------
                This email is free from viruses and malware because avast! 
Antivirus protection is active.






--------------------------------------------------------------------------
              This email is free from viruses and malware because avast! 
Antivirus protection is active.






----------------------------------------------------------------------------
            This email is free from viruses and malware because avast! 
Antivirus protection is active.




---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com

Reply via email to