Reading Text Aloud in Microsoft Access

Want a quick way to get started with Text-to-Speech in your VBA application? This 4-line method gets the job done and requires no references!

Reading Text Aloud in Microsoft Access

Want to try something fun?

The following VBA method will read aloud the string that you pass to it:

Sub Speak(Msg As String, Optional Gender As String = "Male")
    Dim Vox As Object ' SpeechLib.SpVoice
    Set Vox = CreateObject("SAPI.SpVoice") ' New SpeechLib.SpVoice
    Set Vox.Voice = Vox.GetVoices("Gender = " & Gender).Item(0)
    Vox.Speak Msg    
End Sub

The above code uses late binding so there is no need to add References to your project.  You can set the voice's gender with the optional Gender parameter.  

Here's a short video of the method in action:

I plan on going more in-depth on this topic in future articles, but this should be enough to whet your appetite for now.  If you can't wait for those articles–or you really enjoy going down rabbit holes–check out Colin Riddington's Translate & Speak sample database.

External references

Translate & Speak
This sample database builds on the code that @arnelgp used in his sample Language Translator database in this thread Language Translator | Access World Forums (access-programmers.co.uk). Text translation uses the online Google Translate service and was based on that arnelgp found at How to Parse...

Image by Fabio Fabio from Pixabay

All original code samples by Mike Wolfe are licensed under CC BY 4.0