Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET General (http://www.xtremevbtalk.com/-net-general/)
-   -   Choose between different sound cards for playback in VB.net (http://www.xtremevbtalk.com/-net-general/328586-choose-sound-cards-playback-vb-net.html)

jcvamp 01-14-2017 11:04 PM

Choose between different sound cards for playback in VB.net
Edit by Moderator: Re: http://www.xtremevbtalk.com/-net-gen...ck-vb-net.html
I just came across this. I'm working on a voice control system for home automation, and I wanted to have the ability to route different audio to different devices depending on where I'm controlling the program from.

I had to modify some of the code to get it to work for me (and had to overcome a lockload error), but the method works.


Imports Microsoft.DirectX
Imports Microsoft.DirectX.DirectSound
Imports System.IO
Imports System.Speech
Imports System.Speech.AudioFormat

Public Class Form1
    Dim synth As New Synthesis.SpeechSynthesizer
    Dim DsDevice As DirectSound.Device, mydevices As New DevicesCollection

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For Each dev As DeviceInformation In mydevices
    End Sub

    Private Sub lstDevices_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstDevices.SelectedIndexChanged
        If lstDevices.SelectedIndex = -1 Then Exit Sub
        DsDevice = New Device(mydevices(lstDevices.SelectedIndex).DriverGuid)
        DsDevice.SetCooperativeLevel(Me, CooperativeLevel.Priority)
        Dim bufferDesc As New Microsoft.DirectX.DirectSound.BufferDescription
        With bufferDesc
            .GlobalFocus = True
            .ControlVolume = True
            .ControlPan = True
            .ControlFrequency = True
        End With

        Dim VoiceStream As Stream = New MemoryStream()
        Dim sinfo As New SpeechAudioFormatInfo(128, AudioBitsPerSample.Eight, AudioChannel.Stereo)

        VoiceStream.Position = 0
        Dim _buffer As New SecondaryBuffer(VoiceStream, bufferDesc, DsDevice)
        _buffer.Play(0, BufferPlayFlags.Default)
    End Sub

To test, I have it saying 'test' over the selected audio device.

Thanks for the work you put in.

All times are GMT -6. The time now is 05:34 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.