By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,119 Members | 2,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,119 IT Pros & Developers. It's quick & easy.

Can I use VBA to send text to Microsoft Sam (Win XP) from Access 97 to 'speak' the code in modules?

P: n/a
MLH
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?
Nov 21 '05 #1
Share this Question
Share on Google+
17 Replies


P: n/a
MLH
I tried following what I found at
http://msdn.microsoft.com/library/de...tml/sa03f1.asp
but I just couldn't seem to get it to work.
Nov 21 '05 #2

P: n/a
MLH 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?


I have an old DOS (1986) utility from Norton, NE.COM, that has been a
godsend for me over the years. I can pull up 2 files and press a key
and it will go to the first difference between the two files. I can go
thru both files and see all discrepencies between the two files. Since
it's DOS, you can't cut/paste the changes into a program like NotePad.

Anyway, go to http://www.tucows.com. In search, enter something like
Text Compare. You'll find some programs there that should do what you want.
Nov 21 '05 #3

P: n/a
MLH 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?


There is some unix software ported to windows at:

http://unxutils.sourceforge.net/

See if the diff.exe program does what you need. BTW, there was a
poster in the MS groups within the last several weeks who had a problem
that diff.exe could help solve. An enterprising consultant could
benefit from such knowledge.

James A. Fortune

Sometimes I save a whole module into emacs, run a powerful macro or
two, then paste the code back into Access.

Nov 21 '05 #4

P: n/a
MLH
On Mon, 21 Nov 2005 12:59:31 -0500, MLH <CR**@NorthState.net> wrote:
I tried following what I found at
http://msdn.microsoft.com/library/de...tml/sa03f1.asp
but I just couldn't seem to get it to work.


Forgot to say what the error was: Runtime error #2683: There is no
object in this control The offending line is...

Set tts = Me.ActiveXCtl0.Object
Nov 21 '05 #5

P: n/a
MLH
Thx for the suggestion. I would be happy if the reader Microsoft
Sam would work. Meanwhile, diff.exe you say? Thx for the tip on
consulting. I sometime consult with myself - but not with anyone
else. Often, when I am consulting with myself, I often suggest to
myself that I call someone else and ask them.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

There is some unix software ported to windows at:

http://unxutils.sourceforge.net/

See if the diff.exe program does what you need. BTW, there was a
poster in the MS groups within the last several weeks who had a problem
that diff.exe could help solve. An enterprising consultant could
benefit from such knowledge.

James A. Fortune

Sometimes I save a whole module into emacs, run a powerful macro or
two, then paste the code back into Access.


Nov 21 '05 #6

P: n/a

"Salad" <oi*@vinegar.com> schreef in bericht news:de****************@newsread3.news.pas.earthli nk.net...
I have an old DOS (1986) utility from Norton, NE.COM, that has been a
godsend for me over the years. I can pull up 2 files and press a key
and it will go to the first difference between the two files. I can go
thru both files and see all discrepencies between the two files. Since
it's DOS, you can't cut/paste the changes into a program like NotePad.


I use Windows Commander to do just that.
That program is just *fantastic*. You will never use Explorer again ...
File <> Compare by content is what you need here.

Arno R
Nov 21 '05 #7

P: n/a
Can't you just cut and paste into notepad...and have sam read that???

You have to select the text anyway....
Just keep a notepad document open all day....

Highlight...flip to notepad....ctrl-a (select all), then ctrl-v paste you
text...
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.members.shaw.ca/AlbertKallal
Nov 21 '05 #8

P: n/a

"Arno R" <ar***********@tiscali.nl> wrote in message
news:43********************@dreader2.news.tiscali. nl...

"Salad" <oi*@vinegar.com> schreef in bericht
news:de****************@newsread3.news.pas.earthli nk.net...
I have an old DOS (1986) utility from Norton, NE.COM, that has been a
godsend for me over the years. I can pull up 2 files and press a key
and it will go to the first difference between the two files. I can go
thru both files and see all discrepencies between the two files. Since
it's DOS, you can't cut/paste the changes into a program like NotePad.


I use Windows Commander to do just that.
That program is just *fantastic*. You will never use Explorer again ...
File <> Compare by content is what you need here.

Arno R

Windows Commander (now renamed Total Commander) is a really slick program.
I'm too cheap, however, to shell out the few bucks for it. I use a freeware
program called ExamDiff. Excellent tool.

