Hack Forums
[C#] Text to Speech | Covert text to speech - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] Text to Speech | Covert text to speech (/showthread.php?tid=5161285)



Text to Speech | Covert text to speech - dopepizza - Feb 6, 2016

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. 🤝


* - Tesssa - Feb 8, 2016

This looks pretty cool, shall save it on my disk


* - CancerNut - Aug 14, 2016

Nice share going to download in a bit 🎉


* - Vinnilia - Aug 15, 2016

Nice share, I didn't know it was so easy to make a text to speech program.