Speak with female voice - VBA text to speech code

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Hi there,


I want the voice recorded in a female voice. Can someone fix this for me?

I found this on Wikipedia

Thanks


Code:
Sub TestStringToWavFile()
    Dim sP$, sFN$, sStr$, sFP$
    sP = ThisWorkbook.Path & "\work\"
    sFN = "Mytest.mp3"
    sFP = sP & sFN
    sStr = "I want you to speak with a female voice"
    StringToWavFile sStr, sFP
End Sub


Function StringToWavFile(sIn$, sPath$) As Boolean
    Dim fs As New SpFileStream
    Dim Voice As New SpVoice
    fs.Format.Type = SAFT22kHz16BitMono
    fs.Open sPath, SSFMCreateForWrite, False
    Set Voice.AudioOutputStream = fs
    Voice.Speak sIn, SVSFDefault
    fs.Close
    Voice.WaitUntilDone (6000)
    Set fs = Nothing
    Set Voice.AudioOutputStream = Nothing
    StringToWavFile = True
End Function
 
Last edited:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Sorry I Came Here to find Google Translate Play Sound and Found This If you Have Please Help

below Your request:
'Set Voice.Voice = Voice.GetVoices.Item(0) '0 Male
Set Voice.Voice = Voice.GetVoices.Item(1) '1 Female

VBA Code:
Public Declare Function sndPlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Sub TestStringToWavFile()

    Dim sP$, sFN$, sStr$, sFP$
    sP = ThisWorkbook.Path & "\"
    sFN = "Mytest.mp3"
    sFP = sP & sFN
    sStr = "I want you to speak with a female voice"
    StringToWavFile sStr, sFP
End Sub

Function StringToWavFile(sIn$, sPath$) As Boolean

    Dim fs As New SpFileStream
    Dim Voice As New SpVoice
     'Set Voice.Voice = Voice.GetVoices.Item(0) '0 Male
     Set Voice.Voice = Voice.GetVoices.Item(1) '1 Female
    fs.Format.Type = SAFT22kHz16BitMono
    fs.Open sPath, SSFMCreateForWrite, False
    Set Voice.AudioOutputStream = fs
    Voice.Speak sIn, SVSFDefault
    fs.Close
    Voice.WaitUntilDone (6000)
    Set fs = Nothing
    Set Voice.AudioOutputStream = Nothing
    StringToWavFile = True
    
    PlayWavFile sPath$, False ' Play
    
End Function
Sub PlayWavFile(WavFileName As String, Wait As Boolean)

    If Dir(WavFileName) = "" Then Exit Sub ' no file to play
    If Wait Then ' play sound before running any more code
        sndPlaySound WavFileName, 0
    Else ' play sound while code is running
        sndPlaySound WavFileName, 1
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top