locked
Speech.Synthesis repeating twice even though it isn't coded to do so RRS feed

  • Question

  • Hello,

    I am stumped on an issue and I can't figure out why it is doing this. My application uses a tab control, which automatically switches to the next tab control at the set interval. When the appropriate slide is showing, it reads the appropriate line of text. However, it recently and randomly started repeating the last tabpage's and then saying the current tappage instead of just saying the current tabpage. I do not have it coded to do this and it randomly started doing this.

    Here is my code:

    Auto Slideshow of Tabpages:

    Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs)
            Dim g As Graphics = e.Graphics
            Dim _TextBrush As Brush
    
            ' Get the item from the collection.
            Dim _TabPage As TabPage = TabControl1.TabPages(e.Index)
    
            ' Get the real bounds for the tab rectangle.
            Dim _TabBounds As Rectangle = TabControl1.GetTabRect(e.Index)
    
            If (e.State = DrawItemState.Selected) Then
                ' Draw a different background color, and don't paint a focus rectangle.
                _TextBrush = New SolidBrush(Color.Red)
                g.FillRectangle(Brushes.Gray, e.Bounds)
            Else
                _TextBrush = New System.Drawing.SolidBrush(e.ForeColor)
                e.DrawBackground()
            End If
    
            ' Use our own font.
            Dim _TabFont As New Font("Arial", 10.0, FontStyle.Bold, GraphicsUnit.Pixel)
    
            ' Draw string. Center the text.
            Dim _StringFlags As New StringFormat()
            _StringFlags.Alignment = StringAlignment.Center
            _StringFlags.LineAlignment = StringAlignment.Center
            g.DrawString(_TabPage.Text, _TabFont, _TextBrush, _TabBounds, New StringFormat(_StringFlags))
        End Sub
    
    Private Sub LFI_Panel_Timer_Tick(sender As Object, e As EventArgs) Handles LFI_Panel_Timer.Tick
            If TabControl1.SelectedIndex < TabControl1.TabCount - 1 Then
                TabControl1.SelectedIndex = TabControl1.SelectedIndex + 1
            Else
                'Go to the first tab
                TabControl1.SelectedIndex = 0
            End If
    

    Narration Code:

    Private Sub TabPage1_Enter(sender As Object, e As EventArgs) Handles TabPage1.Enter
            Task.Run(AddressOf CurrentConditionsVoice)
        End Sub
    
    'THE ABOVE IS DONE FOR EACH TAB PAGE ONLY THE ADDRESSOF IS DIFFERENT.
    
    
     Private Sub CurrentConditionsVoice()
            My.Settings.RaiseAudio = "0"
    
            speaker.Volume = 100
            Delay(0)
            If My.Settings.speaking = "Yes" Then
                speaker.Volume = 20
            ElseIf My.Settings.speaking = "No" Then
                speaker.Volume = 100
            End If
            speaker.Rate = 1
    
            speaker.SpeakAsync("Currently in your area")
            speaker.SpeakAsync(Label43.Text)
            Dim a As String = Label44.Text
            Select Case True
                'Thunderstorm Group
                Case a = ("Thunderstorms") : speaker.Speak("With a thunderstorm.")
                Case a = ("Thunderstorms and Rain") : speaker.Speak("With a thunderstorm.")
                Case a = ("Heavy Thunderstorm") : speaker.Speak("With a heavy thunderstorm.")
                Case a = ("Thunderstorm In The Vicinity") : speaker.Speak("With a thunderstorm in the vicinity.")
                Case a = ("Thunderstorm Heavy Rain Fog and Breezy") : speaker.Speak("With a thunderstorm with foggy and breezy conditions.")
    
                    'Drizzle Group
                Case a = ("Drizzle") : speaker.Speak("With drizzle.")
                Case a = ("Shower") : speaker.Speak("With a showers.")
    
                    'Rain Group
                Case a = ("Light Rain") : speaker.Speak("With light rain.")
                Case a = ("Light Rain") : speaker.Speak("With light rain and some fog.")
                Case a = ("Heavy Rain") : speaker.Speak("With heavy rain.")
                Case a = ("Freezing Rain") : speaker.Speak("With freezing rain.")
    
                    'Snow Group
                Case a = ("Light Snow") : speaker.Speak("With light snow.")
                Case a = ("Light Snow and Fog/Mist") : speaker.Speak("With light snow and some fog.")
                Case a = ("Snow") : speaker.Speak("With snow.")
                Case a = ("Heavy Snow") : speaker.Speak("With heavy snow.")
                Case a = ("Sleet") : speaker.Speak("With sleet.")
                Case a = ("Wintery Mix") : speaker.Speak("With a mix of wintery preciptation.")
                Case a = ("Flurries") : speaker.Speak("With flurries.")
    
                    'Atmosphere Group
                Case a = ("Mist") : speaker.Speak("With mist.")
                Case a = ("Smoke") : speaker.Speak("With smoky conditions.")
                Case a = ("Haze") : speaker.Speak("With haze.")
                Case a = ("sand, dust whirls") : speaker.Speak("With sand and dust whrils.")
                Case a = ("Fog") : speaker.Speak("With foggy conditions.")
                Case a = ("Fog/Mist") : speaker.Speak("with foggy conditions.")
                Case a = ("sand") : speaker.Speak("With sandy conditions.")
                Case a = ("dust") : speaker.Speak("With dusty conditions.")
                Case a = ("volcanic ash") : speaker.Speak("With volcanic ash.")
                Case a = ("squalls") : speaker.Speak("With squalls.")
                Case a = ("tornado") : speaker.Speak("With a tornado.")
    
                    'Clear Group
                Case a = ("Clear") : speaker.SpeakAsync("Under clear skies.")
                Case a = ("Mostly Clear") : speaker.Speak("Under Mostly Clear skies.")
    
                    'Clouds Group
                Case a = ("Partly Cloudy") : speaker.Speak("Under Partly Cloudy skies.")
                Case a = ("Mostly Cloudy") : speaker.Speak("Under Mostly Cloudy skies.")
                Case a = ("Cloudy") : speaker.Speak("Under Cloudy skies.")
    
                    'Windy Group
                Case a = ("Partly Cloudy and Windy") : speaker.Speak("Under Partly Cloudy skies with windy conditions.")
                Case a = ("Mostly Cloudy and Windy") : speaker.Speak("Under Mostly Cloudy skies with windy conditions.")
                Case a = ("Cloudy and Windy") : speaker.Speak("Under Cloudy skies with windy conditions.")
                Case a = ("Clear and Windy") : speaker.Speak("Under clear skies with windy conditions.")
                Case a = ("Windy") : speaker.Speak("with windy conditions.")
                Case a = ("Mostly Clear and Windy") : speaker.Speak("Under Mostly Clear skies with windy conditions.")
    
                    'Breezy Group
                Case a = ("Clear and Breezy") : speaker.Speak("Under clear skies with breezy conditions.")
                Case a = ("Overcast and Breezy") : speaker.Speak("With overcast skies and breezy conditions.")
                Case a = ("Partly Cloudy and Breezy") : speaker.Speak("Under Partly Cloudy skies with breezy conditions.")
                Case a = ("Mostly Cloudy and Breezy") : speaker.Speak("Under Mostly Cloudy skies with breezy conditions.")
                Case a = ("Cloudy and Breezy") : speaker.Speak("Under Cloudy skies with breezy conditions.")
            End Select
    
            My.Settings.RaiseAudio = "1"
        End Sub
    
    'THE RAISE AUDIO IS FOR THE BUILD IN WINDOWS MEDIA PLAYER TO LOWER THE MUSIC VOLUME SO THE SPEECH CAN BE HEARD.
    The above code has worked flawlessly. This issue started after I forgot to plugin my speakers or headset and it caused the program to give an AudioException because it couldn't find an audio output. What is going on with the application and how can I fix it?

    Saturday, November 28, 2020 8:06 PM

