speech synthesizer (question) RRS feed

  • Question

  • is some example code:

    Imports System.Threading
    Imports System.Speech
    Imports System.Speech.Synthesis
    Public Class Form1
        Dim threada As New Thread(AddressOf thread_A)
        Dim variablea As SpeechSynthesizer
        Public Sub thread_A()
            variablea = New SpeechSynthesizer
        End Sub
    End Class

    howcome variablea.speak("hello........") does not work?  all i get are some basic items in the list for variablea when typing 'variablea.<something>' below the bottom line of code........thanks!


    Monday, November 10, 2014 3:33 AM


  • For one nothing in the code you display calls Public Sub thread_A so it wouldn't work even if it was correct. To start threada then in some event you should use threada.Start I believe which will cause the sub thread_A to launch in a new thread for the code in it to run in or something.

    Also you should place Option Strict On above your imports statements.

    Here's code that I extracted from a program which performs speech synthesis. And using the Async method then you really don't need to use threading. Since it is not synchronous which synchronous allows no other code to function while it speaks.

    Imports System.Speech.Synthesis ' Add reference to System.Speech in Prject tab, Add reference, Assemblies, Framework, System.Speech
    Dim Narrator As New SpeechSynthesizer() ' Global declaration. Although the way you do it is probably O.K.
    Narrator.Rate = NarratorRate ' Can be -10 to +10. In the code I had a NumericUpDown to alter the value of NarratorRate.
    Narrator.SpeakAsync("Some text or something.")

    La vida loca

    Monday, November 10, 2014 4:11 AM