This is a macro to demonstrate text to speech capabilities. A userForm pops up asking for text. The user types in any text and
the user's computer will read the text aloud. Pressing enter triggers the text to speech subroutine and then the userForm is cleared. There are more simple macros on the
SolidWorks Macros page.
Audio2.swp
- Dim speaks, speech
- Sub main()
- UserForm1.Show
- End Sub
- Sub sayThis(sp As String)
- Set speech = CreateObject("sapi.spvoice")
- speech.Speak sp
- End Sub
Below is the userForm code. I set this macro up so you can continuously enter text and run the text to speech
subroutine every time the enter button is pressed. The userForm is basically listening for the enter button to be pressed before triggering the
text to speech subroutine and then clearing out the userForm's text. Pressing the Exit button ends the macro with one line of code. There are more simple macros on the
SolidWorks Macros page.
- Private Sub CommandButton1_Click()
- End
- End Sub
- Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
- If KeyCode = 13 Then
- KeyCode = 0 'this line keeps the focus from shifting away from Textbox1'
- speaks = TextBox1.Text
- TextBox1.Text = ""
- sayThis (speaks)
- End If
- End Sub