0

I am new in Microsoft .Net Technologies, I am working on a project which converts text to speech and text to audio.

Dim SAPI = CreateObject("SAPI.spvoice")
Private Sub Speak_Click(sender As Object, e As EventArgs) Handles Speak.Click

    SAPI.Speak(TextBox1.Text)

End Sub

Above is my code, please guide me to how to save that text into an audio file. I am using latest 2k17 .net technologies. Thanks

braX
  • 11,506
  • 5
  • 20
  • 33
John Doe
  • 1
  • 1

1 Answers1

0

You can save the SAPI output to a .WAV file as follows:

  1. Create and open a .WAV file as a stream using the SpFileStream.Open method.
  2. Assign this file stream to the SpVoice.AudioStream property.

Here's an example:

Const SAFT48kHz16BitStereo = 39
Const SSFMCreateForWrite = 3 ' Creates file even if file exists and so destroys or overwrites the existing file

Dim oFileStream, oVoice

Set oFileStream = CreateObject("SAPI.SpFileStream")
oFileStream.Format.Type = SAFT48kHz16BitStereo
oFileStream.Open "C:\Work\Sample.wav", SSFMCreateForWrite

Set oVoice = CreateObject("SAPI.SpVoice")
Set oVoice.AudioOutputStream = oFileStream
oVoice.Speak "Hello world", 3

oVoice.WaitUntilDone(10000)

oFileStream.Close

https://stackoverflow.com/a/20537139/1744176

Ashish Emmanuel
  • 728
  • 11
  • 23