Could anyone help me please. I have made a Text-To-Speech application using SpeechSynthesizer, it has Play, Pause, Resume, and Stop, but also you can change the voice, rate and volume, and also save as audio (mp3, wav).
But the question is: How do I display the file size of the audio file before the file is created depending on
My code for Form1 is:
Imports System.Speech.Synthesis
Imports System.IO
Public Class Form1
Dim speech As New SpeechSynthesizer
Private Sub ControlBtn_Click(sender As System.Object, e As System.EventArgs) Handles ControlBtn.Click
Form2.ShowDialog()
End Sub
Private Sub speakCompleted(ByVal sender As Object, ByVal e As SpeakCompletedEventArgs)
Dim cancelled = e.Cancelled
PlayBtn.Enabled = True
PauseBtn.Enabled = False
ResumeBtn.Enabled = False
StopBtn.Enabled = False
End Sub
Private Sub PlayBtn_Click(sender As System.Object, e As System.EventArgs) Handles PlayBtn.Click
speech.SelectVoice(Form2.ComboBox1.Text)
speech.Rate = Form2.RateTB.Value
speech.Volume = Form2.VolumeTB.Value
speech.SpeakAsync(RichTextBox1.Text)
PlayBtn.Enabled = False
ResumeBtn.Enabled = False
PauseBtn.Enabled = True
StopBtn.Enabled = True
AddHandler speech.SpeakCompleted, AddressOf speakCompleted
End Sub
Private Sub StopBtn_Click(sender As System.Object, e As System.EventArgs) Handles StopBtn.Click
speech.SpeakAsyncCancelAll()
StopBtn.Enabled = False
PauseBtn.Enabled = False
ResumeBtn.Enabled = False
PlayBtn.Enabled = True
End Sub
Private Sub ResumeBtn_Click(sender As System.Object, e As System.EventArgs) Handles ResumeBtn.Click
speech.Resume()
PlayBtn.Enabled = False
ResumeBtn.Enabled = False
PauseBtn.Enabled = True
StopBtn.Enabled = True
End Sub
Private Sub PauseBtn_Click(sender As System.Object, e As System.EventArgs) Handles PauseBtn.Click
speech.Pause()
PauseBtn.Enabled = False
PlayBtn.Enabled = False
StopBtn.Enabled = True
ResumeBtn.Enabled = True
End Sub
Private Sub SaveAsAudioBtn_Click(sender As System.Object, e As System.EventArgs) Handles SaveAsAudioBtn.Click
Dim mes As New MsgBoxResult
mes = MsgBox("Voice: " & Form2.ComboBox1.Text & vbNewLine & "Rate: " & Form2.RateTB.Value & vbNewLine & "Volume: " & Form2.VolumeTB.Value & vbNewLine & vbNewLine & "Your file size has been estimated at." & vbNewLine & vbNewLine & "Do you want to proceed?", MsgBoxStyle.YesNo, "Save as Audio")
If mes = MsgBoxResult.Yes Then
SaveFileDialog1.Filter = "MPEG-2 Audio Layer III (*.mp3)|*.mp3|WAVeform audio format (*.wav)|*.wav"
SaveFileDialog1.Title = "Save as Audio file"
SaveFileDialog1.RestoreDirectory = True
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim fs As New FileStream(SaveFileDialog1.FileName, FileMode.Create, FileAccess.Write)
speech.SelectVoice(Form2.ComboBox1.Text)
speech.Rate = Form2.RateTB.Value
speech.Volume = Form2.VolumeTB.Value
speech.SetOutputToWaveStream(fs)
speech.Speak(RichTextBox1.Text)
fs.Close()
End If
ElseIf mes = MsgBoxResult.No Then
End If
End Sub
End Class
And the code for Form2 is:
Imports System.Speech.Synthesis
Imports System.Collections.ObjectModel
Public Class Form2
Dim speech As New SpeechSynthesizer
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim objvoices As ReadOnlyCollection(Of InstalledVoice) = Speech.GetInstalledVoices(Globalization.CultureInfo.CurrentCulture)
Dim objvoiceInformation As VoiceInfo = objvoices(0).VoiceInfo
For Each tmpvoice As InstalledVoice In objvoices
objvoiceInformation = tmpvoice.VoiceInfo
ComboBox1.Items.Add(objvoiceInformation.Name.ToString)
Next
End Sub
End Class
It would be great if you could give me the code for it.