Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Text to Speech | Covert text to speech

Hi guys.
I have made a program that converts text to speech.
I also got help from Odus when I got stuck. (Thanks a lot Odus.✌ )

Image:
Spoiler (Click to View)
You can speak, pause, resume and save.

Source code:
PHP Code

<?php 
using System
;
using System.Windows.Forms;
using System.Speech.Synthesis;
using System.IO;

namespace 
TextToSpeech
{
    public 
partial class frmMain : Form
    
{
        
SpeechSynthesizer _voice;

        public 
frmMain()
        {
            
InitializeComponent();

            
            
_voice = new SpeechSynthesizer();
            
cboSelectVoice.DataSource = Enum.GetValues(typeof(VoiceGender));
            
        }

        private 
void Speak_Click(object sender, EventArgs e)
        {
            
_voice.SelectVoiceByHints((VoiceGender)cboSelectVoice.SelectedItem);


            if (!
string.IsNullOrEmpty(txtContent.Text))
                
_voice.SpeakAsync(txtContent.Text);
        }

        private 
void Save_Click(object sender, EventArgs e)
        {
            
using (SaveFileDialog sfd = new SaveFileDialog()
            {
                
Filter = "Wav Files|*.wav",
                
Title = "Save File as Wav"
            
})
            {
                if (
sfd.ShowDialog() != DialogResult.OK)
                    return;

                try
                {
                    
using (var fs = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write))
                    {
                        
_voice.SetOutputToWaveStream(fs);
                        
_voice.Speak(txtContent.Text);
                    }
                }
                catch (
Exception ex)
                {
                    
//handle here
                
}
            }
        }

        private 
void Pause_Click(object sender, EventArgs e) =>
            
_voice.Pause();

        private 
void Resume_Click(object sender, EventArgs e) =>
            
_voice.Resume();

        private 
void frmMain_Load(object sender, EventArgs e)
        {

        }
    }
} 

Download:
Spoiler (Click to View)

Thanks again for helping me Odus.
Tomorrow i will probably put out another release.
See you all later. 🤝
This looks pretty cool, shall save it on my disk
Nice share going to download in a bit 🎉
Nice share, I didn't know it was so easy to make a text to speech program.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by bots4totsSep 7, 2019 07:59 AM 2 377 Sep 7, 2019 07:59 AM
Last Post: bots4tots
[.NET] by SIM-3327349Sep 17, 2017 04:21 PM 14 305 Sep 17, 2017 04:21 PM
Last Post: SIM-3327349
[.NET] by Virtual-EchoMar 26, 2016 03:12 PM 7 264 Mar 26, 2016 03:12 PM
Last Post: Ninja