Speak with female voice - VBA text to speech code

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
1,832
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:

Some videos you may like

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Dossfm0q

Well-known Member
Joined
Mar 9, 2009
Messages
507
Office Version
  1. 2019
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,119,088
Messages
5,576,040
Members
412,694
Latest member
Deaf1Too
Top