by Steegy » Wed Apr 19, 2006 6:32 am
Hello
What you are suggesting can easily be done, however you need to have a TextToSpeech engine installed. SAPI5 is installed by default on WindowsXP systems, so let's use this one (it's the best free one).
Please do mind that a computer voice like SAPI can be very irritating, certainly if it is used with nice music.
Usage:
ttsSpeak YourTextToSpeek, VoiceNumber, Asynchronous
- VoiceNumber is the installed voice on your computer (most have only one). Use 0 if you want to use the default voice.
- Asynchronous should be set to False, unless you are calling the method from another method that takes long to complete.
Code: Select all
ttsSpeak "Hello, this is just a little test.", 0, False
Sub ttsSpeak(Text, VoiceNumber, Asynchronous)
Dim tts, speechFlag
On Error Resume Next
Set tts = Nothing
Set tts = CreateObject("Sapi.SpVoice")
If Not tts Is Nothing Then
If (VoiceNumber - 1) < tts.GetVoices.Count Then
Err.Clear
If VoiceNumber <> 0 Then Set tts.Voice = tts.GetVoices.Item(VoiceNumber - 1)
If Err.Number = 0 Then
If Asynchronous Then
speechFlag = 1
Else
speechFlag = 0
End If
tts.Speak Text, speechFlag
End If
End If
End If
End Sub
BTW: Because TextToSpeech and Speech recognition are about the same subject (like SAPI), this certainly isn't of topic.
Similar functions for SAPI4 also exist, but this is an old thing. Consider using SAPI5 instead (well, WindowsXP users will be very easy as it is already installed by default)
BTW2: This sample of code is very similar to what is programmed in major programming languages (c++, java, c#, vb, ...).
Cheers
Steegy
Hello
What you are suggesting can easily be done, however you need to have a TextToSpeech engine installed. SAPI5 is installed by default on WindowsXP systems, so let's use this one (it's the best free one).
Please do mind that a computer voice like SAPI can be very irritating, certainly if it is used with nice music.
[u]Usage:[/u]
[i]ttsSpeak YourTextToSpeek, VoiceNumber, Asynchronous[/i]
- VoiceNumber is the installed voice on your computer (most have only one). Use 0 if you want to use the default voice.
- Asynchronous should be set to False, unless you are calling the method from another method that takes long to complete.
[code]ttsSpeak "Hello, this is just a little test.", 0, False
Sub ttsSpeak(Text, VoiceNumber, Asynchronous)
Dim tts, speechFlag
On Error Resume Next
Set tts = Nothing
Set tts = CreateObject("Sapi.SpVoice")
If Not tts Is Nothing Then
If (VoiceNumber - 1) < tts.GetVoices.Count Then
Err.Clear
If VoiceNumber <> 0 Then Set tts.Voice = tts.GetVoices.Item(VoiceNumber - 1)
If Err.Number = 0 Then
If Asynchronous Then
speechFlag = 1
Else
speechFlag = 0
End If
tts.Speak Text, speechFlag
End If
End If
End If
End Sub[/code]
BTW: Because TextToSpeech and Speech recognition are about the same subject (like SAPI), this certainly isn't of topic.
Similar functions for SAPI4 also exist, but this is an old thing. Consider using SAPI5 instead (well, WindowsXP users will be very easy as it is already installed by default)
BTW2: This sample of code is very similar to what is programmed in major programming languages (c++, java, c#, vb, ...).
Cheers
Steegy