Lower System Volume When Reading from System.Speech.Synthesis RRS feed

  • Question

  • Hello, I am making a weather program in VB.NET WPF. I would like the computer's volume (expect the voice and weather alert tone) to be lowered and come back to normal. This is so it would get the user's attention. The program would lower the volume play the alert tone, say that a weather alert has been issued, play the alert tone again and then raise the volume back to normal.

    This would happen when anytime the alert tone is playing or the program is reading from the text to speech.

    How can this be accomplished?

    Thank You!

    Saturday, January 19, 2019 10:33 PM

All replies

  • Hi,

    You can use the following method to control the system Volume.

    Imports System.Runtime.InteropServices Public Class Form1 Private Const APPCOMMAND_VOLUME_MUTE As Integer = &H80000 Private Const APPCOMMAND_VOLUME_UP As Integer = &HA0000 Private Const APPCOMMAND_VOLUME_DOWN As Integer = &H90000 Private Const WM_APPCOMMAND As Integer = &H319 <DllImport("user32.dll")> Public Shared Function SendMessageW(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr End Function

    'Forbidden Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click SendMessageW(Me.Handle, WM_APPCOMMAND, Me.Handle, CType(APPCOMMAND_VOLUME_MUTE, IntPtr)) End Sub 'Lower System Volume Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click SendMessageW(Me.Handle, WM_APPCOMMAND, Me.Handle, CType(APPCOMMAND_VOLUME_DOWN, IntPtr)) End Sub 'Increase  System Volume Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click SendMessageW(Me.Handle, WM_APPCOMMAND, Me.Handle, CType(APPCOMMAND_VOLUME_UP, IntPtr)) End Sub End Class

    Best Regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, January 21, 2019 3:23 AM