What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 50266 |  Welcome, Guest!   Register  Login
Home > Articles > Windows Forms > How to create a Text-to-Speech application using VB.NET with Visual studio 2008?

How to create a Text-to-Speech application using VB.NET with Visual studio 2008?

5 vote(s)
Rating: 4.8 out of 5
Article posted by Muhilan on 5/2/2010 | Views: 23677 | Category: Windows Forms | Level: Beginner red flag


This article shows to you , how to creating a Text-to-Speech application using VB.Net with Visual Studio 2008.

Download


 Download source code for How to create a Text-to-Speech application using VB.NET with Visual studio 2008?


Introduction


.Net Framwork 3.5 provides set of speech libraries for developing a Text-to-Speech. The System.Speech.Synthesis namespace provides lot of classes for Text-to-Speech. Mainly InstalledVoice, VoiceInfo and SpeechSynthesizer etc.. 


Step by Step Procedures


Create a new project in Visual Studio 2008 

Select the New Project from File Menu
  • -> New Project window appears 
  • -> browse to other languagues 
  • -> select visual basic and windows application enter Name as TextToSpeechVB.

when the project is created you have to add a reference to the System.Speech.dll under .NET Tab.




Now design the windows form with the following controls





  1. ComboBox  control(cmbInstalled)  - to list all available installed voices 
  2. Button Control(btnStart) - To starting the Text-to-Speech 
  3. Button Control(btnEnd)   - To stop the Text-to-Speech
  4. Track Bar control(btnRate) - to control the Text-to-Speech speed rate.
  5. Trach Bar Control( btnVolume)- to control the Text-to-Speech control volume. 

The Speed rate should be a number between -10 and 10 values. A normal rate is -1 and the volum between 0 and 100. 

So Assign the btnVolumn Trackbar control Minimum and Maximum properties to 0 and 100 and the btnRate trackbar control minimum and maximum properties to -10 and 10. 
Default set to btnVolumn Value properties to 50 and btnRate value properties to -1.
Create a new instance of a SpeechSynthesizer under namespace System.Speech.Synthesis. This class have the  properties and methods that can start, stop and control audio activites specified text. Need to add the Imports statements are 

Imports System.Speech.Synthesis
Imports System.Collections.ObjectModel
and declare the below line as private or public

Private p_objSynth As New SpeechSynthesizer
Next write a method which retrieves a list of installed voices are in local system. By default, Windows Xp available voices are (LH Michael(Gents voice),LH Michelle(Women voice),Microsoft sam(Gents voice)). This voice recognizes English words, punctuation and grammar rules. If you want to more voices , installed valid voices.

p_objSynth.GetInstalledVoices() method retrieving a list of all installed voices and returns a ReadOnlyCollection of InstalledVoice objects

Dim objvoices As ReadOnlyCollection(Of InstalledVoice) = p_objSynth.GetInstalledVoices(Globalization.CultureInfo.CurrentCulture)

Now On_PageLoad event loads cmbInstalled combobox with installed voices 

Dim objvoices As ReadOnlyCollection(Of InstalledVoice) = p_objSynth.GetInstalledVoices(Globalization.CultureInfo.CurrentCulture)
Dim objvoiceInformation As VoiceInfo = objvoices(0).VoiceInfo
For Each tmpvoice As InstalledVoice In objvoices
objvoiceInformation = tmpvoice.VoiceInfo
cmbInstalled.Items.Add(objvoiceInformation.Name.ToString)
Next


Handle Volume and Speed Rate for SpeechSynthesizer


Volume

Write code for handle volume and speed rate changes,earlier mentioned above volume must be a number between 0 and 100. Mention number becomes the value for the Volume property of the active SpeechSynthesizer class instance.The user changes the position of the slider in the volumeTrackBar control to raised the valueChanged event

Private Sub btnVolume_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVolume.ValueChanged
p_objSynth.Volume = btnVolume.Value
End Sub
Speed Rate

To set the speed rate by assigning the rate property of the SpeechSynthesizer in ValueChanged event.

Private Sub btnRate_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRate.ValueChanged
p_objSynth.Rate = btnRate.Value
End Sub
Stop Speech

For stop speech write code in btnEnd button Event 

mySynth.SpeakAsyncCancelAll() method to stop the Text-to-Speech. 

Start Speech

Now Start the Text-to-Speech write code in btnStart button event

p_objSynth.SelectVoice(cmbInstalled.Text)
p_objSynth.SpeakAsync(txtVoiceText.Text)

Complete Code Listing



Imports System.Speech.Synthesis

Imports System.Collections.ObjectModel



Public Class Form1
Private p_objSynth As New SpeechSynthesizer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim objvoices As ReadOnlyCollection(Of InstalledVoice) = p_objSynth.GetInstalledVoices(Globalization.CultureInfo.CurrentCulture)
Dim objvoiceInformation As VoiceInfo = objvoices(0).VoiceInfo
For Each tmpvoice As InstalledVoice In objvoices
objvoiceInformation = tmpvoice.VoiceInfo
cmbInstalled.Items.Add(objvoiceInformation.Name.ToString)
Next

End Sub

Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click

p_objSynth.SelectVoice(cmbInstalled.Text)
p_objSynth.SpeakAsync(txtVoiceText.Text)


End Sub


Private Sub btnVolume_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVolume.ValueChanged
p_objSynth.Volume = btnVolume.Value

End Sub





Private Sub btnRate_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRate.ValueChanged
p_objSynth.Rate = btnRate.Value
End Sub

Private Sub btnEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnd.Click
p_objSynth.SpeakAsyncCancelAll()
End Sub
End Class

Conclusion


I have attached a sample project and let me know your feedback.


If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

About Muhil an

Experience:3 year(s)
Home page:
Member since:Monday, November 30, 2009
Level:Starter
Status: [Member]
Biography:working as an IT System Analyst,tmuhilan at gmail com
 Responses
Posted by: Mary | Posted on: 16 Dec 2011 01:49:27 AM | Points: 25

Hi. Your article was very useful to our project. However, this code is useful when creating a project and when i tried implementing the same in a website, it didn't work! I'm having trouble figuring it out. Can you please help? I'm using VS 2008.

Thanks and Regards,
Mary.

Posted by: U083492 | Posted on: 02 Jan 2012 11:34:34 PM | Points: 25

Hi Muhilan>>>
thank you for your useful artical....but i have a problem appear when i run the cod.

""Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index""
can you please help? i'm waiting your response.
thank you.
Emad almazidi

>> Write Response - Respond to this post and get points
Related Posts

In this article explains you how to create Stopwatch Application using C#.

In this article you will learn about the hash algorithm and types are available in .Net.

The article will make use of the API " ShowWindow " from the user32 Dll and allow users to Minimise,Maximize and manuplate other windows from your DotNet Application

This Article will explain how to work with the FlowLayoutPanel control which is new in the DotNet Framework 2.0

Here I explained the step by step procedure to deploy windows application by extending PART - 1 of this Article

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/22/2013 12:23:21 PM