All replies

  • Do you have something special in TabPageX_Enter of the last page and in the corresponding voice function? Show some details about problematic code.

    Maybe also consider Speak instead of all SpeakAsync.


    • Edited by Viorel_MVP Saturday, November 28, 2020 8:47 PM
    Saturday, November 28, 2020 8:46 PM
  • Here is the rest of the code:

     Private Sub RadarVoice()
            Delay(0)
            My.Settings.RaiseAudio = "0"
            If My.Settings.speaking = "Yes" Then
                speaker.Volume = 20
            ElseIf My.Settings.speaking = "No" Then
                speaker.Volume = 100
            End If
            speaker.Rate = 1
            speaker.Speak("Your local doppler radar.")
            My.Settings.RaiseAudio = "1"
    
            AddHandler speaker.SpeakCompleted, AddressOf speakCompleted
        End Sub
    
        Private Sub Forecast1Voice()
            Delay(0.5)
            My.Settings.RaiseAudio = "0"
            If My.Settings.speaking = "Yes" Then
                speaker.Volume = 20
            ElseIf My.Settings.speaking = "No" Then
                speaker.Volume = 100
            End If
            speaker.Rate = 1
            If Label30.Text.Length > 110 Then
                speaker.Speak("Your Forecast for " + My.Settings.LFIPeriod1Date)
            Else
                speaker.Speak(My.Settings.LFIPeriod1Date + ", " + My.Settings.LFIPeriod1Forecast)
            End If
            My.Settings.RaiseAudio = "1"
            speaker.Pause()
        End Sub
    
        Private Sub Forecast2Voice()
            Delay(0.5)
            My.Settings.RaiseAudio = "0"
            speaker.Resume()
            If My.Settings.speaking = "Yes" Then
                speaker.Volume = 20
            ElseIf My.Settings.speaking = "No" Then
                speaker.Volume = 100
            End If
            speaker.Rate = 1
            If Label47.Text.Length > 110 Then
                speaker.Speak("Your Forecast for " + My.Settings.LFIPeriod2Date)
            Else
                speaker.Speak(My.Settings.LFIPeriod2Date + ", " + My.Settings.LFIPeriod2Forecast)
            End If
    
            My.Settings.RaiseAudio = "1"
    
            speaker.Pause()
        End Sub
        Private Sub ExtendedForecastVoice()
            Delay(0.5)
            My.Settings.RaiseAudio = "0"
            speaker.Resume()
            If My.Settings.speaking = "Yes" Then
                speaker.Volume = 20
            ElseIf My.Settings.speaking = "No" Then
                speaker.Volume = 100
            End If
            speaker.Rate = 1
            speaker.Speak("Your extended forecast!")
            My.Settings.RaiseAudio = "1"
        End Sub
    
        Private Sub AlertVoice()
            Delay(0.5)
            My.Settings.RaiseAudio = "0"
            speaker.Resume()
            If My.Settings.speaking = "Yes" Then
                speaker.Volume = 20
            ElseIf My.Settings.speaking = "No" Then
                speaker.Volume = 100
            End If
            speaker.Rate = 1
            If WxDisplay.ListBox1.Items.Count.ToString > 0 Then
                speaker.Speak("The National Weather Service has issued multiple weather bulletins for your area!")
            ElseIf WxDisplay.ListBox1.Items.Count.ToString = 2 Then
                speaker.Speak("A" + My.Settings.LFIAlert1 + "and a" + My.Settings.LFIAlert2 + "has been issued for your area by the national weather service!")
            Else
                speaker.Speak("A" + My.Settings.LFIAlert1 + "has been issued for your area!")
            End If
            My.Settings.RaiseAudio = "1"
        End Sub
        Private Sub speakCompleted(ByVal sender As Object, ByVal e As SpeakCompletedEventArgs)
            Dim cancelled = e.Cancelled
        End Sub

    I have looked and it does the same thing for each of the narrations just slightly different but nothing says repeat the last one. An example of what is going is say TabPage1 is showing, it switches to TabPage2, the program repeats the narration for tabpage1 and then says tabpage2.  Then it goes to TabPage3, repeats narration for tabpage2 then says tabpage3's narration and so on. Hope that answers your question.

    Saturday, November 28, 2020 8:50 PM
  • Maybe it is better to use some other events instead of Enter, which probably could occur several times for a tab. I do not think it means “A tab is selected”. Check it using debugger or adding some message boxes.

    Consider other events: Selected or SelectedIndexChanged of TabControl. Then you can choose and start one of the voice tasks depending on selected index.

    Also note that AddHandler from RadarVoice adds duplicate handlers on each call.

    Saturday, November 28, 2020 9:43 PM
  • I tried the selected of the tabcontrol event and the voice says nothing unless I push the arrow keys to go to the next slide. I need it to start automatically without any user pushing a button.
    Saturday, November 28, 2020 10:04 PM
  • Hi Austin Althouse,

    Thanks for your feedback.

    In order to reproduce your problem and make a test, could you share your project on OneDrive or GitHub?

    Note: do not include any privacy information in the project.

    We are waiting for your update.

    Best Regards,

    Xingyu Zhao


     

    Visual Basic and CLR forum will be migrating to a new home on Microsoft Q&A! (VB.NET and CLR) We invite you to post new questions in the new home on Microsoft Q&A ! For more information, please refer to the sticky post(VB.NET and CLR).


    Tuesday, December 1, 2020 3:01 AM