Randy

Nov 21 '05 #9

P: n/a
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

Nov 23 '05 #10

P: n/a
MLH
You know, you're probably quite right. I just don't know how to do
that. The only way I've ever heard SAM talk is when I open him up
and type in a line manually into the one-line textbox there for
testing.
On Mon, 21 Nov 2005 22:42:38 GMT, "Albert D. Kallal" <ka****@msn.com>
wrote:
Can't you just cut and paste into notepad...and have sam read that???

You have to select the text anyway....
Just keep a notepad document open all day....

Highlight...flip to notepad....ctrl-a (select all), then ctrl-v paste you
text...


Nov 23 '05 #11

P: n/a
MLH
Thx polite person. I'm going to have a go at it.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

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


Nov 23 '05 #12

P: n/a
MLH
I get an error at compile time on the following line
Dim Voice As SpVoice
telling me user-defined type not defined.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxx

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


Nov 23 '05 #13

P: n/a
On Tue, 22 Nov 2005 10:46:11 -0500, MLH <CR**@NorthState.net> wrote:
I get an error at compile time on the following line
Dim Voice As SpVoice
telling me user-defined type not defined.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx


I see that I have a reference to the Microsoft Speech Object Library.
Open a code module, go to Tools/ References and see if you can find it in the list, and check it.
If not try to browse to sapi.dll.

Nov 23 '05 #14

P: n/a
On Tue, 22 Nov 2005 16:03:54 GMT, polite person <si*****@ease.com> wrote:
On Tue, 22 Nov 2005 10:46:11 -0500, MLH <CR**@NorthState.net> wrote:
I get an error at compile time on the following line
Dim Voice As SpVoice
telling me user-defined type not defined.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx


I see that I have a reference to the Microsoft Speech Object Library.
Open a code module, go to Tools/ References and see if you can find it in the list, and check it.
If not try to browse to sapi.dll.


If that fails you can always download the speech sdk, which I did in NT4 days -
http://www.microsoft.com/speech/download/sdk51/

it is big and contains a lot more than you need. I can't help feeling that because the speech is
already in XP you shouldn't need to have to download anything.

You probably know that you can set the speaking voice properties via the control panel, speech. You
can also set these by program but if you change them this a a global setting, not just for your
program.

Nov 23 '05 #15

P: n/a
MLH
After adding the Reference you mentioned, I clicked Debug, Compile
Loaded Modules and received an error saying "There was an error
loading an ActiveX control on one of your forms or reports. Make sure
all the controls you are using are properly registered. For info...."

The second time I did the same thing - the error did NOT reappear.
Same for each successive time. I'm curious about the initial error
report. But I can live with dismissing it as a subspace anomoly.

Looks like I'm still not out of hot water though...
Private Sub Command1_Click()
Call SpeakIt("Hello Michael", 1, "")
End Sub

Results in me getting a error on the Voice.Speak Txt, SVSFlagsAsync
line. It says "Run-time error 91. Object variable or With block var-
iable not set."
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx
On Tue, 22 Nov 2005 16:03:54 GMT, polite person <si*****@ease.com>
wrote:
On Tue, 22 Nov 2005 10:46:11 -0500, MLH <CR**@NorthState.net> wrote:
I get an error at compile time on the following line
Dim Voice As SpVoice
telling me user-defined type not defined.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx


I see that I have a reference to the Microsoft Speech Object Library.
Open a code module, go to Tools/ References and see if you can find it in the list, and check it.
If not try to browse to sapi.dll.


Nov 23 '05 #16

P: n/a
On Tue, 22 Nov 2005 12:54:50 -0500, MLH <CR**@NorthState.net> wrote:

Looks like I'm still not out of hot water though...
Private Sub Command1_Click()
Call SpeakIt("Hello Michael", 1, "")
End Sub

Results in me getting a error on the Voice.Speak Txt, SVSFlagsAsync
line. It says "Run-time error 91. Object variable or With block var-
iable not set."


You need to call InitialiseVoice at the start.

Nov 23 '05 #17

P: n/a
MLH
Private Sub Command1_Click()
Call InitialiseVoice
Call SpeakIt("Hello Michael", 1, "")

End Sub

Works like a charm. 'preciate it much.
Nov 23 '05 #18

This discussion thread is closed

Replies have been disabled for this discussion.