TECH TIPS Headline Animator

Saturday, December 18, 2010

Speech to text application with VB.net

This is a notepad which contains features for converting speech to text.
On clicking the button you will be able to listen the text written in textbox.
This is done with an object and sapi.spvoice.


[sourcecode language="vb.net"]
Imports System.IO
Public Class Form1
Dim fname As String
Dim fw As StreamWriter
Dim fr As StreamReader
Public Shared i As Integer
Public Shared x1, y1, z1 As String
Public Shared m, n As Integer
Dim len As Integer

Private Sub FILEToolStripMenuItem_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles FILEToolStripMenuItem.MouseHover
FILEToolStripMenuItem.ShowDropDown()
End Sub

Private Sub NEWToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NEWToolStripMenuItem.Click
RichTextBox1.Clear()
End Sub

Private Sub OPENToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OPENToolStripMenuItem.Click
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.ShowDialog = 1 Then
fname = OpenFileDialog1.FileName
Dim fr As New StreamReader(fname)
RichTextBox1.Text = fr.ReadToEnd()
fr.Close()
End If
End Sub

Private Sub SAVEToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SAVEToolStripMenuItem.Click
SaveFileDialog1.ShowDialog()
Dim fw As New StreamWriter(fname)
fw.Write(RichTextBox1.Text)
fw.Close()
Dim fr As New StreamReader(fname)
RichTextBox1.Text = fr.ReadToEnd()
End Sub

Private Sub EXITToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EXITToolStripMenuItem.Click
Me.Close()
End Sub

Private Sub FONTToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FONTToolStripMenuItem.Click
Dim fnt As Font
FontDialog1.ShowApply = True
FontDialog1.ScriptsOnly = True
FontDialog1.ShowDialog()
fnt = FontDialog1.Font
If RichTextBox1.SelectedText.Count = 0 Then
RichTextBox1.Font = fnt
Else
RichTextBox1.SelectionFont = fnt
End If
End Sub

Private Sub CUTToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CUTToolStripMenuItem.Click
RichTextBox1.Cut()
End Sub

Private Sub COPYToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles COPYToolStripMenuItem.Click
RichTextBox1.Copy()
End Sub

Private Sub PASTEToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PASTEToolStripMenuItem.Click
RichTextBox1.Paste()
End Sub

Private Sub DELETEToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DELETEToolStripMenuItem.Click
Dim str As String = ""
RichTextBox1.SelectedText = str
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "Untitled-Notepad1"
OpenFileDialog1.FileName = ""
If OpenFileDialog1.FileName.Count = 0 Then
Me.Text = "Untitled"
Else
Me.Text = OpenFileDialog1.FileName
End If
If RichTextBox1.SelectedText.Count = 0 Then
DELETEToolStripMenuItem.Enabled = False
End If
If RichTextBox1.SelectedText.Count = 0 Then
PASTEToolStripMenuItem.Enabled = False
End If
If RichTextBox1.SelectedText.Count = 0 Then
COPYToolStripMenuItem.Enabled = False
End If
If RichTextBox1.SelectedText.Count = 0 Then
CUTToolStripMenuItem.Enabled = False
End If
End Sub

Private Sub EDITToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EDITToolStripMenuItem.Click
If Not RichTextBox1.SelectedText.Count = 0 Then
COPYToolStripMenuItem.Enabled = True
Else
COPYToolStripMenuItem.Enabled = False
End If
If Not RichTextBox1.SelectedText.Count = 0 Then
CUTToolStripMenuItem.Enabled = True
Else
CUTToolStripMenuItem.Enabled = False
End If
If Not RichTextBox1.SelectedText.Count = 0 Then
PASTEToolStripMenuItem.Enabled = True
End If
If Not RichTextBox1.SelectedText.Count = 0 Then
DELETEToolStripMenuItem.Enabled = True
Else
DELETEToolStripMenuItem.Enabled = False
End If
End Sub

Private Sub FINDANDREPLACEToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FINDANDREPLACEToolStripMenuItem.Click
y1 = RichTextBox1.Text
x1 = InputBox("Enter text to find : ")
m = x1.Length
n = y1.Length
len = n - m + 1
For i As Integer = 0 To len
z1 = y1.Substring(i, m)
If z1 = x1 Then
RichTextBox1.SelectionStart = i
RichTextBox1.SelectionLength = m
Exit For
MessageBox.Show("Found.")
End If
Next
End Sub

Private Sub ABOUTNOTEPADToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ABOUTNOTEPADToolStripMenuItem.Click
MsgBox("Notepad DESIGNED and developed By MURTAZA KANPURWALA " & vbNewLine & "visit http://techtips52.co.cc for more", MsgBoxStyle.Information, "ABOUT NOTEPAD")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim speech
speech = CreateObject("sapi.spvoice")
speech.speak(RichTextBox1.Text)
End Sub
End Class
[/sourcecode]

DOWNLOAD CODE HERE

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More