Text to Speech: For C# and VB NET Students
In this walkthrough, you'll write a Text to Speech program in either C# or Visual Basic .NET (or both, if you're feeling adventurous!). It will look like this:
This lesson shows how to check for installed voices on your computer. But here's a list of what you'll be doing in this project:
- How to get a list of inbuilt Voices on your Windows computer
- Select a Voice from a dropdown list
- Use the Speech Synthesizer in C# and VB Net
- Adjust the speed and volume of the chosen Voice
- How to use Sliders (TrackBars) in C# and VB
- Read out Word files, PDF documents and text files
- How to use the NuGet Package Manager in Visual Basic
- Highlight a word or phrase and have that pronounced
- Read out text grabbed from a webpage
(Note: This program was written using the Windows 10 operating system. I haven't tested it on Windows 7 or 8. Might still work, and you can skip this section, if you don't have Windows 10. Also, you don't need to add the Word feature, if you don't have Microsoft Word.)
Before we get to anything else, let's see what voices you have on your computer.
In the search box at the bottom of Windows 10, type Control Panel.
Launch the Control Panel window and select the Ease of Access item:
From the Ease of Access screen, select the Speech Recognition item:
From the Speech Recognition screen, select Text to Speech on the left:
When you select Text to Speech, you should see this dialog box appear:
Click the dropdown box at the top under Voice Selection to see what voices you have:
In the image above, you can see that we have three voices: Hazel, David and Zira.
If you don't see any voices, or only one, you can add voices through the Settings screen.
Close down the speech dialog box and the Control Panel. In the Windows 10 search box, type Settings then launch the Settings screen. Click on the Time and Language item:
On the Time & Language page, select the Region & Language option on the left (not the Speech item):
On the Region & Language page, click on Add a Language:
When you click on Add a Language, you'll see this dialog box:
Select a language from the list. It's better to select a language with all four symbols, the ones indicated at the bottom. A lot of languages on the list won't have the speech components installed, so won't show up on the list of Voices you saw earlier.
Click Next to install the language:
Deselect the option at the top, Set as my Windows display language, otherwise you'll end up with all your Windows dialog boxes, and even your keyboard settings, in a different language. Notice that in the image above, it has options for Speech and Handwriting. You only need the Speech one. But click Install and you'll have added another Voice to that dropdown list from earlier. You may need to restart your computer, however, to see it. Even then, there's no guarantee that an installed language will appear on the list. It's very hit and miss!
OK, back to our Speech Program. Let's design the form. We'll do that in the next lesson below.