If you want to spell out the content of text file using VBA you can do it as shown below:
Sub Speech_FromFile_Example() Dim oVoice As SpVoice ' Voice Object Dim oVoiceFile As SpFileStream ' File Stream Object Dim sFile As String ' File Name Set oVoice = New SpVoice Set oVoiceFile = New SpFileStream ' -------------------------------------------------------------- ' Code for http://vbadud.blogspot.com ' -------------------------------------------------------------- oVoice.Speak "This is an example for reading out a file" sFile = "C:\ShasurData\ForBlogger\SpeechSample.txt" oVoiceFile.Open sFile oVoice.SpeakStream oVoiceFile End Sub
The above code creates a filestream and reads the text file and the Voice object speaks it out!
The code requires Microsoft Speech Object Library (see figure below)
See also:
Good but how to save mp3 file of that text
ReplyDeleteThanks
sameer
sameertanpure29390@gmail.com
Thank you for sharing this code snippet.
ReplyDeleteI would really like to know how to save the output of speech to a MP3 file.
I get an error about the function being restricted or using an automation interface not supported by VBA...
ReplyDeleteIt works for me. i changed slightly to read the text from the selection. but the problem is, it reads only 127 characters. is there any way to put streaming after that. However it is an excellent code. Thank you very much. it would be great if can fix the max character issue
ReplyDeleteThank you very much for this useful article. I like it. https://onlineconvertfree.com/
ReplyDelete