2011-02-07 4 views
3
Imports SpeechLib 

Public Class Form1 
    Public vox = CreateObject("sapi.spvoice") 

    Private Sub cmdSpeak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSpeak.Click 
     Dim text2 As String = "Hello , This is a Text. Hello , This is a Text." 
     BackgroundWorker1.RunWorkerAsync() 
    End Sub 

    Private Sub cmdPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPause.Click 
     vox.pause() 
    End Sub 

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
     Dim SVEPhoneme As Integer = 64 
     vox.EventInterests = SVEPhoneme 
     vox.AlertBoundary = SVEPhoneme 
    End Sub 

    Private Sub cmdResume_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdResume.Click 
     vox.resume() 
    End Sub 

    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork 
     vox.Speak(Text, SpeechVoiceSpeakFlags.SVSFlagsAsync) 
    End Sub 
End Class 

Как передать текст2 в vox.speak?Как передать аргументы в BackGroundWorker

ответ

12

В cmdSpeak_Click, проходит text2 в качестве параметра RunWorkerAsync

BackgroundWorker1.RunWorkerAsync(text2) 

В BackgroundWorker1_DoWork, получить значение параметра

vox.Speak(DirectCast(e.Argument, String), SpeechVoiceSpeakFlags.SVSFlagsAsync) 
+0

К сожалению об этом немом вопросе, но как я могу добавить text2 в качестве параметра в cmdSpeakClick? –

+0

Как этот 'Private Sub cmdSpeak_Click (ByVal sender As System.Object, ByVal e As System.EventArgs, ByVal text2 As String) Обрабатывает cmdSpeak.Click' ?? –

+1

Замените строку 'BackgroundWorker1.RunWorkerAsync()' с моей линией 'BackgroundWorker1.RunWorkerAsync (text2)' – Jimmy

 Смежные вопросы

  • Нет связанных вопросов^_^