Speak with female voice - VBA text to speech code

kelly mort

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

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Dossfm0q

Active Member
Joined
Mar 9, 2009
Messages
478
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,118,140
Messages
5,570,405
Members
412,322
Latest member
mohi021
Top