On Mon, 21 Nov 2005 12:44:53 -0500, MLH <CR**@NorthState.net> wrote:
From time to time, I find myself cross checking one block of code
against another. Usually older stuff in which I've made modifications
that don't work. I don't remember what all the changes were so I
have to print an earlier version and compare it against a printout
of a more recent version. I am dyslexic and it is helpful to have
someone read one copy while I follow along on another copy
until we hit a discrepancy.
Could I somehow call on Microsoft Sam to do that w/o involving
another person? I have that program in my Control Panel. I don't
know how to call it up and feed it text though.
Any exeriences you care to share?
Yes.
Example code ex MS below.
I did this some time ago when you had to download SAPI and install it but the voice feature is
now in Windows (2000/XP) so maybe that is no longer necessary.
Option Compare Database
Option Explicit
'================================================= ============================
'
' This SimpleTTS sample application demonstrates how to create a SpVoice object
' and how to use it to speak text and save it to a .wav file.
'
' Copyright @ 2001 Microsoft Corporation All Rights Reserved.
'================================================= ============================
'Declare the SpVoice object.
Dim Voice As SpVoice
'Note - Applications that require handling of SAPI events should declair the
'SpVoice as follows:
'Dim WithEvents Voice As SpVoice
Public Sub InitialiseVoice()
' Initialize the voice object
Set Voice = New SpVoice
End Sub
Public Sub SpeakIt(Txt$, ByVal sMode&, Wfilename$)
'On Error GoTo Speak_Error
'mode=1 speak
'mode=2 save
If Len(Txt) = 0 Then Return
If sMode = 2 Then
SaveToWav Txt$, Wfilename
Else
' Call the Speak method with the text from the text box. We use the
' SVSFlagsAsync flag to speak asynchronously and return immediately
' from this call.
Voice.Speak Txt, SVSFlagsAsync
End If
Exit Sub
Speak_Error:
MsgBox "Speak Error!", vbOKOnly
End Sub
Private Sub SaveToWav(Txt$, Wfilename$)
' Create a wave stream
Dim cpFileStream As New SpFileStream
If Len(Wfilename) = 0 Then Return
' Set audio format
cpFileStream.Format.Type = SAFT22kHz16BitMono
' Create a new .wav file for writing. False indicates that we're not
' interested in writing events into the .wav file.
' Note - this line of code will fail if the file exists and is currently open.
cpFileStream.Open Wfilename, SSFMCreateForWrite, False
' Set the .wav file stream as the output for the Voice object
Set Voice.AudioOutputStream = cpFileStream
' Calling the Speak method now will send the output to the "SimpTTS.wav" file.
' We use the SVSFDefault flag so this call does not return until the file is
' completely written.
Voice.Speak Txt, SVSFDefault
' Close the file
cpFileStream.close
Set cpFileStream = Nothing
' Reset the Voice object's output to 'Nothing'. This will force it to use
' the default audio output the next time.
Set Voice.AudioOutputStream = Nothing
Cancel:
Exit Sub
End Sub