0 votes
in VBA by Beginner (2 points)

Hi, i'm trying to use SpeakAsync with supertalk.

I saw on this website that you can change the voice, volume and speed with "supertalk"

Sub ChangeVoiceDemo()
SuperTalk "Excel is talking to me.", "BOY", 2, 100
SuperTalk "Excel is talking to me.", "GIRL", 2, 100
SuperTalk "Excel is talking to me.", "BOY", -10, 30
SuperTalk "Excel is talking to me.", "GIRL", 10, 70
End Sub

Private Sub SuperTalk(Words As String, Person As String, Rate As Long, Volume As Long)
Dim Voc As SpeechLib.SpVoice
Set Voc = New SpVoice

With Voc
    If UCase(Person) = "BOY" Then
        Set .Voice = .GetVoices.Item(0)
    ElseIf UCase(Person) = "GIRL" Then
        Set .Voice = .GetVoices.Item(1)
    End If
    .Rate = Rate
    .Volume = Volume
    .Speak Words
End With
End Sub

And I saw that you can use "SpeakAsync" to continue the code while the excle is speaking

Sub TalkToMe3()
Application.Speech.Speak "Excel is talking to me", SpeakAsync:=True
MsgBox "test"
End Sub

But I can't find a way to do the simultaneously.

It will be much appreciated if someone could help with this.

1 Answer

0 votes
by Skilled (670 points)
edited by

This is Rev.1 of my original answer:

Sub ChangeVoiceDemo()
SuperTalk "Excel is talking to me.", "BOY", 2, 100
SuperTalk "Excel is talking to me.", "GIRL", 2, 100
SuperTalk "Excel is talking to me.", "BOY", -10, 30
SuperTalk "Excel is talking to me.", "GIRL", 10, 70
End Sub

Private Sub SuperTalk(Words As String, Person As String, Rate As Long, Volume As Long)
Dim Voc As SpeechLib.SpVoice
Set Voc = New SpVoice

With Voc
    If UCase(Person) = "BOY" Then
        Set .Voice = .GetVoices.Item(0)
    ElseIf UCase(Person) = "GIRL" Then
        Set .Voice = .GetVoices.Item(1)
    End If
    .Rate = Rate
    .Volume = Volume
    .Speak Words, SVSFlagsAsync
    'add your code here
    'for example
    Cells(1, 1) = Words
    Cells(2, 1) = Person
    Cells(3, 1) = Rate
    Cells(4, 1) = Volume
    'end example
    Do
        DoEvents
    Loop Until .WaitUntilDone(10)
End With
End Sub

It starts Speak asnychronously, then enters a tight loop permitting events every 10 msec until Speak is done. This allows Excel user interaction while speaking. If you want your code to do something while speaking, add it where indicated by the example. See SpVoice WaitUntilDone for more info.

Welcome to wellsr Q&A
wellsr Q&A is the VBA and Python programming community that rewards you for learning how to code.

Getting Started
Register
VBA Cheat Sheets (On Sale Now)

Earn free prizes for asking VBA and Python questions and for answering questions asked by others in our community.

Looking for something else? Hire our professional VBA Help, instead.

What makes us different?
Our points system rewards you with a chance for free gifts based on the quality of your questions and answers. All you have to do is post and you could get rewarded, like these members:

ParserMonster $25 Amazon Gift Card
Hightree $10 Amazon Gift Card
Thales1 $10 Amazon Gift Card
runfunke $10 Amazon Gift Card
coolag $10 Amazon Gift Card
Siew Hun $10 Amazon Gift Card

So, why don't you join us? It really is an encouraging way to motivate members in our VBA and Python community.

Register

For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.

...