none
microsoft speech synthesizer plugin for VB .NET RRS feed

  • Question

  • Hi, is there a plugin that allows you to use the Microsoft speech synthesizer in a VB .NET application.  For instance, have textbox1.text = "hello..." read aloud by the computer voice.  TY.

    llama

    Friday, October 18, 2013 6:32 PM

Answers

All replies

  • Add a reference to System.Speech:

    http://msdn.microsoft.com/en-us/library/gg145021.aspx

    Then use the synthesizer:

    http://msdn.microsoft.com/en-us/library/system.speech.synthesis.speechsynthesizer.aspx


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Proposed as answer by Andrew Morton Friday, October 18, 2013 7:48 PM
    • Marked as answer by Tess Card Friday, October 18, 2013 8:05 PM
    Friday, October 18, 2013 6:40 PM
    Moderator
  • Cool, thanks sir.

    llama

    Friday, October 18, 2013 7:39 PM
  • Is system.speech only available in professional versions of VB .NET?


    • Edited by Tess Card Friday, October 18, 2013 8:12 PM edit 2
    Friday, October 18, 2013 8:11 PM
  • Is system.speech only available in professional versions of VB .NET?


    It should be available in all versions of Visual Studio: I just checked with VS2010 Express for Desktop and it was available. What exact problem are you having?

    How to: Add or Remove References in Visual Studio (Visual Basic)

    --
    Andrew

    Friday, October 18, 2013 8:27 PM
  • Well, I type imports system.speech but there is no reference showing to speech in the window that opens.

    llama

    Friday, October 18, 2013 8:35 PM
  • Well, I type imports system.speech but there is no reference showing to speech in the window that opens.

    You have to add a reference to System.Speech first: please see the link in my previous post.

    HTH,

    Andrew

    Friday, October 18, 2013 8:42 PM
  • Oh, thanks Andrew.. I don't do that often so it skipped my mind.

    llama

    Friday, October 18, 2013 8:43 PM
  • Oh, thanks Andrew.. I don't do that often so it skipped my mind.

    llama

    Here's an example of code that bypasses the speech recognition library which contains various commands. So this code only uses its own library read into it from a .txt file.

    And it synthesizes speech in order to respond to commands it receives. In this instance there are only two commands loaded from the .txt file and they are "Hello Mister Monkeyboy" and "Goodbye". It opens Notepads whenever Hello Mister Monkeyboy is said and it closes the app whenever Goodbye is said. Also note that I set it to SpeakAsync for replying to Hello Mister Monkeyboy as it does not interfere with launching Notepad and it will not lockup your app as using Speak will which is synchronous. And I set it to Speak for closing the app because if it were run asynchronously at that point the app would never close properly since SpeakAsync would be running while the app tried to close and it would crash I suppose like it does in debugger. However running Speak at that point will cause the Speech synthesis to finish speaking before call Me.Close occurs.

    Imports System.Speech.Recognition ' Add reference Assemblies Framework System.Speech
    Imports System.Speech.Recognition.SrgsGrammar ' Adding this is unnecessary on my PC
    
    Public Class Form1
    
        Dim WithEvents recognizer As SpeechRecognitionEngine
    
        Dim Neuro As New Speech.Synthesis.SpeechSynthesizer
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            recognizer = New SpeechRecognitionEngine()
            recognizer.SetInputToDefaultAudioDevice()
    
            ' Voice commands in Commands.txt are Hello, Goodbye, Time and Share
    
            Dim ReadLines As New System.IO.StreamReader("C:\Users\John\Desktop\Commands.txt")
    
            Do Until ReadLines.EndOfStream
                Dim NewGrammar As New Grammar(New Choices(New String(ReadLines.ReadLine())))
                recognizer.LoadGrammarAsync(NewGrammar)
            Loop
    
            ReadLines.Close()
    
            recognizer.RecognizeAsync(RecognizeMode.Multiple)
    
    
        End Sub
    
        Private Sub recognizer_LoadGrammarCompleted(sender As Object, e As LoadGrammarCompletedEventArgs) Handles recognizer.LoadGrammarCompleted
    
            Dim grammarName As String = e.Grammar.Name
            Dim grammarLoaded As Boolean = e.Grammar.Loaded
    
            If e.[Error] IsNot Nothing Then
                ' Add exception handling code here.
                Label1.Text = "LoadGrammar for " & grammarName & " failed with a " & e.[Error].[GetType]().Name & "."
            End If
    
            Label1.Text = ("Grammar " & grammarName & " " & If((grammarLoaded), "Is", "Is Not") & " loaded.")
    
        End Sub
    
        Private Sub recognizer_SpeechRecognized(sender As Object, e As SpeechRecognizedEventArgs) Handles recognizer.SpeechRecognized
    
            Label2.Text = "Grammar " & e.Result.Grammar.Name & " " & e.Result.Text
    
            Select Case e.Result.Text.ToUpper
                Case Is = "HELLO MISTER MONKEYBOY"
                    Neuro.SpeakAsync("Hello Mister Monkeyboy!")
                    Process.Start("Notepad")
                Case Is = "GOODBYE"
                    Neuro.Speak("Goodbye!")
                    Me.Close()
                    End
            End Select
    
        End Sub
    
    End Class


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    Saturday, October 19, 2013 5:26 AM
  • Very cool Mr. Monkeyboy.. TY

    llama

    Saturday, October 19, 2013 6:35 PM
  • Very cool Mr. Monkeyboy.. TY

    llama


    You're welcome. :)

    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    Saturday, October 19, 2013 9:44 PM
  • Unable to run Monkeyboy's program.  I get this error message:

    "Platform not supported.  Speech recognition not available on this system.  SAPI and speech recognition engines cannot be found."

    How can this be fixed?

    Here is a short speech program I wrote some time ago that works for me.  It uses 1 button and 1 textbox.

    Imports System.Speech.Synthesis
    'Added reference to System.Speech
    
    Public Class Form1
        Dim speaker As New SpeechSynthesizer()
        Dim selvoice As String
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim dis As Boolean
            For Each voice As System.Speech.Synthesis.InstalledVoice In speaker.GetInstalledVoices()
                txtSentence.Text = "I am " & voice.VoiceInfo.Name
                Try
                    selvoice = voice.VoiceInfo.Name
                    speaker.Speak("Press OK.")
                Catch
                    MessageBox.Show("Voice has been disabled.")
                    dis = True
                End Try
                If dis = False Then Exit For
            Next
        End Sub
    
        Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
            speaker.Rate = 0
            speaker.Volume = 100
            speaker.SelectVoice(selvoice)
            speaker.Speak("Please type your sentence in the textbox and press Enter.")
            txtSentence.Clear()
            txtSentence.Focus()
        End Sub
    
        Private Sub txtSentence_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSentence.KeyPress
            If e.KeyChar = Chr(13) Then
                speaker.Speak(txtSentence.Text)
                btnOK.Focus()
            End If
        End Sub
    
    End Class


    Solitaire


    • Edited by Solitaire Sunday, October 20, 2013 5:38 PM
    Sunday, October 20, 2013 5:37 PM
  • Unable to run Monkeyboy's program.  I get this error message:

    "Platform not supported.  Speech recognition not available on this system.  SAPI and speech recognition engines cannot be found."

    What platform are you using?

    speech-recognition-is-not-available-on-this-system-sapi-and-speech-recognition-engines-cannot-be...

    --
    Andrew

    Sunday, October 20, 2013 6:48 PM
  • I had that error message when running under Windows XP.  I ran it again under Windows 7 but got no speech at all, even after reinstalling the reference to System.Speech.


    Solitaire

    Sunday, October 20, 2013 9:35 PM