Create Text to Speech/Converter Sample using C# step by step.
First we open microsoft visual studio program
We do the settings in the first 4 images in order
We put 1 label and 1 combo box on the form screen
Click once on the combo box and click on edit items
In the window that opens, type the following and click OK
NotSet - Male - Female - Neutral
Then, on the form screen, take 1 text box and make it look like you see the settings
Now let's put 4 buttons on my form screen
Then click button 1 and do the settings in the picture
Do the same for button 2 3 and 4 .
Briefly;
button2 : Text = Resume and Name = btnResume
button3 : Text = Pause and Name = btnPause
button4 : Text = Speak and Name = btnSpeak
Result;
Click once in the text box and make it look like the image
Name = txtContent
Go to Form1.cs on the right, right click and choose Rename, and name it frmMain
Right-click Preferences, select Add references
Down to select system.speech and press ok
Double-click the form screen to go to the code screen, and do as you see in the image.
Codes;
using System.Speech.Synthesis;
SpeechSynthesizer voice;
voice = new SpeechSynthesizer();
We go back to the form screen and double-click on the speak button.
And we write our codes
private void btnSpeak_Click(object sender, EventArgs e)
{
try
{
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
We also do the same for pause, resume and save buttons
Return to the form screen and click once on the combo box to make the setting in the image.
Then double-click on the talk button and come to the code screen and make it look like in the picture.
Codes;
private void btnSpeak_Click(object sender, EventArgs e)
{
try
{
switch (cboSelectVoice.SelectedIndex)
{
case 0:
voice.SelectVoiceByHints(VoiceGender.NotSet);
break;
case 1:
voice.SelectVoiceByHints(VoiceGender.Male);
break;
case 2:
voice.SelectVoiceByHints(VoiceGender.Female);
break;
case 3:
voice.SelectVoiceByHints(VoiceGender.Neutral);
break;
default:
break;
}
voice.SpeakAsync(txtContent.Text);
Then come and edit btnPause_Click
try
{
voice.Pause();
}
Then come and edit btnResume_Click
try
{
voice.Resume();
}
Then come and edit btnSave_Click
private void btnSave_Click(object sender, EventArgs e)
{
try
{
using (SaveFileDialog sfd = new SaveFileDialog())
{
sfd.Filter = "Wav files|*.wav";
sfd.Title = "Save to a wave file";
if (sfd.ShowDialog() == DialogResult.OK)
{
FileStream fs = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write);
voice.SetOutputToWaveStream(fs);
voice.Speak(txtContent.Text);
}
}
}
**And here is the result :) **
https://www.youtube.com/watch?v=UiJUUN2oChk
I hope this is useful for you so you can improve yourself by working this way
If there is a problem, you can write a comment under this topic.
Project result : https://github.com/ShanksTaicho/C-Text-to-speech
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
Can you please remove the animated gif at the end of your post. Thank you.
You can contact us on Discord.
[utopian-moderator]
Thank you for approved @vladimir-simovic , I removed the animation thanks <3
@freedom , @manishmike10 , @simnrodrguez , @utopian-io , @espoem , @knowledges , @freedom , @ruah , @manishmike10 :)
Yine süper bi paylaşım abi ellerine sağlık . <3
Süper bi paylaşım abi ellerine sağlık .
Hemen deniyorum abi eyvallahh hhhhh
@originalworks
The @OriginalWorks bot has determined this post by @shankstaicho to be original material and upvoted it!
To call @OriginalWorks, simply reply to any post with @originalworks or !originalworks in your message!
Hey @shankstaicho I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
thank you very much @utopian-io <3 .